p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_create
creates a new vmem arena.
p l -tag -width qcache_max t Fa name The string to describe the vmem. t Fa base The start address of the initial span. It can be .Dv VMEM_ADDR_NULL if no initial span is required. t Fa size The size of the initial span. 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 source .Fa size .Fa "\*[Am]actualsize" .Fa flags .Fc to import a span of size at least .Fa size . .Fa allocfn should accept the same .Fa flags as .Fn vmem_alloc . .Fa allocfn must return .Dv VMEM_ADDR_NULL to indicate failure, or else the starting address of the imported span. If .Fa allocfn succeeds, it must write the actual size of the allocation to .Fa actualsize . 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 not be .Dv NULL unless .Fa allocfn is .Dv NULL . .Nm calls .Fn "(*freefn)" source addr size to return to .Fa source a span of size .Fa size , starting at .Fa addr , that was previously allocated by .Fa allocfn . t Fa source The backend arena. .Fa source may be .Dv NULL . .Nm passes .Fa source 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 Can 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
.Fa addr
on success.
.Fa flags
should be one of:
l -tag -width VM_NOSLEEP t Dv VM_SLEEP Can sleep until enough resources are available.
t Dv VM_NOSLEEP Don't sleep.
Immediately return
.Dv VMEM_ADDR_NULL
if there are not enough resources available.
.El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_xalloc
allocates a resource from the arena.
p l -tag -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 should be zero. Otherwise, .Fa phase should be smaller than .Fa align . t Fa nocross Request a resource which doesn't cross .Fa nocross aligned boundary. t Fa minaddr If non-zero, specify the minimum address which can be allocated. t Fa maxaddr If non-zero, specify the maximum address + 1 which can be allocated. t Fa flags A bitwise OR of an allocation strategy and a sleep flag.
p The allocation strategy is 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 should be one of: l -tag -width VM_NOSLEEP t Dv VM_SLEEP Can sleep until enough resources are available. t Dv VM_NOSLEEP Don't sleep. Immediately return .Dv VMEM_ADDR_NULL if there are not enough resources available. .El .El
p
------------------------------------------------------------
.Fn vmem_xfree
frees resource allocated by
.Fn vmem_xalloc
to the arena.
p l -tag -width addr t Fa vm The arena which we free to. t Fa addr The resource being freed. It must be the one returned by .Fn vmem_xalloc . Notably, it must not be the one from .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 . .El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_alloc
allocates a resource from the arena.
p l -tag -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 is 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 should be one of: l -tag -width VM_NOSLEEP t Dv VM_SLEEP Can sleep until enough resources are available. t Dv VM_NOSLEEP Don't sleep. Immediately return .Dv VMEM_ADDR_NULL if there are not enough resources available. .El .El
p
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_free
frees resource allocated by
.Fn vmem_alloc
to the arena.
p l -tag -width addr t Fa vm The arena which we free to. t Fa addr The resource being freed. It must be the one returned by .Fn vmem_alloc . Notably, it must not be the one from .Fn vmem_xalloc . 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_alloc . .El
p
------------------------------------------------------------
.Fn vmem_destroy
destroys a vmem arena.
p
l -tag -width vm t Fa vm The vmem arena being destroyed.
The caller should ensure that no one will use it anymore.
.El
------------------------------------------------------------
.Sh RETURN VALUES
.Fn vmem_create
return a pointer to the newly allocated vmem_t.
Otherwise, it returns
.Dv NULL .
p
On success,
.Fn vmem_xalloc
and
.Fn vmem_alloc
return an allocated vmem_addr_t.
Otherwise,
.Dv VMEM_ADDR_NULL
is returned.
------------------------------------------------------------
.Sh CODE REFERENCES
The
.Nm
subsystem is implemented within the file
a sys/kern/subr_vmem.c .
------------------------------------------------------------
.Sh SEE ALSO
.Xr intro 9 ,
.Xr kmem 9 ,
.Xr memoryallocators 9 ,
.Xr uvm 9
.Rs
.%A Jeff Bonwick
.%A Jonathan Adams
.%T "Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources"
.%J "2001 USENIX Annual Technical Conference"
.%D 2001
.Re
------------------------------------------------------------
.Sh AUTHORS
This implementation of
.Nm
was written by
.An YAMAMOTO Takashi .
.Sh BUGS
.Nm
cannot manage a resource that starts at 0, because it reserves the
address
.Dv VMEM_ADDR_NULL
q 0 for indicating errors.
p .Nm cannot manage a resource that ends at the maximum .Vt vmem_addr_t . This is an implementation limitation.
p .Nm relies on .Xr malloc 9 , .Xr pool 9 , and .Xr RUN_ONCE 9 , so it cannot be used as early during system bootstrap as .Xr extent 9 .