VMEM(9) | Kernel Developer's Manual | VMEM(9) |
vmem
— general
purpose resource allocator
#include
<sys/vmem.h>
vmem_t *
vmem_create
(const
char *name, vmem_addr_t
base, vmem_size_t
size, vmem_size_t
quantum, vmem_size_t
qcache_max, int
flags);
int
vmem_add
(vmem_t
*vm, vmem_addr_t
addr, vmem_size_t
size, int
flags);
int
vmem_xalloc
(vmem_t
*vm, const vmem_size_t
size, vmem_size_t
align, const vmem_size_t
phase, const vmem_size_t
nocross, const
vmem_addr_t minaddr,
const vmem_addr_t
maxaddr, int 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, int 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);
The 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.vmem
allocation strategy flag:
M_FIRSTFIT
M_BESTFIT
vmem_add
()
adds a span of size size starting at
addr to the arena. Returns 0 on success,
ENOMEM
on failure. flags is
malloc(9) wait flag.
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.M_FIRSTFIT
and
M_BESTFIT
.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 be the one
from vmem_alloc
(). Otherwise, the behaviour is
undefined.vmem_xalloc
().vmem_alloc
()
allocates a resource from the arena.
vmem
allocation strategy flag
(see above) and a malloc(9) sleep flag.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 be the one from
vmem_xalloc
(). Otherwise, the behaviour is
undefined.vmem_alloc
().vmem_destroy
()
destroys a vmem arena.
vmem_create
() returns 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.
The 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.
The vmem
allocator was originally
implemented in NetBSD. It was introduced in
FreeBSD 10.0.
Original implementation of vmem
was
written by YAMAMOTO Takashi. The
FreeBSD port was made by Jeff
Roberson.
vmem
relies on
malloc(9), so it cannot be used as early during system
bootstrap.
July 12, 2013 | Debian |