Expand description
Physical frame allocator abstraction.
§MetaSlot (per-frame metadata, issue #38)
Each 4 KiB physical frame has a dedicated 64-byte MetaSlot
in a separate contiguous array (initialized by init_metadata_array). Buddy
free-list FreeListLink nodes, reference counts, purpose flags,
meta_guard bits, a per-allocation generation counter, and an optional
FrameMetaVtable live here : not in the mapped page bytes, so mappings
see a pristine payload.
§Revue / invariants (issue #38)
- Pas de métadonnées dans la charge utile : les liens buddy sont dans
FreeListLink, jamais écrits comme « faux pointeurs » dans les 4 KiB mappés. generation: incrémentée uniquement parMetaSlot::note_new_allocation_epochaprès unCASréussi dansFrameAllocOptions::allocate. Ne pas utiliserMetaSlot::set_generationsauf bootstrap/tests : sinon les schémas « généalogiques » deviennent incohérents.meta_guard::POISONEDvsframe_flags::POISONED: deux espaces (bits dédiésguardvs flags logiques). Pour marquer une frame corrompue, préférerMetaSlot::mark_poisonedqui pose les deux.vtable_ref/try_vtable_ref: bits0→ défaut ; bits non alignés ou invalides → défaut (pas d’UB). Les pointeurs alignés doivent désigner uneFrameMetaVtable'staticvalide lorsqu’ils sont enregistrés par le noyau.- Cache order-0 :
buddy::alloc(0)peut servir depuis le cache local ; le cheminFrameAllocOptions::allocateapplique quand même le CAS + epoch sur la même frame.
Modules§
- frame_
flags - Persistent flags stored in
MetaSlot/FrameMeta. - meta_
guard - Guard bits stored in
MetaSlot::guard(issue #38 : extensible without touching page bytes).
Structs§
- Frame
Alloc Options - Options controlling how a physical frame is allocated.
- Frame
Meta Vtable - Custom vtable for frame-type-specific behavior (DMA teardown, device hooks, …).
- Frame
Range Inclusive - Iterator over an inclusive range of physical frames
- Free
List Link - Buddy free-list link storage (intrusive list nodes live in
MetaSlot, not in frame bytes). - Meta
Slot - 64-byte cache-line metadata for one physical frame (issue #38).
- Phys
Frame - Physical frame (4KB aligned physical memory)
Enums§
- Alloc
Error - Frame allocation errors
- Frame
Purpose - Describes the intended purpose of an allocated frame.
Constants§
- FRAME_
META_ ALIGN - FRAME_
META_ LINK_ NONE - FRAME_
META_ SIZE - META_
SLOT_ REFCOUNT_ BYTE_ OFFSET - Byte offset of
MetaSlot::refcountfrom the start of each metadata slot (layout contract). - PAGE_
SIZE - REFCOUNT_
UNUSED - Sentinel refcount for a frame that is in the buddy free list.
Statics§
- DEFAULT_
FRAME_ META_ VTABLE - Default vtable used when
MetaSlot::vtableis0.
Traits§
- Frame
Allocator - Frame allocator trait
Functions§
- block_
phys_ has_ poison_ guard - Returns
trueif any page in[phys, phys + 2^order * PAGE_SIZE)hasMetaSlot::is_guard_poisoned. - frame_
meta_ debug_ snapshot (generation, guard_bits, vtable_bits)for debugging (e.g.serial_println!).- get_
meta - Get the
MetaSlotfor a given physical frame (same asget_meta_slot). - get_
meta_ slot - Preferred name matching the frame metadata design (issue #38).
- init_
metadata_ array - Initialize the global metadata array for all physical frames.
- invoke_
vtable_ on_ last_ ref - Invokes
on_last_reffrom the frame vtable, if any (last refcount drop). - invoke_
vtable_ on_ unmap - Invokes
on_unmapfrom the frame vtable, if any (issue #38 : unmap / release path). - meta_
generation_ matches - Returns
trueifMetaSlot::generationmatchesexpectedforphys(epoch check for use-after-free guards). - metadata_
size_ for - The metadata array size for
ram_sizebytes, rounded up to the nearest page since each frame has a dedicated metadata entry. @param ram_size Total RAM size to be covered by the metadata (in bytes).