Skip to main content

vfree

Function vfree 

Source
pub fn vfree(ptr: *mut u8, token: &IrqDisabledToken) -> bool
Expand description

Free a vmalloc allocation.

Structured as three phases to avoid a spinlock-under-IPI deadlock:

  1. Under VMALLOC lock : unmap pages (acquires/releases KERNEL_PT_LOCK per page), collect the frame list, update allocator bookkeeping, return the virtual extent to the free list.
  2. Lock released : TLB shootdown. Remote CPUs servicing the IPI must acknowledge before returning. If VMALLOC were still held here, any remote CPU blocked on VMALLOC could not reach the acknowledgement path, causing a deadlock. Releasing first eliminates the hazard.
  3. No lock : free physical frames back to the buddy allocator.

Returns true if a region was released (free(NULL) counts as success). Returns false if the pointer was non-null but did not denote a live vmalloc mapping in the arena (nothing freed : caller may be leaking).