| VMEM(9) | Kernel Developer's Manual | VMEM(9) |
vmem —
#include <sys/vmem.h>
vmem_t *
vmem_create(const
char *name, vmem_addr_t
base, vmem_size_t
size, vmem_size_t
quantum, int
(*allocfn)(void *, vmem_size_t, vm_flag_t, vmem_addr_t *),
void (*freefn)(void *,
vmem_addr_t, vmem_size_t),
void *arg,
vmem_size_t qcache_max,
vm_flag_t flags,
int ipl);
vmem_t *
vmem_xcreate(const
char *name, vmem_addr_t
base, vmem_size_t
size, vmem_size_t
quantum, int
(*allocfn)(void *, vmem_size_t, vmem_size_t *, vm_flag_t, vmem_addr_t
*), void (*freefn)(void
*, vmem_addr_t, vmem_size_t),
void *arg,
vmem_size_t qcache_max,
vm_flag_t flags,
int ipl);
int
vmem_add(vmem_t
*vm, vmem_addr_t
addr, vmem_size_t
size, vm_flag_t
flags, vmem_addr_t
*addrp);
int
vmem_xalloc(vmem_t
*vm, vmem_size_t
size, vmem_size_t
align, vmem_size_t
phase, vmem_size_t
nocross, vmem_addr_t
minaddr, vmem_addr_t
maxaddr, vm_flag_t
flags, vmem_addr_t
*addrp);
void
vmem_xfree(vmem_t
*vm, vmem_addr_t
addr, vmem_size_t
size);
int
vmem_alloc(vmem_t
*vm, vmem_size_t
size, vm_flag_t
flags, vmem_addr_t
*addrp);
void
vmem_free(vmem_t
*vm, vmem_addr_t
addr, vmem_size_t
size);
void
vmem_destroy(vmem_t
*vm);
vmem is a general purpose resource allocator.
Despite its name, it can be used for arbitrary resources other than virtual
memory.
vmem_create() creates a new vmem
arena.
0 if
no initial span is required.0 if no initial
span is required.NULL to disable automatic imports.
vmem calls
(*allocfn)(arg,
size, flags,
&addrp); to import a span of size at least
size. allocfn must accept the
same flags as vmem_alloc().
allocfn must return ENOMEM
to indicate failure, or 0 on success. If allocfn
succeeds, it must write the starting address of the imported span to
addrp.NULL even if
allocfn is not NULL.
vmem calls
(*freefn)(arg,
addr, size) to return to
arg a span of size size,
starting at addr, that was previously allocated by
allocfn.NULL. vmem passes
arg as the first argument of
allocfn and freefn.VM_SLEEPVM_NOSLEEPNULL if there
are not enough resources available.vmem_xcreate() creates a new vmem
arena.
0 if
no initial span is required.0 if no initial
span is required.NULL to disable automatic imports.
vmem calls
(*allocfn)(arg,
size, &actualsize,
flags, &addrp); to import
a span of size at least size.
allocfn must accept the same
flags as vmem_alloc().
allocfn must return ENOMEM
to indicate failure, or 0 on success. If allocfn
succeeds, it must write the actual size of the allocation to
actualsize and the starting address of the imported
span to addrp. The actual size will always be
greater than or equal to the requested size.NULL even if
allocfn is not NULL.
vmem calls
(*freefn)(arg,
addr, size) to return to
arg a span of size size,
starting at addr, that was previously allocated by
allocfn.NULL. vmem passes
arg as the first argument of
allocfn and freefn.VM_SLEEPVM_NOSLEEPNULL if there
are not enough resources available.vmem_add() adds a span of size
size starting at addr to the
arena. Returns 0 on success, ENOMEM on failure.
VM_SLEEPVM_NOSLEEPENOMEM if
there are not enough resources available.vmem_xalloc() allocates a resource from
the arena.
VMEM_ADDR_MIN if the caller does not care.VMEM_ADDR_MAX if the caller does not care.The allocation strategy must be one of:
VM_BESTFITVM_INSTANTFITThe sleep flag must be one of:
VM_SLEEPVM_NOSLEEPENOMEM if
there are not enough resources available.NULL, vmem_xalloc()
overwrites it with the start address of the allocated span.vmem_xfree() frees resource allocated by
vmem_xalloc() to the arena.
vmem_xalloc(). Notably, it must not have been
allocated via vmem_alloc(). Otherwise, the
behaviour is undefined.vmem_xalloc().vmem_alloc() allocates a resource from the
arena.
The allocation strategy must be one of:
VM_BESTFITVM_INSTANTFITThe sleep flag must be one of:
VM_SLEEPVM_NOSLEEPENOMEM if
there are not enough resources available.NULL, vmem_alloc()
overwrites it with the start address of the allocated span.vmem_free() frees resource allocated by
vmem_alloc() to the arena.
vmem_alloc(). Notably, it must not have been
allocated via vmem_xalloc(). Otherwise, the
behaviour is undefined.vmem_alloc().vmem_destroy() destroys a vmem arena.
vmem_create() return a pointer to the newly allocated
vmem_t. Otherwise, it returns NULL.
On success, vmem_xalloc() and
vmem_alloc() return 0. Otherwise,
ENOMEM is returned.
vmem subsystem is implemented within the file
sys/kern/subr_vmem.c.
Jeff Bonwick and Jonathan Adams, Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources, 2001 USENIX Annual Technical Conference, 2001.
vmem was written by
YAMAMOTO Takashi.
vmem relies on
malloc(9),
pool(9), and
RUN_ONCE(9), so it cannot be
used as early during system bootstrap as
extent(9).
| February 28, 2016 | NetBSD 9.0 |