Skip to main content

Module vmalloc

Module vmalloc 

Source
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_0000

This region sits well above the HHDM direct map (starting at 0xffff8000_0000_0000) and kernel code/data.

§Allocation strategy

  1. Allocate backing physical pages individually from the frame allocator.
  2. Reserve a virtually contiguous range from the vmalloc extent allocator.
  3. Map each page into the kernel page tables at the virtual address.

§Deallocation

  1. Unmap each page from the kernel page tables.
  2. Flush stale TLB entries across CPUs for the unmapped range.
  3. Return the virtual range to the extent allocator.
  4. 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§

VmallocAttr
Attribution snapshot captured at vmalloc time.
VmallocDiagSnapshot
VmallocFailureSnapshot
VmallocLiveAllocationSnapshot

Enums§

VmallocAllocBackend
VmallocError

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 vmalloc calls 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 ptr is 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.