[libc-commits] [libc] [libc] Implement dual freestore rotation for baremetal heap (PR #209811)
Daniel Thornburgh via libc-commits
libc-commits at lists.llvm.org
Fri Sep 4 16:59:11 PDT 2026
================
@@ -68,15 +83,79 @@ class FreeListHeap {
bool is_valid_ptr(const void *ptr) const { return ptr >= begin && ptr < end; }
+ /// The store that allocations are served from.
+ LIBC_INLINE FreeStore &active_free_store() { return free_stores[active]; }
+
+ /// @returns The index of the store that receives newly freed blocks. With a
+ /// single free store this is the active store itself, so freed memory is
+ /// immediately available again.
+ LIBC_INLINE size_t quarantine_store_index() const {
+ return (active + 1) % NUM_FREE_STORES;
+ }
+
+ /// @returns Whether `neighbor`, a free block adjacent to a block owned by
+ /// `store_index`, can be merged into it.
+ LIBC_INLINE static bool can_merge(BlockRef neighbor, size_t store_index) {
+ // Blocks too small to be tracked are owned by no store, so they can always
+ // be absorbed. Anything else must belong to the same store: merging across
+ // stores would hand memory quarantined in an inactive store back out
+ // through the active one.
+ return FreeStore::too_small(neighbor) ||
+ neighbor.next().prev_free_store_index() ==
+ static_cast<int>(store_index);
+ }
+
+ /// Marks `block` free, coalesces it with the adjacent free blocks that may
----------------
mysterymath wrote:
This took me a bit to parse: these blocks are already free, right? This just transfers them to the new store. If so, then "Marks `block` free" is *quite* confusing.
https://github.com/llvm/llvm-project/pull/209811
More information about the libc-commits
mailing list