Add persistent_term support#2323
Conversation
97739cb to
51ab669
Compare
PR Review: persistent_term + term_hash extractionScope: last two commits on this branch.
VerdictNo blocking soundness issues found. The headline design choice — skipping OTP's global GC pass on The CodeQL fix in Findings below are prioritized. P1 — Document the retention invariant near
|
pguyot
left a comment
There was a problem hiding this comment.
I'm not sure we should ship a r/w persistent term feature that leaks memory. I would suggest a first version with everything except erase and replace.
I want to challenge usage of locking.
I am not sure I understand why we copy keys with get_all. It seems inherited from ets, but maybe I didn't spend enough time yet on this review.
Implement a VM-level persistent_term table with NIFs for get/0,1,2, put/2, put_new/2, erase/1, and info/0. Persistent terms are copied into VM-owned heaps on write and returned without copying on read. Replaced and erased entries are retained until VM shutdown so previously returned terms remain valid without an OTP-style global GC pass, and info/0 reports retained memory. Also share the ETS term hashing helper for persistent_term lookup and add coverage for put/get/erase behavior, retained values, info/0, complex keys, and function keys. Signed-off-by: Peter M <petermm@gmail.com>
Use an explicit 64-bit intermediate when folding bytes from uint64_t values into the 32-bit term hash accumulator. This avoids CodeQL's "multiplication result converted to larger type" warning while preserving the intended uint32_t wraparound behavior of the hash. Signed-off-by: Peter M <petermm@gmail.com>
Use the project RWLock API directly for persistent_term instead of wrapping spinlock calls in local read/write lock macros. Also reduce the persistent_term critical sections by precomputing the bucket hash and allocating replacement entries before taking the write lock. Finally, stop copying keys in persistent_term:get/0. The returned list now allocates only the outer list and tuple cells on the caller heap, while both keys and values reference the persistent-term entry heap directly. This matches get/1 semantics, since retired entries are retained so previously returned persistent terms remain valid. Add a regression assertion that a persistent_term:get/0 result remains valid after the corresponding entries are erased. Signed-off-by: Peter M <petermm@gmail.com>
7af87d4 to
fda1420
Compare
Note the lack of GC in this implementation for erased/replaced persistent_terms, that is for followup..
Implement a VM-level persistent_term table with NIFs for get/0,1,2, put/2, put_new/2, erase/1, and info/0.
Persistent terms are copied into VM-owned heaps on write and returned without copying on read. Replaced and erased entries are retained until VM shutdown so previously returned terms remain valid without an OTP-style global GC pass, and info/0 reports retained memory.
Also share the ETS term hashing helper for persistent_term lookup and add coverage for put/get/erase behavior, retained values, info/0, complex keys, and function keys.
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later