2001-01-27 19:13:08 +00:00
|
|
|
|
.\"-
|
|
|
|
|
.\" Copyright (c) 2001 Dag-Erling Co<43>dan Sm<53>rgrav
|
|
|
|
|
.\" 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.
|
|
|
|
|
.\"
|
|
|
|
|
.\" $FreeBSD$
|
|
|
|
|
.\"
|
|
|
|
|
.Dd January 27, 2001
|
|
|
|
|
.Dt ZONE 9
|
|
|
|
|
.Os
|
|
|
|
|
.Sh NAME
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Nm uma_zalloc ,
|
|
|
|
|
.Nm uma_zfree ,
|
|
|
|
|
.Nm uma_zdestroy
|
2001-01-29 08:59:30 +00:00
|
|
|
|
.Nd zone allocator
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
|
.In sys/param.h
|
2001-12-26 23:14:04 +00:00
|
|
|
|
.In sys/queue.h
|
2002-04-30 08:51:42 +00:00
|
|
|
|
.In vm/uma.h
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Ft void *
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zalloc "vm_zone_t z"
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Ft void
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zfree "vm_zone_t z" "void *item"
|
2001-08-09 16:01:27 +00:00
|
|
|
|
.Ft void
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zdestroy "vm_zone_t z"
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
|
The zone allocator provides an efficient interface for managing
|
|
|
|
|
dynamically-sized collections of items of similar size.
|
|
|
|
|
The zone allocator can work with preallocated zones as well as with
|
|
|
|
|
runtime-allocated ones, and is therefore available much earlier in the
|
|
|
|
|
boot process than other memory management routines.
|
|
|
|
|
.Pp
|
|
|
|
|
A zone is an extensible collection of items of identical size.
|
|
|
|
|
The zone allocator keeps track of which items are in use and which
|
2002-04-30 09:38:52 +00:00
|
|
|
|
are not, and provides functions for allocating items from the zone and
|
2001-01-27 19:13:08 +00:00
|
|
|
|
for releasing them back (which makes them available for later use).
|
|
|
|
|
.Pp
|
2001-12-14 19:19:31 +00:00
|
|
|
|
The zone allocator stores state information inside the items proper
|
|
|
|
|
while they are not allocated,
|
|
|
|
|
so structures that will be managed by the zone allocator
|
|
|
|
|
and wish to use the type stable property of zones by leaving some fields
|
|
|
|
|
pre-filled between allocations, must reserve
|
2001-01-27 19:13:08 +00:00
|
|
|
|
two pointers at the very beginning for internal use by the zone
|
|
|
|
|
allocator, as follows:
|
|
|
|
|
.Bd -literal
|
|
|
|
|
struct my_item {
|
|
|
|
|
struct my_item *z_rsvd1;
|
|
|
|
|
struct my_item *z_rsvd2;
|
|
|
|
|
/* rest of structure */
|
|
|
|
|
};
|
|
|
|
|
.Ed
|
|
|
|
|
.Pp
|
2001-12-14 19:19:31 +00:00
|
|
|
|
Alternatively they should assume those entries corrupted
|
2002-01-10 13:02:55 +00:00
|
|
|
|
after each allocation.
|
|
|
|
|
After the first allocation of an item,
|
|
|
|
|
it will have been cleared to zeroes, however subsequent allocations
|
|
|
|
|
will retain the contents as of the last free, with the exception of the
|
2001-12-14 19:19:31 +00:00
|
|
|
|
fields mentioned above.
|
|
|
|
|
.Pp
|
2001-01-27 19:13:08 +00:00
|
|
|
|
To allocate an item from a zone, simply call
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zalloc
|
2001-01-27 19:13:08 +00:00
|
|
|
|
with a pointer to that zone; it will return a pointer to an item, or
|
|
|
|
|
.Dv NULL
|
|
|
|
|
in the rare case where all items in the zone are in use and the
|
|
|
|
|
allocator is unable to grow the zone.
|
|
|
|
|
.Pp
|
|
|
|
|
Items are released back to the zone from which they were allocated by
|
|
|
|
|
calling
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zfree
|
2001-01-27 19:13:08 +00:00
|
|
|
|
with a pointer to the zone and a pointer to the item.
|
2001-08-09 16:01:27 +00:00
|
|
|
|
.Pp
|
|
|
|
|
Zones created with
|
|
|
|
|
.Fn zinit
|
|
|
|
|
can be destroyed using
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zdestroy ,
|
2001-08-09 16:01:27 +00:00
|
|
|
|
freeing all memory that was allocated for the zone.
|
|
|
|
|
All items allocated from the zone with
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zalloc
|
2001-08-09 16:01:27 +00:00
|
|
|
|
must have been freed with
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zfree
|
2001-08-09 16:01:27 +00:00
|
|
|
|
before.
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Fn zinit
|
|
|
|
|
function returns a pointer to a fully initialized
|
2001-01-29 08:59:30 +00:00
|
|
|
|
.Vt "struct vm_zone" ,
|
2001-01-27 19:13:08 +00:00
|
|
|
|
or
|
|
|
|
|
.Dv NULL
|
|
|
|
|
if it was unable to
|
|
|
|
|
.Fn malloc
|
|
|
|
|
a
|
2002-04-30 09:47:50 +00:00
|
|
|
|
.Vt "struct vm_zone" .
|
2001-01-27 19:13:08 +00:00
|
|
|
|
.Pp
|
|
|
|
|
The
|
2002-04-30 12:45:31 +00:00
|
|
|
|
.Fn uma_zalloc
|
2001-01-27 19:13:08 +00:00
|
|
|
|
function returns a pointer to an item, or
|
|
|
|
|
.Dv NULL
|
|
|
|
|
if the zone ran out of unused items and the allocator was unable to
|
|
|
|
|
enlarge it.
|
|
|
|
|
.Sh SEE ALSO
|
|
|
|
|
.Xr malloc 9
|
|
|
|
|
.Sh HISTORY
|
|
|
|
|
The zone allocator first appeared in
|
|
|
|
|
.Fx 3.0 .
|
|
|
|
|
.Sh AUTHORS
|
|
|
|
|
.An -nosplit
|
|
|
|
|
The zone allocator was written by
|
|
|
|
|
.An John S. Dyson .
|
|
|
|
|
.Pp
|
|
|
|
|
This manual page was written by
|
|
|
|
|
.An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
|