Skip to main content

Module pagemap

Module pagemap 

Source
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 densifiesalloc_slot takes 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;
  • free writes 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§

SpanMeta
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 i of a slot_size class overlaps, inclusive.
slots_of_page
The slots of a slot_size class overlapping page p, inclusive, clamped to nslots.