p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_create
creates a new vmem arena.
l -tag -offset indent -width qcache_max t Fa name The string to describe the vmem.
t Fa base The start address of the initial span.
Pass
.Dv 0
if no initial span is required.
t Fa size The size of the initial span.
Pass
.Dv 0
if no initial span is required.
t Fa quantum The smallest unit of allocation.
t Fa allocfn The callback function used to import spans from the backend arena.
Set both
.Fa allocfn
and
.Fa freefn
to
.Dv NULL
to disable automatic imports.
.Nm
calls
.Fo "(*allocfn)"
.Fa arg
.Fa size
.Fa flags
.Fa "&addrp"
.Fc
to import a span of size at least
.Fa size .
.Fa allocfn
must accept the same
.Fa flags
as
.Fn vmem_alloc .
.Fa allocfn
must return
.Dv ENOMEM
to indicate failure, or 0 on success.
If
.Fa allocfn
succeeds, it must write the starting address of the imported span to
.Fa addrp .
t Fa freefn The callback function used to free spans to the backend arena.
.Fa freefn
may be
.Dv NULL
even if
.Fa allocfn
is not
.Dv NULL .
.Nm
calls
.Fn "(*freefn)" arg addr size
to return to
.Fa arg
a span of size
.Fa size ,
starting at
.Fa addr ,
that was previously allocated by
.Fa allocfn .
t Fa arg The backend arena.
.Fa arg
may be
.Dv NULL .
.Nm
passes
.Fa arg
as the first argument of
.Fa allocfn
and
.Fa freefn .
t Fa qcache_max The largest size of allocations which can be served by quantum cache.
It is merely a hint and can be ignored.
t Fa flags Either of:
l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until enough
resources are available.
t Dv VM_NOSLEEP Don't sleep.
Immediately return
.Dv NULL
if there are not enough resources available.
.El
t Fa ipl Interrupt level to be blocked for allocating from vmem.
.El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_xcreate
creates a new vmem arena.
l -tag -offset indent -width qcache_max t Fa name The string to describe the vmem.
t Fa base The start address of the initial span.
Pass
.Dv 0
if no initial span is required.
t Fa size The size of the initial span.
Pass
.Dv 0
if no initial span is required.
t Fa quantum The smallest unit of allocation.
t Fa allocfn The callback function used to import spans from the backend arena.
Set both
.Fa allocfn
and
.Fa freefn
to
.Dv NULL
to disable automatic imports.
.Nm
calls
.Fo "(*allocfn)"
.Fa arg
.Fa size
.Fa "&actualsize"
.Fa flags
.Fa "&addrp"
.Fc
to import a span of size at least
.Fa size .
.Fa allocfn
must accept the same
.Fa flags
as
.Fn vmem_alloc .
.Fa allocfn
must return
.Dv ENOMEM
to indicate failure, or 0 on success.
If
.Fa allocfn
succeeds, it must write the actual size of the allocation to
.Fa actualsize
and the starting address of the imported span to
.Fa addrp .
The actual size will always be greater than or equal to the requested size.
t Fa freefn The callback function used to free spans to the backend arena.
.Fa freefn
may be
.Dv NULL
even if
.Fa allocfn
is not
.Dv NULL .
.Nm
calls
.Fn "(*freefn)" arg addr size
to return to
.Fa arg
a span of size
.Fa size ,
starting at
.Fa addr ,
that was previously allocated by
.Fa allocfn .
t Fa arg The backend arena.
.Fa arg
may be
.Dv NULL .
.Nm
passes
.Fa arg
as the first argument of
.Fa allocfn
and
.Fa freefn .
t Fa qcache_max The largest size of allocations which can be served by quantum cache.
It is merely a hint and can be ignored.
t Fa flags Either of:
l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until enough
resources are available.
t Dv VM_NOSLEEP Don't sleep.
Immediately return
.Dv NULL
if there are not enough resources available.
.El
t Fa ipl Interrupt level to be blocked for allocating from vmem.
.El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_add
adds a span of size
.Fa size
starting at
.Fa addr
to the arena.
Returns
0
on success,
.Dv ENOMEM
on failure.
l -tag -offset indent -width flags t Fa flags Either of:
l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until enough
resources are available.
t Dv VM_NOSLEEP Don't sleep.
Immediately return
.Dv ENOMEM
if there are not enough resources available.
.El
.El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_xalloc
allocates a resource from the arena.
l -tag -offset indent -width nocross t Fa vm The arena which we allocate from.
t Fa size Specify the size of the allocation.
t Fa align If zero, don't care about the alignment of the allocation.
Otherwise, request a resource segment starting at
offset
.Fa phase
from an
.Fa align
aligned boundary.
t Fa phase See the above description of
.Fa align .
If
.Fa align
is zero,
.Fa phase
must be zero.
Otherwise,
.Fa phase
must be smaller than
.Fa align .
t Fa nocross Request a resource which doesn't cross
.Fa nocross
aligned boundary.
t Fa minaddr Specify the minimum address which can be allocated, or
.Dv VMEM_ADDR_MIN
if the caller does not care.
t Fa maxaddr Specify the maximum address which can be allocated, or
.Dv VMEM_ADDR_MAX
if the caller does not care.
t Fa flags A bitwise OR of an allocation strategy and a sleep flag.
p The allocation strategy must be one of: l -tag -width VM_INSTANTFIT t Dv VM_BESTFIT Prefer space efficiency. t Dv VM_INSTANTFIT Prefer performance. .El
p The sleep flag must be one of: l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until enough resources are available. t Dv VM_NOSLEEP Don't sleep. Immediately return .Dv ENOMEM if there are not enough resources available. .El t Fa addrp On success, if .Fa addrp is not .Dv NULL , .Fn vmem_xalloc overwrites it with the start address of the allocated span. .El
p
------------------------------------------------------------
.Fn vmem_xalloc_addr
allocates a specific address from the arena.
The requested address must be aligned with the arena's quantum.
l -tag -offset indent -width flags t Fa vm The arena which we allocate from.
t Fa addr The address to allocate.
t Fa size Specify the size of the allocation.
t Fa flags A sleep flag.
Because a specific address is being allocated, any specified allocation
strategy is ignored.
p The sleep flag must be one of: l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until the requested range can be allocated. t Dv VM_NOSLEEP Don't sleep. Immediately return .Dv ENOMEM if the requested range is not available. .El .El
p
------------------------------------------------------------
.Fn vmem_xfree
frees resource allocated by
.Fn vmem_xalloc
or
.Fn vmem_xalloc_addr
to the arena.
l -tag -offset indent -width addr t Fa vm The arena which we free to.
t Fa addr The resource being freed.
It must have been allocated via
.Fn vmem_xalloc
or
.Fn vmem_xalloc_addr .
Notably, it must not have been allocated via
.Fn vmem_alloc ,
otherwise, the behaviour is undefined.
t Fa size The size of the resource being freed.
It must be the same as the
.Fa size
argument used for
.Fn vmem_xalloc
or
.Fn vmem_xalloc_addr .
.El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_xfreeall
frees all resources that have been allocated by
.Fn vmem_xalloc
to the arena.
l -tag -offset indent -width addr t Fa vm The arena which we free to.
Note that this function is may not be used on arenas
where resources have been allocated using
.Fn vmem_alloc
or arenas that have a quantum cache
o i.e. were created with a non-zero .Fa qcache_max
c . .El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_alloc
allocates a resource from the arena.
l -tag -offset indent -width flags t Fa vm The arena which we allocate from.
t Fa size Specify the size of the allocation.
t Fa flags A bitwise OR of an allocation strategy and a sleep flag.
p The allocation strategy must be one of: l -tag -width VM_INSTANTFIT t Dv VM_BESTFIT Prefer space efficiency. t Dv VM_INSTANTFIT Prefer performance. .El
p The sleep flag must be one of: l -tag -width VM_NOSLEEP t Dv VM_SLEEP If the allocation cannot be satisfied immediately, sleep until enough resources are available. t Dv VM_NOSLEEP