xref: /freebsd/share/man/man9/zone.9 (revision 1437c79a4a15c5a3e5fa77b4d7ba5303ea06abdf)
10aa028ffSDag-Erling Smørgrav.\"-
20aa028ffSDag-Erling Smørgrav.\" Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
30aa028ffSDag-Erling Smørgrav.\" All rights reserved.
40aa028ffSDag-Erling Smørgrav.\"
50aa028ffSDag-Erling Smørgrav.\" Redistribution and use in source and binary forms, with or without
60aa028ffSDag-Erling Smørgrav.\" modification, are permitted provided that the following conditions
70aa028ffSDag-Erling Smørgrav.\" are met:
80aa028ffSDag-Erling Smørgrav.\" 1. Redistributions of source code must retain the above copyright
90aa028ffSDag-Erling Smørgrav.\"    notice, this list of conditions and the following disclaimer.
100aa028ffSDag-Erling Smørgrav.\" 2. Redistributions in binary form must reproduce the above copyright
110aa028ffSDag-Erling Smørgrav.\"    notice, this list of conditions and the following disclaimer in the
120aa028ffSDag-Erling Smørgrav.\"    documentation and/or other materials provided with the distribution.
130aa028ffSDag-Erling Smørgrav.\"
140aa028ffSDag-Erling Smørgrav.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
150aa028ffSDag-Erling Smørgrav.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160aa028ffSDag-Erling Smørgrav.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
170aa028ffSDag-Erling Smørgrav.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
180aa028ffSDag-Erling Smørgrav.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
190aa028ffSDag-Erling Smørgrav.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
200aa028ffSDag-Erling Smørgrav.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
210aa028ffSDag-Erling Smørgrav.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
220aa028ffSDag-Erling Smørgrav.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
230aa028ffSDag-Erling Smørgrav.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
240aa028ffSDag-Erling Smørgrav.\" SUCH DAMAGE.
250aa028ffSDag-Erling Smørgrav.\"
260aa028ffSDag-Erling Smørgrav.\" $FreeBSD$
270aa028ffSDag-Erling Smørgrav.\"
280aa028ffSDag-Erling Smørgrav.Dd January 27, 2001
290aa028ffSDag-Erling Smørgrav.Dt ZONE 9
300aa028ffSDag-Erling Smørgrav.Os
310aa028ffSDag-Erling Smørgrav.Sh NAME
327c32182eSJeroen Ruigrok van der Werven.Nm uma_zalloc ,
337c32182eSJeroen Ruigrok van der Werven.Nm uma_zfree ,
347c32182eSJeroen Ruigrok van der Werven.Nm uma_zdestroy
35f5fccbbcSDag-Erling Smørgrav.Nd zone allocator
360aa028ffSDag-Erling Smørgrav.Sh SYNOPSIS
3732eef9aeSRuslan Ermilov.In sys/param.h
38f16b3c0dSChad David.In sys/queue.h
393a347a6eSJeroen Ruigrok van der Werven.In vm/uma.h
400aa028ffSDag-Erling Smørgrav.Ft void *
41f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zalloc "uma_zone_t zone, int wait"
420aa028ffSDag-Erling Smørgrav.Ft void
43f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zfree "uma_zone_t zone" "void *item"
445ca0c84eSThomas Moestl.Ft void
45f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zdestroy "uma_zone_t zone"
460aa028ffSDag-Erling Smørgrav.Sh DESCRIPTION
470aa028ffSDag-Erling SmørgravThe zone allocator provides an efficient interface for managing
480aa028ffSDag-Erling Smørgravdynamically-sized collections of items of similar size.
490aa028ffSDag-Erling SmørgravThe zone allocator can work with preallocated zones as well as with
500aa028ffSDag-Erling Smørgravruntime-allocated ones, and is therefore available much earlier in the
510aa028ffSDag-Erling Smørgravboot process than other memory management routines.
520aa028ffSDag-Erling Smørgrav.Pp
530aa028ffSDag-Erling SmørgravA zone is an extensible collection of items of identical size.
540aa028ffSDag-Erling SmørgravThe zone allocator keeps track of which items are in use and which
55008080bdSJeroen Ruigrok van der Wervenare not, and provides functions for allocating items from the zone and
560aa028ffSDag-Erling Smørgravfor releasing them back (which makes them available for later use).
570aa028ffSDag-Erling Smørgrav.Pp
5890d83886SJulian ElischerThe zone allocator stores state information inside the items proper
5990d83886SJulian Elischerwhile they are not allocated,
6090d83886SJulian Elischerso structures that will be managed by the zone allocator
6190d83886SJulian Elischerand wish to use the type stable property of zones by leaving some fields
6290d83886SJulian Elischerpre-filled between allocations, must reserve
630aa028ffSDag-Erling Smørgravtwo pointers at the very beginning for internal use by the zone
640aa028ffSDag-Erling Smørgravallocator, as follows:
650aa028ffSDag-Erling Smørgrav.Bd -literal
660aa028ffSDag-Erling Smørgravstruct my_item {
670aa028ffSDag-Erling Smørgrav        struct my_item  *z_rsvd1;
680aa028ffSDag-Erling Smørgrav        struct my_item  *z_rsvd2;
690aa028ffSDag-Erling Smørgrav        /* rest of structure */
700aa028ffSDag-Erling Smørgrav};
710aa028ffSDag-Erling Smørgrav.Ed
720aa028ffSDag-Erling Smørgrav.Pp
7390d83886SJulian ElischerAlternatively they should assume those entries corrupted
74ced699e3SRuslan Ermilovafter each allocation.
75ced699e3SRuslan ErmilovAfter the first allocation of an item,
7690d83886SJulian Elischerit will have been cleared to zeroes, however subsequent allocations
7790d83886SJulian Elischerwill retain the contents as of the last free, with the exception of the
7890d83886SJulian Elischerfields mentioned above.
7990d83886SJulian Elischer.Pp
800aa028ffSDag-Erling SmørgravTo allocate an item from a zone, simply call
817c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
821437c79aSJeroen Ruigrok van der Wervenwith a pointer to that zone
831437c79aSJeroen Ruigrok van der Wervenand set the
841437c79aSJeroen Ruigrok van der Werven.Fa wait
851437c79aSJeroen Ruigrok van der Wervenargument to
861437c79aSJeroen Ruigrok van der Werven.Dv M_WAITOK
871437c79aSJeroen Ruigrok van der Wervenor
881437c79aSJeroen Ruigrok van der Werven.Dv M_NOWAIT
891437c79aSJeroen Ruigrok van der Wervendepending on whether or not to block while allocating memory for this zone,
901437c79aSJeroen Ruigrok van der Wervenshould we run out.
911437c79aSJeroen Ruigrok van der WervenIt will return a pointer to an item if successful,
921437c79aSJeroen Ruigrok van der Wervenor
930aa028ffSDag-Erling Smørgrav.Dv NULL
940aa028ffSDag-Erling Smørgravin the rare case where all items in the zone are in use and the
951437c79aSJeroen Ruigrok van der Wervenallocator is unable to grow the zone
961437c79aSJeroen Ruigrok van der Wervenor when
971437c79aSJeroen Ruigrok van der Werven.Dv M_NOWAIT
981437c79aSJeroen Ruigrok van der Wervenis specified.
990aa028ffSDag-Erling Smørgrav.Pp
1000aa028ffSDag-Erling SmørgravItems are released back to the zone from which they were allocated by
1010aa028ffSDag-Erling Smørgravcalling
1027c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
1030aa028ffSDag-Erling Smørgravwith a pointer to the zone and a pointer to the item.
1045ca0c84eSThomas Moestl.Pp
1055ca0c84eSThomas MoestlZones created with
1065ca0c84eSThomas Moestl.Fn zinit
1075ca0c84eSThomas Moestlcan be destroyed using
1087c32182eSJeroen Ruigrok van der Werven.Fn uma_zdestroy ,
1095ca0c84eSThomas Moestlfreeing all memory that was allocated for the zone.
1105ca0c84eSThomas MoestlAll items allocated from the zone with
1117c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
1125ca0c84eSThomas Moestlmust have been freed with
1137c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
1145ca0c84eSThomas Moestlbefore.
1150aa028ffSDag-Erling Smørgrav.Sh RETURN VALUES
1160aa028ffSDag-Erling Smørgrav.Pp
1170aa028ffSDag-Erling SmørgravThe
1180aa028ffSDag-Erling Smørgrav.Fn zinit
1190aa028ffSDag-Erling Smørgravfunction returns a pointer to a fully initialized
120f5fccbbcSDag-Erling Smørgrav.Vt "struct vm_zone" ,
1210aa028ffSDag-Erling Smørgravor
1220aa028ffSDag-Erling Smørgrav.Dv NULL
1230aa028ffSDag-Erling Smørgravif it was unable to
1240aa028ffSDag-Erling Smørgrav.Fn malloc
1250aa028ffSDag-Erling Smørgrava
12677776e8cSJeroen Ruigrok van der Werven.Vt "struct vm_zone" .
1270aa028ffSDag-Erling Smørgrav.Pp
1280aa028ffSDag-Erling SmørgravThe
1297c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
1300aa028ffSDag-Erling Smørgravfunction returns a pointer to an item, or
1310aa028ffSDag-Erling Smørgrav.Dv NULL
1320aa028ffSDag-Erling Smørgravif the zone ran out of unused items and the allocator was unable to
1330aa028ffSDag-Erling Smørgravenlarge it.
1340aa028ffSDag-Erling Smørgrav.Sh SEE ALSO
1350aa028ffSDag-Erling Smørgrav.Xr malloc 9
1360aa028ffSDag-Erling Smørgrav.Sh HISTORY
1370aa028ffSDag-Erling SmørgravThe zone allocator first appeared in
1380aa028ffSDag-Erling Smørgrav.Fx 3.0 .
1390aa028ffSDag-Erling Smørgrav.Sh AUTHORS
1400aa028ffSDag-Erling Smørgrav.An -nosplit
1410aa028ffSDag-Erling SmørgravThe zone allocator was written by
1420aa028ffSDag-Erling Smørgrav.An John S. Dyson .
1430aa028ffSDag-Erling Smørgrav.Pp
1440aa028ffSDag-Erling SmørgravThis manual page was written by
1450aa028ffSDag-Erling Smørgrav.An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
146