xref: /freebsd/share/man/man9/zone.9 (revision 2f891cd504eabbf495af9c1fcbd0d5c44feb16ac)
10aa028ffSDag-Erling Smørgrav.\"-
26e18fca1SUlrich Spörlein.\" 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.\"
28*2f891cd5SPawel Jakub Dawidek.Dd December 7, 2012
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 ,
346a4c41d1SRemko Lodder.Nm uma_zalloc_arg ,
357c32182eSJeroen Ruigrok van der Werven.Nm uma_zfree ,
366a4c41d1SRemko Lodder.Nm uma_zfree_arg ,
37d7bbb21aSHartmut Brandt.Nm uma_zdestroy ,
38c4ae7908SLawrence Stewart.Nm uma_zone_set_max,
39c4ae7908SLawrence Stewart.Nm uma_zone_get_max,
40*2f891cd5SPawel Jakub Dawidek.Nm uma_zone_get_cur,
41*2f891cd5SPawel Jakub Dawidek.Nm uma_zone_set_warning
42f5fccbbcSDag-Erling Smørgrav.Nd zone allocator
430aa028ffSDag-Erling Smørgrav.Sh SYNOPSIS
4432eef9aeSRuslan Ermilov.In sys/param.h
45f16b3c0dSChad David.In sys/queue.h
463a347a6eSJeroen Ruigrok van der Werven.In vm/uma.h
47382682b2SJeroen Ruigrok van der Werven.Ft uma_zone_t
489be1948fSRuslan Ermilov.Fo uma_zcreate
499be1948fSRuslan Ermilov.Fa "char *name" "int size"
509be1948fSRuslan Ermilov.Fa "uma_ctor ctor" "uma_dtor dtor" "uma_init uminit" "uma_fini fini"
516b99842aSEd Schouten.Fa "int align" "uint16_t flags"
529be1948fSRuslan Ermilov.Fc
539be1948fSRuslan Ermilov.Ft "void *"
549be1948fSRuslan Ermilov.Fn uma_zalloc "uma_zone_t zone" "int flags"
556a4c41d1SRemko Lodder.Ft "void *"
566a4c41d1SRemko Lodder.Fn uma_zalloc_arg "uma_zone_t zone" "void *arg" "int flags"
570aa028ffSDag-Erling Smørgrav.Ft void
58f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zfree "uma_zone_t zone" "void *item"
595ca0c84eSThomas Moestl.Ft void
606a4c41d1SRemko Lodder.Fn uma_zfree_arg "uma_zone_t zone" "void *item" "void *arg"
616a4c41d1SRemko Lodder.Ft void
62f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zdestroy "uma_zone_t zone"
631c6cae97SLawrence Stewart.Ft int
64d7bbb21aSHartmut Brandt.Fn uma_zone_set_max "uma_zone_t zone" "int nitems"
65c4ae7908SLawrence Stewart.Ft int
66c4ae7908SLawrence Stewart.Fn uma_zone_get_max "uma_zone_t zone"
67c4ae7908SLawrence Stewart.Ft int
68c4ae7908SLawrence Stewart.Fn uma_zone_get_cur "uma_zone_t zone"
69*2f891cd5SPawel Jakub Dawidek.Ft void
70*2f891cd5SPawel Jakub Dawidek.Fn uma_zone_set_warning "uma_zone_t zone" "const char *warning"
710aa028ffSDag-Erling Smørgrav.Sh DESCRIPTION
720aa028ffSDag-Erling SmørgravThe zone allocator provides an efficient interface for managing
730aa028ffSDag-Erling Smørgravdynamically-sized collections of items of similar size.
740aa028ffSDag-Erling SmørgravThe zone allocator can work with preallocated zones as well as with
750aa028ffSDag-Erling Smørgravruntime-allocated ones, and is therefore available much earlier in the
760aa028ffSDag-Erling Smørgravboot process than other memory management routines.
770aa028ffSDag-Erling Smørgrav.Pp
780aa028ffSDag-Erling SmørgravA zone is an extensible collection of items of identical size.
790aa028ffSDag-Erling SmørgravThe zone allocator keeps track of which items are in use and which
80008080bdSJeroen Ruigrok van der Wervenare not, and provides functions for allocating items from the zone and
810aa028ffSDag-Erling Smørgravfor releasing them back (which makes them available for later use).
820aa028ffSDag-Erling Smørgrav.Pp
83ced699e3SRuslan ErmilovAfter the first allocation of an item,
8490d83886SJulian Elischerit will have been cleared to zeroes, however subsequent allocations
857251f557SKonstantin Belousovwill retain the contents as of the last free.
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
954919e8cbSAlfred PerlsteinThe
964919e8cbSAlfred Perlstein.Fa ctor
974919e8cbSAlfred Perlsteinand
984919e8cbSAlfred Perlstein.Fa dtor
994919e8cbSAlfred Perlsteinarguments are callback functions that are called by
1004919e8cbSAlfred Perlsteinthe uma subsystem at the time of the call to
1014919e8cbSAlfred Perlstein.Fn uma_zalloc
1024919e8cbSAlfred Perlsteinand
1034919e8cbSAlfred Perlstein.Fn uma_zfree
104d962d52aSRuslan Ermilovrespectively.
105d962d52aSRuslan ErmilovTheir purpose is to provide hooks for initializing or
1064919e8cbSAlfred Perlsteindestroying things that need to be done at the time of the allocation
107d962d52aSRuslan Ermilovor release of a resource.
108e07f1d5fSHiten PandyaA good usage for the
1094919e8cbSAlfred Perlstein.Fa ctor
1104919e8cbSAlfred Perlsteinand
1114919e8cbSAlfred Perlstein.Fa dtor
1124919e8cbSAlfred Perlsteincallbacks
1134919e8cbSAlfred Perlsteinmight be to adjust a global count of the number of objects allocated.
1144919e8cbSAlfred Perlstein.Pp
1154919e8cbSAlfred PerlsteinThe
1164919e8cbSAlfred Perlstein.Fa uminit
1174919e8cbSAlfred Perlsteinand
1184919e8cbSAlfred Perlstein.Fa fini
1194919e8cbSAlfred Perlsteinarguments are used to optimize the allocation of
120d962d52aSRuslan Ermilovobjects from the zone.
121d962d52aSRuslan ErmilovThey are called by the uma subsystem whenever
1224919e8cbSAlfred Perlsteinit needs to allocate or free several items to satisfy requests or memory
123d962d52aSRuslan Ermilovpressure.
124d962d52aSRuslan ErmilovA good use for the
125d962d52aSRuslan Ermilov.Fa uminit
126d962d52aSRuslan Ermilovand
127d962d52aSRuslan Ermilov.Fa fini
128d962d52aSRuslan Ermilovcallbacks might be to
129d962d52aSRuslan Ermilovinitialize and destroy mutexes contained within the object.
130d962d52aSRuslan ErmilovThis would
1314919e8cbSAlfred Perlsteinallow one to re-use already initialized mutexes when an object is returned
132d962d52aSRuslan Ermilovfrom the uma subsystem's object cache.
133d962d52aSRuslan ErmilovThey are not called on each call to
1344919e8cbSAlfred Perlstein.Fn uma_zalloc
1354919e8cbSAlfred Perlsteinand
1364919e8cbSAlfred Perlstein.Fn uma_zfree
1374919e8cbSAlfred Perlsteinbut rather in a batch mode on several objects.
1384919e8cbSAlfred Perlstein.Pp
1390aa028ffSDag-Erling SmørgravTo allocate an item from a zone, simply call
1407c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
1411437c79aSJeroen Ruigrok van der Wervenwith a pointer to that zone
1421437c79aSJeroen Ruigrok van der Wervenand set the
143acff84fbSJeroen Ruigrok van der Werven.Fa flags
144acff84fbSJeroen Ruigrok van der Wervenargument to selected flags as documented in
145acff84fbSJeroen Ruigrok van der Werven.Xr malloc 9 .
1461437c79aSJeroen Ruigrok van der WervenIt will return a pointer to an item if successful,
1471437c79aSJeroen Ruigrok van der Wervenor
1480aa028ffSDag-Erling Smørgrav.Dv NULL
1490aa028ffSDag-Erling Smørgravin the rare case where all items in the zone are in use and the
1501437c79aSJeroen Ruigrok van der Wervenallocator is unable to grow the zone
1512864c799SEdward Tomasz Napieralaand
1521437c79aSJeroen Ruigrok van der Werven.Dv M_NOWAIT
1531437c79aSJeroen Ruigrok van der Wervenis specified.
1540aa028ffSDag-Erling Smørgrav.Pp
1550aa028ffSDag-Erling SmørgravItems are released back to the zone from which they were allocated by
1560aa028ffSDag-Erling Smørgravcalling
1577c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
1580aa028ffSDag-Erling Smørgravwith a pointer to the zone and a pointer to the item.
15920ed0cb0SMatthew D FlemingIf
16020ed0cb0SMatthew D Fleming.Fa item
16120ed0cb0SMatthew D Flemingis
16220ed0cb0SMatthew D Fleming.Dv NULL ,
16320ed0cb0SMatthew D Flemingthen
16420ed0cb0SMatthew D Fleming.Fn uma_zfree
16520ed0cb0SMatthew D Flemingdoes nothing.
1665ca0c84eSThomas Moestl.Pp
1676a4c41d1SRemko LodderThe variations
1686a4c41d1SRemko Lodder.Fn uma_zalloc_arg
1696a4c41d1SRemko Lodderand
1706a4c41d1SRemko Lodder.Fn uma_zfree_arg
1716a4c41d1SRemko Lodderallow to
1726a4c41d1SRemko Lodderspecify an argument for the
1736a4c41d1SRemko Lodder.Dv ctor
1746a4c41d1SRemko Lodderand
1756a4c41d1SRemko Lodder.Dv dtor
1766a4c41d1SRemko Lodderfunctions, respectively.
1776a4c41d1SRemko Lodder.Pp
17855407559SJeroen Ruigrok van der WervenCreated zones,
17955407559SJeroen Ruigrok van der Wervenwhich are empty,
1805ca0c84eSThomas Moestlcan be destroyed using
1817c32182eSJeroen Ruigrok van der Werven.Fn uma_zdestroy ,
1825ca0c84eSThomas Moestlfreeing all memory that was allocated for the zone.
1835ca0c84eSThomas MoestlAll items allocated from the zone with
1847c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
1855ca0c84eSThomas Moestlmust have been freed with
1867c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
1875ca0c84eSThomas Moestlbefore.
188d7bbb21aSHartmut Brandt.Pp
189c4ae7908SLawrence StewartThe
190d7bbb21aSHartmut Brandt.Fn uma_zone_set_max
191c4ae7908SLawrence Stewartfunction limits the number of items
192c4ae7908SLawrence Stewart.Pq and therefore memory
193c4ae7908SLawrence Stewartthat can be allocated to
194c4ae7908SLawrence Stewart.Fa zone .
195d7bbb21aSHartmut BrandtThe
196d7bbb21aSHartmut Brandt.Fa nitems
197c4ae7908SLawrence Stewartargument specifies the requested upper limit number of items.
1981c6cae97SLawrence StewartThe effective limit is returned to the caller, as it may end up being higher
1991c6cae97SLawrence Stewartthan requested due to the implementation rounding up to ensure all memory pages
2001c6cae97SLawrence Stewartallocated to the zone are utilised to capacity.
201c4ae7908SLawrence StewartThe limit applies to the total number of items in the zone, which includes
202d7bbb21aSHartmut Brandtallocated items, free items and free items in the per-cpu caches.
203d7bbb21aSHartmut BrandtOn systems with more than one CPU it may not be possible to allocate
204d7bbb21aSHartmut Brandtthe specified number of items even when there is no shortage of memory,
205d7bbb21aSHartmut Brandtbecause all of the remaining free items may be in the caches of the
206d7bbb21aSHartmut Brandtother CPUs when the limit is hit.
207c4ae7908SLawrence Stewart.Pp
208c4ae7908SLawrence StewartThe
209c4ae7908SLawrence Stewart.Fn uma_zone_get_max
210c4ae7908SLawrence Stewartfunction returns the effective upper limit number of items for a zone.
211c4ae7908SLawrence Stewart.Pp
212c4ae7908SLawrence StewartThe
213c4ae7908SLawrence Stewart.Fn uma_zone_get_cur
214c4ae7908SLawrence Stewartfunction returns the approximate current occupancy of the zone.
215c4ae7908SLawrence StewartThe returned value is approximate because appropriate synchronisation to
2163102cfe2SGlen Barberdetermine an exact value is not performed by the implementation.
217c4ae7908SLawrence StewartThis ensures low overhead at the expense of potentially stale data being used
218c4ae7908SLawrence Stewartin the calculation.
219*2f891cd5SPawel Jakub Dawidek.Pp
220*2f891cd5SPawel Jakub DawidekThe
221*2f891cd5SPawel Jakub Dawidek.Fn uma_zone_set_warning
222*2f891cd5SPawel Jakub Dawidekfunction sets a warning that will be printed on the system console when the
223*2f891cd5SPawel Jakub Dawidekgiven zone becomes full and fails to allocate an item.
224*2f891cd5SPawel Jakub DawidekThe warning will be printed not often than every five minutes.
225*2f891cd5SPawel Jakub DawidekWarnings can be turned off globally by setting the
226*2f891cd5SPawel Jakub Dawidek.Va vm.zone_warnings
227*2f891cd5SPawel Jakub Dawideksysctl tunable to
228*2f891cd5SPawel Jakub Dawidek.Va 0 .
2290aa028ffSDag-Erling Smørgrav.Sh RETURN VALUES
2300aa028ffSDag-Erling SmørgravThe
2317c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
2320aa028ffSDag-Erling Smørgravfunction returns a pointer to an item, or
2330aa028ffSDag-Erling Smørgrav.Dv NULL
2342864c799SEdward Tomasz Napieralaif the zone ran out of unused items
2352864c799SEdward Tomasz Napieralaand
2362864c799SEdward Tomasz Napierala.Dv M_NOWAIT
2372864c799SEdward Tomasz Napieralawas specified.
2380aa028ffSDag-Erling Smørgrav.Sh SEE ALSO
2390aa028ffSDag-Erling Smørgrav.Xr malloc 9
2400aa028ffSDag-Erling Smørgrav.Sh HISTORY
2410aa028ffSDag-Erling SmørgravThe zone allocator first appeared in
2420aa028ffSDag-Erling Smørgrav.Fx 3.0 .
2439a795583SJeroen Ruigrok van der WervenIt was radically changed in
2449a795583SJeroen Ruigrok van der Werven.Fx 5.0
2459a795583SJeroen Ruigrok van der Wervento function as a slab allocator.
2460aa028ffSDag-Erling Smørgrav.Sh AUTHORS
2470aa028ffSDag-Erling Smørgrav.An -nosplit
2480aa028ffSDag-Erling SmørgravThe zone allocator was written by
2490aa028ffSDag-Erling Smørgrav.An John S. Dyson .
2509a795583SJeroen Ruigrok van der WervenThe zone allocator was rewritten in large parts by
2519a795583SJeroen Ruigrok van der Werven.An Jeff Roberson Aq jeff@FreeBSD.org
2529a795583SJeroen Ruigrok van der Wervento function as a slab allocator.
2530aa028ffSDag-Erling Smørgrav.Pp
2540aa028ffSDag-Erling SmørgravThis manual page was written by
25509e06539SDag-Erling Smørgrav.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
2569a795583SJeroen Ruigrok van der WervenChanges for UMA by
2579a795583SJeroen Ruigrok van der Werven.An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org .
258