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.\" 289be1948fSRuslan Ermilov.Dd May 18, 2002 290aa028ffSDag-Erling Smørgrav.Dt ZONE 9 300aa028ffSDag-Erling Smørgrav.Os 310aa028ffSDag-Erling Smørgrav.Sh NAME 32382682b2SJeroen Ruigrok van der Werven.Nm uma_zcreate , 337c32182eSJeroen Ruigrok van der Werven.Nm uma_zalloc , 347c32182eSJeroen Ruigrok van der Werven.Nm uma_zfree , 357c32182eSJeroen Ruigrok van der Werven.Nm uma_zdestroy 36f5fccbbcSDag-Erling Smørgrav.Nd zone allocator 370aa028ffSDag-Erling Smørgrav.Sh SYNOPSIS 3832eef9aeSRuslan Ermilov.In sys/param.h 39f16b3c0dSChad David.In sys/queue.h 403a347a6eSJeroen Ruigrok van der Werven.In vm/uma.h 41382682b2SJeroen Ruigrok van der Werven.Ft uma_zone_t 429be1948fSRuslan Ermilov.Fo uma_zcreate 439be1948fSRuslan Ermilov.Fa "char *name" "int size" 449be1948fSRuslan Ermilov.Fa "uma_ctor ctor" "uma_dtor dtor" "uma_init uminit" "uma_fini fini" 459be1948fSRuslan Ermilov.Fa "int align" "u_int16_t flags" 469be1948fSRuslan Ermilov.Fc 479be1948fSRuslan Ermilov.Ft "void *" 489be1948fSRuslan Ermilov.Fn uma_zalloc "uma_zone_t zone" "int flags" 490aa028ffSDag-Erling Smørgrav.Ft void 50f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zfree "uma_zone_t zone" "void *item" 515ca0c84eSThomas Moestl.Ft void 52f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zdestroy "uma_zone_t zone" 530aa028ffSDag-Erling Smørgrav.Sh DESCRIPTION 540aa028ffSDag-Erling SmørgravThe zone allocator provides an efficient interface for managing 550aa028ffSDag-Erling Smørgravdynamically-sized collections of items of similar size. 560aa028ffSDag-Erling SmørgravThe zone allocator can work with preallocated zones as well as with 570aa028ffSDag-Erling Smørgravruntime-allocated ones, and is therefore available much earlier in the 580aa028ffSDag-Erling Smørgravboot process than other memory management routines. 590aa028ffSDag-Erling Smørgrav.Pp 600aa028ffSDag-Erling SmørgravA zone is an extensible collection of items of identical size. 610aa028ffSDag-Erling SmørgravThe zone allocator keeps track of which items are in use and which 62008080bdSJeroen Ruigrok van der Wervenare not, and provides functions for allocating items from the zone and 630aa028ffSDag-Erling Smørgravfor releasing them back (which makes them available for later use). 640aa028ffSDag-Erling Smørgrav.Pp 6590d83886SJulian ElischerThe zone allocator stores state information inside the items proper 6690d83886SJulian Elischerwhile they are not allocated, 6790d83886SJulian Elischerso structures that will be managed by the zone allocator 6890d83886SJulian Elischerand wish to use the type stable property of zones by leaving some fields 6990d83886SJulian Elischerpre-filled between allocations, must reserve 700aa028ffSDag-Erling Smørgravtwo pointers at the very beginning for internal use by the zone 710aa028ffSDag-Erling Smørgravallocator, as follows: 729be1948fSRuslan Ermilov.Bd -literal -offset indent 730aa028ffSDag-Erling Smørgravstruct my_item { 740aa028ffSDag-Erling Smørgrav struct my_item *z_rsvd1; 750aa028ffSDag-Erling Smørgrav struct my_item *z_rsvd2; 760aa028ffSDag-Erling Smørgrav /* rest of structure */ 770aa028ffSDag-Erling Smørgrav}; 780aa028ffSDag-Erling Smørgrav.Ed 790aa028ffSDag-Erling Smørgrav.Pp 8090d83886SJulian ElischerAlternatively they should assume those entries corrupted 81ced699e3SRuslan Ermilovafter each allocation. 82ced699e3SRuslan ErmilovAfter the first allocation of an item, 8390d83886SJulian Elischerit will have been cleared to zeroes, however subsequent allocations 8490d83886SJulian Elischerwill retain the contents as of the last free, with the exception of the 8590d83886SJulian Elischerfields mentioned above. 8690d83886SJulian Elischer.Pp 87382682b2SJeroen Ruigrok van der WervenThe 88382682b2SJeroen Ruigrok van der Werven.Fn uma_zcreate 89382682b2SJeroen Ruigrok van der Wervenfunction creates a new zone from which items may then be allocated from. 90382682b2SJeroen Ruigrok van der WervenThe 91382682b2SJeroen Ruigrok van der Werven.Fa name 92382682b2SJeroen Ruigrok van der Wervenargument is a text name of the zone for debugging and stats; this memory 93382682b2SJeroen Ruigrok van der Wervenshould not be freed until the zone has been deallocated. 94382682b2SJeroen Ruigrok van der Werven.Pp 950aa028ffSDag-Erling SmørgravTo allocate an item from a zone, simply call 967c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc 971437c79aSJeroen Ruigrok van der Wervenwith a pointer to that zone 981437c79aSJeroen Ruigrok van der Wervenand set the 99acff84fbSJeroen Ruigrok van der Werven.Fa flags 100acff84fbSJeroen Ruigrok van der Wervenargument to selected flags as documented in 101acff84fbSJeroen Ruigrok van der Werven.Xr malloc 9 . 1021437c79aSJeroen Ruigrok van der WervenIt will return a pointer to an item if successful, 1031437c79aSJeroen Ruigrok van der Wervenor 1040aa028ffSDag-Erling Smørgrav.Dv NULL 1050aa028ffSDag-Erling Smørgravin the rare case where all items in the zone are in use and the 1061437c79aSJeroen Ruigrok van der Wervenallocator is unable to grow the zone 1071437c79aSJeroen Ruigrok van der Wervenor when 1081437c79aSJeroen Ruigrok van der Werven.Dv M_NOWAIT 1091437c79aSJeroen Ruigrok van der Wervenis specified. 1100aa028ffSDag-Erling Smørgrav.Pp 1110aa028ffSDag-Erling SmørgravItems are released back to the zone from which they were allocated by 1120aa028ffSDag-Erling Smørgravcalling 1137c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree 1140aa028ffSDag-Erling Smørgravwith a pointer to the zone and a pointer to the item. 1155ca0c84eSThomas Moestl.Pp 11655407559SJeroen Ruigrok van der WervenCreated zones, 11755407559SJeroen Ruigrok van der Wervenwhich are empty, 1185ca0c84eSThomas Moestlcan be destroyed using 1197c32182eSJeroen Ruigrok van der Werven.Fn uma_zdestroy , 1205ca0c84eSThomas Moestlfreeing all memory that was allocated for the zone. 1215ca0c84eSThomas MoestlAll items allocated from the zone with 1227c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc 1235ca0c84eSThomas Moestlmust have been freed with 1247c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree 1255ca0c84eSThomas Moestlbefore. 1260aa028ffSDag-Erling Smørgrav.Sh RETURN VALUES 1270aa028ffSDag-Erling SmørgravThe 1287c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc 1290aa028ffSDag-Erling Smørgravfunction returns a pointer to an item, or 1300aa028ffSDag-Erling Smørgrav.Dv NULL 1310aa028ffSDag-Erling Smørgravif the zone ran out of unused items and the allocator was unable to 1320aa028ffSDag-Erling Smørgravenlarge it. 1330aa028ffSDag-Erling Smørgrav.Sh SEE ALSO 1340aa028ffSDag-Erling Smørgrav.Xr malloc 9 1350aa028ffSDag-Erling Smørgrav.Sh HISTORY 1360aa028ffSDag-Erling SmørgravThe zone allocator first appeared in 1370aa028ffSDag-Erling Smørgrav.Fx 3.0 . 1389a795583SJeroen Ruigrok van der WervenIt was radically changed in 1399a795583SJeroen Ruigrok van der Werven.Fx 5.0 1409a795583SJeroen Ruigrok van der Wervento function as a slab allocator. 1410aa028ffSDag-Erling Smørgrav.Sh AUTHORS 1420aa028ffSDag-Erling Smørgrav.An -nosplit 1430aa028ffSDag-Erling SmørgravThe zone allocator was written by 1440aa028ffSDag-Erling Smørgrav.An John S. Dyson . 1459a795583SJeroen Ruigrok van der WervenThe zone allocator was rewritten in large parts by 1469a795583SJeroen Ruigrok van der Werven.An Jeff Roberson Aq jeff@FreeBSD.org 1479a795583SJeroen Ruigrok van der Wervento function as a slab allocator. 1480aa028ffSDag-Erling Smørgrav.Pp 1490aa028ffSDag-Erling SmørgravThis manual page was written by 1500aa028ffSDag-Erling Smørgrav.An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org . 1519a795583SJeroen Ruigrok van der WervenChanges for UMA by 1529a795583SJeroen Ruigrok van der Werven.An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org . 153