Expand description
VM-backed allocator for large heap objects.
Provides virtually contiguous allocations backed by individually allocated
physical pages. Unlike the buddy allocator, vmalloc does not require
physically contiguous memory : it maps each page individually into a
dedicated kernel virtual memory arena.
§Arena layout
VMALLOC_VIRT_START = 0xffffc000_0000_0000 (256 GiB boundary)
VMALLOC_SIZE = 1 GiB
VMALLOC_VIRT_END = 0xffffc040_0000_0000This region sits well above the HHDM direct map (starting at 0xffff8000_0000_0000) and kernel code/data.
§Allocation strategy
- Allocate backing physical pages individually from the frame allocator.
- Reserve a virtually contiguous range from the vmalloc extent allocator.
- Map each page into the kernel page tables at the virtual address.
§Deallocation
- Unmap each page from the kernel page tables.
- Flush stale TLB entries across CPUs for the unmapped range.
- Return the virtual range to the extent allocator.
- Free each physical page back to the frame allocator.
§Metadata model
The allocator no longer uses a fixed allocation-record table or a bitmap. It maintains:
- a sorted free-extent list;
- a sorted active-allocation list;
- a metadata node pool carved from raw buddy pages, independent from the general kernel heap.
This removes the old fixed-slot ceiling and keeps vmalloc bookkeeping from recursing back into heap allocation.
§Thread safety
Protected by a single SpinLock<Vmalloc>. IRQs are disabled during
allocation to prevent deadlock with the buddy allocator.
Structs§
- Vmalloc
Attr - Attribution snapshot captured at vmalloc time.
- Vmalloc
Diag Snapshot - Vmalloc
Failure Snapshot - Vmalloc
Live Allocation Snapshot
Enums§
Constants§
- VMALLOC_
SIZE - Total size of the vmalloc arena: 1 GiB.
- VMALLOC_
VIRT_ END - End virtual address of the vmalloc arena.
- VMALLOC_
VIRT_ START - Base virtual address of the vmalloc arena. Placed at 0xffffc000_0000_0000 : well above the HHDM direct map.
Statics§
- VMALLOC_
ALLOC_ SEQ - Monotonic count of successful
vmalloccalls this boot (next seq = current value). - VMALLOC_
PEAK_ PAGES - High-watermark of simultaneously allocated pages (updated on every alloc).
- VMALLOC_
POLICY_ REJECT_ COUNT - Counts ZeroSize / policy-limit rejections.
Functions§
- diag_
snapshot - dump_
diagnostics - Dump vmalloc diagnostics to the serial console.
- dump_
live_ allocations - Dump all live large allocations with attribution to the serial console.
- init
- is_
live_ allocation - Returns whether
ptris currently the base address of a live vmalloc allocation. - last_
failure_ snapshot - live_
allocations_ snapshot - Copy live vmalloc allocations into
out, in allocation-address order. - vfree
- Free a vmalloc allocation.