VMEM_ALLOC(9F) Kernel Functions for Drivers VMEM_ALLOC(9F)
NAME
vmem_alloc,
vmem_xalloc,
vmem_free,
vmem_xfree - allocate and free
segments from a vmem arena
SYNOPSIS
#include <sys/vmem.h> void * vmem_alloc(
vmem_t *vmp,
size_t size,
int vmflag);
void * vmem_xalloc(
vmem_t *vmp,
size_t size,
size_t align_arg,
size_t phase,
size_t nocross,
void *minaddr,
void *maxaddr,
int vmflag);
void vmem_free(
vmem_t *vmp,
void *vaddr,
size_t size);
void vmem_xfree(
vmem_t *vmp,
void *vaddr,
size_t size);
INTERFACE LEVEL
illumos DDI specific
PARAMETERS
vmp The vmem arena from which to allocate or free.
size The size of the segment to allocate or free.
vmflag A bitmask of flags controlling the behaviour of the allocation.
There are two meaningful groups of flags. VM_SLEEP or
VM_NOSLEEP must be specified, and indicate whether the
allocation may block. A VM_SLEEP allocation can never fail but
may block indefinitely.
The allocation policy may be specified by one of the following
flags:
VM_BESTFIT
Take the segment from the smallest free segment that
could satisfy this allocation.
VM_FIRSTFIT
Take the segment from the first free segment found that
could satisfy this allocation.
VM_NEXTFIT
Take the segment from the segment after the one
previously allocated. This provides sequential
behaviour useful when allocating identifiers from a
VMC_IDENTIFIER arena.
VM_ENDALLOC
May be specified in combination with VM_BESTFIT,
VM_FIRSTFIT or the default policy to indicate that the
higher addresses should be preferred.
The default (unnamed) allocation policy is "instant fit", an
approximation of VM_BESTFIT in guaranteed constant time.
align_arg The minimum alignment of the allocation. If 0, the allocated
segment will be aligned as the arena's quantum.
phase The allocated segment must be
phase bytes from the alignment
boundary.
nocross The allocated segment may not straddle a
nocross alignment
boundary.
minaddr The minimum address at which the segment may be allocated.
maxaddr The maximum address which may be included in the segment.
vaddr The address of the segment which
vmem_free() or
vmem_xfree()
should free.
DESCRIPTION
The
vmem_alloc() and
vmem_xalloc() functions allocate a segment of
size length from the vmem arena
vmp.
The
vmflag argument controls the behaviour of the allocation, as
described in
PARAMETERS.
For allocations with complex requirements, such as those used for DMA
vmem_xalloc() takes additional arguments allowing those requirements to
be expressed.
Segments allocated with
vmem_xalloc() must always be freed with
vmem_xfree(), since these allocations are uncached.
CONTEXT
This function can be called from either user or kernel context. If the
VM_NOSLEEP flag is specified, it may also be called from interrupt
context.
RETURN VALUES
Upon successful completion the
vmem_alloc() and
vmem_xalloc() functions
return a pointer to the beginning of the allocated segment. In the
case of a VMC_IDENTIFIER arena, the address of this pointer is the
meaningful component, not the value to which it points.
On failure, NULL is returned. When the VM_SLEEP flag is specified,
these functions can never fail (but may block forever).
SEE ALSO
vmem(9),
vmem_contains(9F),
vmem_create(9F)illumos January 18, 2017 illumos