VMEM_ALLOC(9F) Kernel Functions for Drivers VMEM_ALLOC(9F)

vmem_alloc, vmem_xalloc, vmem_free, vmem_xfreeallocate and free segments from a vmem arena

#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);

vmem_free(vmem_t *vmp, void *vaddr, size_t size);

vmem_xfree(vmem_t *vmp, void *vaddr, size_t size);

illumos DDI specific

The vmem arena from which to allocate or free.
The size of the segment to allocate or free.
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:

Take the segment from the smallest free segment that could satisfy this allocation.
Take the segment from the first free segment found that could satisfy this allocation.
Take the segment from the segment after the one previously allocated. This provides sequential behaviour useful when allocating identifiers from a VMC_IDENTIFIER arena.
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.

The minimum alignment of the allocation. If 0, the allocated segment will be aligned as the arena's quantum.
The allocated segment must be phase bytes from the alignment boundary.
The allocated segment may not straddle a nocross alignment boundary.
The minimum address at which the segment may be allocated.
The maximum address which may be included in the segment.
The address of the segment which () or () should free.

The () 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 () takes additional arguments allowing those requirements to be expressed.

Segments allocated with () must always be freed with (), since these allocations are uncached.

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.

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).

vmem(9), vmem_contains(9F), vmem_create(9F)

January 18, 2017 OmniOS