Expand description
Per-span occupancy — a bitmap in the segment header, one bit per slot.
v1 tracked free slots as a LIFO list threaded through the slots
themselves. That was the structure M3 killed: a page can only be
returned to the OS if no metadata lives inside it, and the free
list’s next-pointers sat in the exact pages MADV_DONTNEED would
zero — so reclaim could only ever work on whole spans, and a span
returns nothing until all of its (up to 157) slots die together.
The bitmap moves every trace of occupancy into the header, which buys three properties at once (RFC §5.1 v2):
- pages are pure data, so any page whose overlapping slots are all free is returnable while its neighbours stay live;
- lowest-first allocation densifies —
alloc_slottakes the lowest free bit, so live slots pack low and churn migrates free space upward into whole pages, manufacturing returnable pages rather than waiting for coincident deaths; freewrites nothing into the slot, one line fewer touched.
Worst case (16 B class) is 4096 slots → 512 B of bitmap; 64 spans of metadata ≈ 34 KB, comfortably inside the 64 KiB header span.
Structs§
- Span
Meta - Per-span bookkeeping. Deliberately not small: the bitmap is the price of page-granular reclaim, and it lives in the header span, which exists to be spent on exactly this.
Constants§
- BITMAP_
WORDS - Bitmap words: enough for the smallest class (16 B → 4096 slots).
- NO_
CLASS - No class assigned — the span is free for any class to take.
- PAGES_
PER_ SPAN - 4 KiB pages per 64 KiB span.
Functions§
- pages_
of_ slot - The pages slot
iof aslot_sizeclass overlaps, inclusive. - slots_
of_ page - The slots of a
slot_sizeclass overlapping pagep, inclusive, clamped tonslots.