2016-02-29 03:34:17 +03:00
|
|
|
.\" $NetBSD: vmem.9,v 1.16 2016/02/29 00:34:17 chs Exp $
|
2006-10-22 15:14:52 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c)2006 YAMAMOTO Takashi,
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" ------------------------------------------------------------
|
2016-02-29 03:34:17 +03:00
|
|
|
.Dd February 28, 2016
|
2006-10-22 15:14:52 +04:00
|
|
|
.Dt VMEM 9
|
|
|
|
.Os
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh NAME
|
|
|
|
.Nm vmem
|
2006-10-24 01:21:49 +04:00
|
|
|
.Nd virtual memory allocator
|
2006-10-22 15:14:52 +04:00
|
|
|
.\" ------------------------------------------------------------
|
2009-08-04 03:15:29 +04:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/vmem.h
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Ft vmem_t *
|
|
|
|
.Fn vmem_create \
|
|
|
|
"const char *name" "vmem_addr_t base" "vmem_size_t size" "vmem_size_t quantum" \
|
2013-01-30 01:55:07 +04:00
|
|
|
"int (*allocfn)(void *, vmem_size_t, vm_flag_t, vmem_addr_t *)" \
|
|
|
|
"void (*freefn)(void *, vmem_addr_t, vmem_size_t)" \
|
|
|
|
"void *arg" "vmem_size_t qcache_max" "vm_flag_t flags" "int ipl"
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Ft vmem_t *
|
|
|
|
.Fn vmem_xcreate \
|
|
|
|
"const char *name" "vmem_addr_t base" "vmem_size_t size" "vmem_size_t quantum" \
|
2011-09-03 02:07:33 +04:00
|
|
|
"int (*allocfn)(void *, vmem_size_t, vmem_size_t *, vm_flag_t, vmem_addr_t *)" \
|
|
|
|
"void (*freefn)(void *, vmem_addr_t, vmem_size_t)" \
|
|
|
|
"void *arg" "vmem_size_t qcache_max" "vm_flag_t flags" "int ipl"
|
2009-08-04 03:15:29 +04:00
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-09-03 02:07:33 +04:00
|
|
|
.Ft int
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fn vmem_add \
|
2011-09-03 02:07:33 +04:00
|
|
|
"vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size" "vm_flag_t flags" "vmem_addr_t *addrp"
|
2009-12-22 01:49:18 +03:00
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-09-03 02:07:33 +04:00
|
|
|
.Ft int
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_xalloc \
|
|
|
|
"vmem_t *vm" "vmem_size_t size" "vmem_size_t align" \
|
|
|
|
"vmem_size_t phase" "vmem_size_t nocross" "vmem_addr_t minaddr" \
|
2011-09-03 02:07:33 +04:00
|
|
|
"vmem_addr_t maxaddr" "vm_flag_t flags" "vmem_addr_t *addrp"
|
2009-08-04 03:15:29 +04:00
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Ft void
|
|
|
|
.Fn vmem_xfree "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-09-03 02:07:33 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn vmem_alloc "vmem_t *vm" "vmem_size_t size" "vm_flag_t flags" "vmem_addr_t *addrp"
|
2009-08-04 03:15:29 +04:00
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Ft void
|
|
|
|
.Fn vmem_free "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Ft void
|
|
|
|
.Fn vmem_destroy "vmem_t *vm"
|
|
|
|
.\" ------------------------------------------------------------
|
2006-10-22 15:14:52 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
is a general purpose resource allocator.
|
2006-10-26 15:16:28 +04:00
|
|
|
Despite its name, it can be used for arbitrary resources
|
2006-10-22 15:14:52 +04:00
|
|
|
other than virtual memory.
|
2009-08-04 03:15:29 +04:00
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Fn vmem_create
|
|
|
|
creates a new vmem arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width qcache_max
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa name
|
|
|
|
The string to describe the vmem.
|
|
|
|
.It Fa base
|
|
|
|
The start address of the initial span.
|
2011-09-03 02:07:33 +04:00
|
|
|
Pass
|
|
|
|
.Dv 0
|
2009-08-04 03:15:29 +04:00
|
|
|
if no initial span is required.
|
|
|
|
.It Fa size
|
|
|
|
The size of the initial span.
|
2011-09-03 02:07:33 +04:00
|
|
|
Pass
|
|
|
|
.Dv 0
|
|
|
|
if no initial span is required.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa quantum
|
|
|
|
The smallest unit of allocation.
|
|
|
|
.It Fa allocfn
|
|
|
|
The callback function used to import spans from the backend arena.
|
2009-12-22 01:49:18 +03:00
|
|
|
Set both
|
2009-12-22 14:56:14 +03:00
|
|
|
.Fa allocfn
|
2009-12-22 01:49:18 +03:00
|
|
|
and
|
|
|
|
.Fa freefn
|
|
|
|
to
|
|
|
|
.Dv NULL
|
|
|
|
to disable automatic imports.
|
|
|
|
.Nm
|
|
|
|
calls
|
|
|
|
.Fo "(*allocfn)"
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa arg
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fa size
|
2013-01-30 01:55:07 +04:00
|
|
|
.Fa flags
|
|
|
|
.Fa "\*[Am]addrp"
|
|
|
|
.Fc
|
|
|
|
to import a span of size at least
|
|
|
|
.Fa size .
|
|
|
|
.Fa allocfn
|
2016-02-29 03:34:17 +03:00
|
|
|
must accept the same
|
2013-01-30 01:55:07 +04:00
|
|
|
.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 .
|
|
|
|
.It 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 .
|
|
|
|
.It 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 .
|
|
|
|
.It Fa qcache_max
|
|
|
|
The largest size of allocations which can be served by quantum cache.
|
|
|
|
It is merely a hint and can be ignored.
|
|
|
|
.It Fa flags
|
|
|
|
Either of:
|
|
|
|
.Bl -tag -width VM_NOSLEEP
|
|
|
|
.It Dv VM_SLEEP
|
2016-02-29 03:34:17 +03:00
|
|
|
If the allocation cannot be satisfied immediately, sleep until enough
|
|
|
|
resources are available.
|
2013-01-30 01:55:07 +04:00
|
|
|
.It Dv VM_NOSLEEP
|
|
|
|
Don't sleep.
|
|
|
|
Immediately return
|
|
|
|
.Dv NULL
|
|
|
|
if there are not enough resources available.
|
|
|
|
.El
|
|
|
|
.It Fa ipl
|
|
|
|
Interrupt level to be blocked for allocating from vmem.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Fn vmem_xcreate
|
|
|
|
creates a new vmem arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width qcache_max
|
2013-01-30 01:55:07 +04:00
|
|
|
.It Fa name
|
|
|
|
The string to describe the vmem.
|
|
|
|
.It Fa base
|
|
|
|
The start address of the initial span.
|
|
|
|
Pass
|
|
|
|
.Dv 0
|
|
|
|
if no initial span is required.
|
|
|
|
.It Fa size
|
|
|
|
The size of the initial span.
|
|
|
|
Pass
|
|
|
|
.Dv 0
|
|
|
|
if no initial span is required.
|
|
|
|
.It Fa quantum
|
|
|
|
The smallest unit of allocation.
|
|
|
|
.It 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
|
2009-12-22 14:56:14 +03:00
|
|
|
.Fa "\*[Am]actualsize"
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fa flags
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa "\*[Am]addrp"
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fc
|
|
|
|
to import a span of size at least
|
|
|
|
.Fa size .
|
|
|
|
.Fa allocfn
|
2016-02-29 03:34:17 +03:00
|
|
|
must accept the same
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fa flags
|
|
|
|
as
|
|
|
|
.Fn vmem_alloc .
|
|
|
|
.Fa allocfn
|
|
|
|
must return
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv ENOMEM
|
|
|
|
to indicate failure, or 0 on success.
|
2009-12-22 01:49:18 +03:00
|
|
|
If
|
|
|
|
.Fa allocfn
|
|
|
|
succeeds, it must write the actual size of the allocation to
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa actualsize
|
|
|
|
and the starting address of the imported span to
|
|
|
|
.Fa addrp .
|
2009-12-22 01:49:18 +03:00
|
|
|
The actual size will always be greater than or equal to the requested size.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa freefn
|
|
|
|
The callback function used to free spans to the backend arena.
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fa freefn
|
2011-09-03 02:07:33 +04:00
|
|
|
may be
|
2009-12-22 01:49:18 +03:00
|
|
|
.Dv NULL
|
2011-09-03 02:07:33 +04:00
|
|
|
even if
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fa allocfn
|
2011-09-03 02:07:33 +04:00
|
|
|
is not
|
2009-12-22 01:49:18 +03:00
|
|
|
.Dv NULL .
|
|
|
|
.Nm
|
|
|
|
calls
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fn "(*freefn)" arg addr size
|
2009-12-22 01:49:18 +03:00
|
|
|
to return to
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa arg
|
2009-12-22 01:49:18 +03:00
|
|
|
a span of size
|
|
|
|
.Fa size ,
|
|
|
|
starting at
|
|
|
|
.Fa addr ,
|
|
|
|
that was previously allocated by
|
|
|
|
.Fa allocfn .
|
2011-09-03 02:07:33 +04:00
|
|
|
.It Fa arg
|
2009-08-04 03:15:29 +04:00
|
|
|
The backend arena.
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa arg
|
2009-12-22 01:49:18 +03:00
|
|
|
may be
|
|
|
|
.Dv NULL .
|
|
|
|
.Nm
|
|
|
|
passes
|
2011-09-03 02:07:33 +04:00
|
|
|
.Fa arg
|
2009-12-22 01:49:18 +03:00
|
|
|
as the first argument of
|
|
|
|
.Fa allocfn
|
|
|
|
and
|
|
|
|
.Fa freefn .
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa qcache_max
|
|
|
|
The largest size of allocations which can be served by quantum cache.
|
|
|
|
It is merely a hint and can be ignored.
|
|
|
|
.It Fa flags
|
|
|
|
Either of:
|
|
|
|
.Bl -tag -width VM_NOSLEEP
|
|
|
|
.It Dv VM_SLEEP
|
2016-02-29 03:34:17 +03:00
|
|
|
If the allocation cannot be satisfied immediately, sleep until enough
|
|
|
|
resources are available.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Dv VM_NOSLEEP
|
|
|
|
Don't sleep.
|
|
|
|
Immediately return
|
|
|
|
.Dv NULL
|
|
|
|
if there are not enough resources available.
|
|
|
|
.El
|
|
|
|
.It Fa ipl
|
|
|
|
Interrupt level to be blocked for allocating from vmem.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fn vmem_add
|
|
|
|
adds a span of size
|
|
|
|
.Fa size
|
|
|
|
starting at
|
|
|
|
.Fa addr
|
|
|
|
to the arena.
|
|
|
|
Returns
|
2011-09-03 02:07:33 +04:00
|
|
|
0
|
|
|
|
on success,
|
|
|
|
.Dv ENOMEM
|
|
|
|
on failure.
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width flags
|
|
|
|
.It Fa flags
|
|
|
|
Either of:
|
2009-12-22 01:49:18 +03:00
|
|
|
.Bl -tag -width VM_NOSLEEP
|
|
|
|
.It Dv VM_SLEEP
|
2016-02-29 03:34:17 +03:00
|
|
|
If the allocation cannot be satisfied immediately, sleep until enough
|
|
|
|
resources are available.
|
2009-12-22 01:49:18 +03:00
|
|
|
.It Dv VM_NOSLEEP
|
|
|
|
Don't sleep.
|
|
|
|
Immediately return
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv ENOMEM
|
2009-12-22 01:49:18 +03:00
|
|
|
if there are not enough resources available.
|
|
|
|
.El
|
2016-02-29 03:34:17 +03:00
|
|
|
.El
|
2009-12-22 01:49:18 +03:00
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_xalloc
|
|
|
|
allocates a resource from the arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width nocross
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa vm
|
|
|
|
The arena which we allocate from.
|
|
|
|
.It Fa size
|
|
|
|
Specify the size of the allocation.
|
|
|
|
.It 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.
|
|
|
|
.It Fa phase
|
|
|
|
See the above description of
|
|
|
|
.Fa align .
|
|
|
|
If
|
|
|
|
.Fa align
|
|
|
|
is zero,
|
|
|
|
.Fa phase
|
2016-02-29 03:34:17 +03:00
|
|
|
must be zero.
|
2009-08-04 03:15:29 +04:00
|
|
|
Otherwise,
|
|
|
|
.Fa phase
|
2016-02-29 03:34:17 +03:00
|
|
|
must be smaller than
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fa align .
|
|
|
|
.It Fa nocross
|
|
|
|
Request a resource which doesn't cross
|
|
|
|
.Fa nocross
|
|
|
|
aligned boundary.
|
|
|
|
.It Fa minaddr
|
2011-08-24 02:00:57 +04:00
|
|
|
Specify the minimum address which can be allocated, or
|
|
|
|
.Dv VMEM_ADDR_MIN
|
|
|
|
if the caller does not care.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa maxaddr
|
2011-08-24 02:00:57 +04:00
|
|
|
Specify the maximum address which can be allocated, or
|
|
|
|
.Dv VMEM_ADDR_MAX
|
|
|
|
if the caller does not care.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa flags
|
|
|
|
A bitwise OR of an allocation strategy and a sleep flag.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
The allocation strategy must be one of:
|
2009-08-04 03:15:29 +04:00
|
|
|
.Bl -tag -width VM_INSTANTFIT
|
|
|
|
.It Dv VM_BESTFIT
|
|
|
|
Prefer space efficiency.
|
|
|
|
.It Dv VM_INSTANTFIT
|
|
|
|
Prefer performance.
|
|
|
|
.El
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
The sleep flag must be one of:
|
2009-08-04 03:15:29 +04:00
|
|
|
.Bl -tag -width VM_NOSLEEP
|
|
|
|
.It Dv VM_SLEEP
|
2016-02-29 03:34:17 +03:00
|
|
|
If the allocation cannot be satisfied immediately, sleep until enough
|
|
|
|
resources are available.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Dv VM_NOSLEEP
|
|
|
|
Don't sleep.
|
|
|
|
Immediately return
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv ENOMEM
|
2009-08-04 03:15:29 +04:00
|
|
|
if there are not enough resources available.
|
|
|
|
.El
|
2011-09-03 02:07:33 +04:00
|
|
|
.It Fa addrp
|
|
|
|
On success, if
|
|
|
|
.Fa addrp
|
2011-09-05 22:21:29 +04:00
|
|
|
is not
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv NULL ,
|
|
|
|
.Fn vmem_xalloc
|
|
|
|
overwrites it with the start address of the allocated span.
|
2009-08-04 03:15:29 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Fn vmem_xfree
|
|
|
|
frees resource allocated by
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fn vmem_xalloc
|
2009-08-04 03:15:29 +04:00
|
|
|
to the arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width addr
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa vm
|
|
|
|
The arena which we free to.
|
|
|
|
.It Fa addr
|
|
|
|
The resource being freed.
|
2016-02-29 03:34:17 +03:00
|
|
|
It must have been allocated via
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_xalloc .
|
2016-02-29 03:34:17 +03:00
|
|
|
Notably, it must not have been allocated via
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_alloc .
|
|
|
|
Otherwise, the behaviour is undefined.
|
|
|
|
.It 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
|
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Fn vmem_alloc
|
|
|
|
allocates a resource from the arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width flags
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa vm
|
|
|
|
The arena which we allocate from.
|
|
|
|
.It Fa size
|
|
|
|
Specify the size of the allocation.
|
|
|
|
.It Fa flags
|
|
|
|
A bitwise OR of an allocation strategy and a sleep flag.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
The allocation strategy must be one of:
|
2009-08-04 03:15:29 +04:00
|
|
|
.Bl -tag -width VM_INSTANTFIT
|
|
|
|
.It Dv VM_BESTFIT
|
|
|
|
Prefer space efficiency.
|
|
|
|
.It Dv VM_INSTANTFIT
|
|
|
|
Prefer performance.
|
|
|
|
.El
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
The sleep flag must be one of:
|
2009-08-04 03:15:29 +04:00
|
|
|
.Bl -tag -width VM_NOSLEEP
|
|
|
|
.It Dv VM_SLEEP
|
2016-02-29 03:34:17 +03:00
|
|
|
If the allocation cannot be satisfied immediately, sleep until enough
|
|
|
|
resources are available.
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Dv VM_NOSLEEP
|
|
|
|
Don't sleep.
|
|
|
|
Immediately return
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv ENOMEM
|
2009-08-04 03:15:29 +04:00
|
|
|
if there are not enough resources available.
|
|
|
|
.El
|
2011-09-03 02:07:33 +04:00
|
|
|
.It Fa addrp
|
|
|
|
On success, if
|
|
|
|
.Fa addrp
|
2011-09-05 22:21:29 +04:00
|
|
|
is not
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv NULL ,
|
|
|
|
.Fn vmem_alloc
|
|
|
|
overwrites it with the start address of the allocated span.
|
2009-08-04 03:15:29 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
.Fn vmem_free
|
|
|
|
frees resource allocated by
|
2009-12-22 01:49:18 +03:00
|
|
|
.Fn vmem_alloc
|
2009-08-04 03:15:29 +04:00
|
|
|
to the arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width addr
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa vm
|
|
|
|
The arena which we free to.
|
|
|
|
.It Fa addr
|
|
|
|
The resource being freed.
|
2016-02-29 03:34:17 +03:00
|
|
|
It must have been allocated via
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_alloc .
|
2016-02-29 03:34:17 +03:00
|
|
|
Notably, it must not have been allocated via
|
2009-08-04 03:15:29 +04:00
|
|
|
.Fn vmem_xalloc .
|
|
|
|
Otherwise, the behaviour is undefined.
|
|
|
|
.It 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
|
|
|
|
.Pp
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Fn vmem_destroy
|
|
|
|
destroys a vmem arena.
|
|
|
|
.Pp
|
2016-02-29 03:34:17 +03:00
|
|
|
.Bl -tag -offset indent -width vm
|
2009-08-04 03:15:29 +04:00
|
|
|
.It Fa vm
|
|
|
|
The vmem arena being destroyed.
|
2016-02-29 03:34:17 +03:00
|
|
|
The caller must ensure that no one will use it anymore.
|
2009-08-04 03:15:29 +04:00
|
|
|
.El
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
.Fn vmem_create
|
|
|
|
return a pointer to the newly allocated vmem_t.
|
|
|
|
Otherwise, it returns
|
|
|
|
.Dv NULL .
|
|
|
|
.Pp
|
|
|
|
On success,
|
|
|
|
.Fn vmem_xalloc
|
|
|
|
and
|
|
|
|
.Fn vmem_alloc
|
2011-09-03 02:07:33 +04:00
|
|
|
return 0.
|
2009-08-04 03:15:29 +04:00
|
|
|
Otherwise,
|
2011-09-03 02:07:33 +04:00
|
|
|
.Dv ENOMEM
|
2009-08-04 03:15:29 +04:00
|
|
|
is returned.
|
2006-10-22 15:14:52 +04:00
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh CODE REFERENCES
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
subsystem is implemented within the file
|
|
|
|
.Pa sys/kern/subr_vmem.c .
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr intro 9 ,
|
2009-08-04 03:15:29 +04:00
|
|
|
.Xr kmem 9 ,
|
2007-02-17 02:13:05 +03:00
|
|
|
.Xr memoryallocators 9 ,
|
2009-08-04 03:15:29 +04:00
|
|
|
.Xr uvm 9
|
2006-10-22 15:14:52 +04:00
|
|
|
.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
|
|
|
|
.\" ------------------------------------------------------------
|
2009-12-22 14:56:14 +03:00
|
|
|
.Sh AUTHORS
|
|
|
|
This implementation of
|
|
|
|
.Nm
|
|
|
|
was written by
|
|
|
|
.An YAMAMOTO Takashi .
|
2009-12-22 01:49:18 +03:00
|
|
|
.Sh BUGS
|
|
|
|
.Pp
|
|
|
|
.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 .
|