xref: /freebsd/share/man/man9/zone.9 (revision 0766f278d88b93e81e8b81cac6258cf75cde3e35)
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*0766f278SJonathan T. Looney.Dd June 13, 2018
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 ,
3593f31533SJeff Roberson.Nm uma_zalloc_domain ,
367c32182eSJeroen Ruigrok van der Werven.Nm uma_zfree ,
376a4c41d1SRemko Lodder.Nm uma_zfree_arg ,
3893f31533SJeff Roberson.Nm uma_zfree_domain ,
39d7bbb21aSHartmut Brandt.Nm uma_zdestroy ,
40c4ae7908SLawrence Stewart.Nm uma_zone_set_max ,
41c4ae7908SLawrence Stewart.Nm uma_zone_get_max ,
422f891cd5SPawel Jakub Dawidek.Nm uma_zone_get_cur ,
4354503a13SJonathan T. Looney.Nm uma_zone_set_warning ,
4454503a13SJonathan T. Looney.Nm uma_zone_set_maxaction
45f5fccbbcSDag-Erling Smørgrav.Nd zone allocator
460aa028ffSDag-Erling Smørgrav.Sh SYNOPSIS
4732eef9aeSRuslan Ermilov.In sys/param.h
48f16b3c0dSChad David.In sys/queue.h
493a347a6eSJeroen Ruigrok van der Werven.In vm/uma.h
50382682b2SJeroen Ruigrok van der Werven.Ft uma_zone_t
519be1948fSRuslan Ermilov.Fo uma_zcreate
529be1948fSRuslan Ermilov.Fa "char *name" "int size"
539be1948fSRuslan Ermilov.Fa "uma_ctor ctor" "uma_dtor dtor" "uma_init uminit" "uma_fini fini"
546b99842aSEd Schouten.Fa "int align" "uint16_t flags"
559be1948fSRuslan Ermilov.Fc
569be1948fSRuslan Ermilov.Ft "void *"
579be1948fSRuslan Ermilov.Fn uma_zalloc "uma_zone_t zone" "int flags"
586a4c41d1SRemko Lodder.Ft "void *"
596a4c41d1SRemko Lodder.Fn uma_zalloc_arg "uma_zone_t zone" "void *arg" "int flags"
6093f31533SJeff Roberson.Ft "void *"
6193f31533SJeff Roberson.Fn uma_zalloc_domain "uma_zone_t zone" "void *arg" "int domain" "int flags"
620aa028ffSDag-Erling Smørgrav.Ft void
63f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zfree "uma_zone_t zone" "void *item"
645ca0c84eSThomas Moestl.Ft void
656a4c41d1SRemko Lodder.Fn uma_zfree_arg "uma_zone_t zone" "void *item" "void *arg"
666a4c41d1SRemko Lodder.Ft void
6793f31533SJeff Roberson.Fn uma_zfree_domain "uma_zone_t zone" "void *item" "void *arg"
6893f31533SJeff Roberson.Ft void
69f1de92e6SJeroen Ruigrok van der Werven.Fn uma_zdestroy "uma_zone_t zone"
701c6cae97SLawrence Stewart.Ft int
71d7bbb21aSHartmut Brandt.Fn uma_zone_set_max "uma_zone_t zone" "int nitems"
72c4ae7908SLawrence Stewart.Ft int
73c4ae7908SLawrence Stewart.Fn uma_zone_get_max "uma_zone_t zone"
74c4ae7908SLawrence Stewart.Ft int
75c4ae7908SLawrence Stewart.Fn uma_zone_get_cur "uma_zone_t zone"
762f891cd5SPawel Jakub Dawidek.Ft void
772f891cd5SPawel Jakub Dawidek.Fn uma_zone_set_warning "uma_zone_t zone" "const char *warning"
7854503a13SJonathan T. Looney.Ft void
7954503a13SJonathan T. Looney.Fn uma_zone_set_maxaction "uma_zone_t zone" "void (*maxaction)(uma_zone_t)"
800a5a3ccbSGleb Smirnoff.In sys/sysctl.h
810a5a3ccbSGleb Smirnoff.Fn SYSCTL_UMA_MAX parent nbr name access zone descr
820a5a3ccbSGleb Smirnoff.Fn SYSCTL_ADD_UMA_MAX ctx parent nbr name access zone descr
830a5a3ccbSGleb Smirnoff.Fn SYSCTL_UMA_CUR parent nbr name access zone descr
840a5a3ccbSGleb Smirnoff.Fn SYSCTL_ADD_UMA_CUR ctx parent nbr name access zone descr
850aa028ffSDag-Erling Smørgrav.Sh DESCRIPTION
860aa028ffSDag-Erling SmørgravThe zone allocator provides an efficient interface for managing
8793f31533SJeff Robersondynamically-sized collections of items of identical size.
880aa028ffSDag-Erling SmørgravThe zone allocator can work with preallocated zones as well as with
890aa028ffSDag-Erling Smørgravruntime-allocated ones, and is therefore available much earlier in the
9093f31533SJeff Robersonboot process than other memory management routines.  The zone allocator
9193f31533SJeff Robersonprovides per-cpu allocation caches with linear scalability on SMP
9293f31533SJeff Robersonsystems as well as round-robin and first-touch policies for NUMA
9393f31533SJeff Robersonsystems.
940aa028ffSDag-Erling Smørgrav.Pp
950aa028ffSDag-Erling SmørgravA zone is an extensible collection of items of identical size.
960aa028ffSDag-Erling SmørgravThe zone allocator keeps track of which items are in use and which
97008080bdSJeroen Ruigrok van der Wervenare not, and provides functions for allocating items from the zone and
980aa028ffSDag-Erling Smørgravfor releasing them back (which makes them available for later use).
990aa028ffSDag-Erling Smørgrav.Pp
100ced699e3SRuslan ErmilovAfter the first allocation of an item,
10190d83886SJulian Elischerit will have been cleared to zeroes, however subsequent allocations
1027251f557SKonstantin Belousovwill retain the contents as of the last free.
10390d83886SJulian Elischer.Pp
104382682b2SJeroen Ruigrok van der WervenThe
105382682b2SJeroen Ruigrok van der Werven.Fn uma_zcreate
106382682b2SJeroen Ruigrok van der Wervenfunction creates a new zone from which items may then be allocated from.
107382682b2SJeroen Ruigrok van der WervenThe
108382682b2SJeroen Ruigrok van der Werven.Fa name
109382682b2SJeroen Ruigrok van der Wervenargument is a text name of the zone for debugging and stats; this memory
110382682b2SJeroen Ruigrok van der Wervenshould not be freed until the zone has been deallocated.
111382682b2SJeroen Ruigrok van der Werven.Pp
1124919e8cbSAlfred PerlsteinThe
1134919e8cbSAlfred Perlstein.Fa ctor
1144919e8cbSAlfred Perlsteinand
1154919e8cbSAlfred Perlstein.Fa dtor
1164919e8cbSAlfred Perlsteinarguments are callback functions that are called by
1174919e8cbSAlfred Perlsteinthe uma subsystem at the time of the call to
1184919e8cbSAlfred Perlstein.Fn uma_zalloc
1194919e8cbSAlfred Perlsteinand
1204919e8cbSAlfred Perlstein.Fn uma_zfree
121d962d52aSRuslan Ermilovrespectively.
122d962d52aSRuslan ErmilovTheir purpose is to provide hooks for initializing or
1234919e8cbSAlfred Perlsteindestroying things that need to be done at the time of the allocation
124d962d52aSRuslan Ermilovor release of a resource.
125e07f1d5fSHiten PandyaA good usage for the
1264919e8cbSAlfred Perlstein.Fa ctor
1274919e8cbSAlfred Perlsteinand
1284919e8cbSAlfred Perlstein.Fa dtor
1294919e8cbSAlfred Perlsteincallbacks
1304919e8cbSAlfred Perlsteinmight be to adjust a global count of the number of objects allocated.
1314919e8cbSAlfred Perlstein.Pp
1324919e8cbSAlfred PerlsteinThe
1334919e8cbSAlfred Perlstein.Fa uminit
1344919e8cbSAlfred Perlsteinand
1354919e8cbSAlfred Perlstein.Fa fini
1364919e8cbSAlfred Perlsteinarguments are used to optimize the allocation of
137d962d52aSRuslan Ermilovobjects from the zone.
138d962d52aSRuslan ErmilovThey are called by the uma subsystem whenever
1394919e8cbSAlfred Perlsteinit needs to allocate or free several items to satisfy requests or memory
140d962d52aSRuslan Ermilovpressure.
141d962d52aSRuslan ErmilovA good use for the
142d962d52aSRuslan Ermilov.Fa uminit
143d962d52aSRuslan Ermilovand
144d962d52aSRuslan Ermilov.Fa fini
145d962d52aSRuslan Ermilovcallbacks might be to
146d962d52aSRuslan Ermilovinitialize and destroy mutexes contained within the object.
147d962d52aSRuslan ErmilovThis would
1484919e8cbSAlfred Perlsteinallow one to re-use already initialized mutexes when an object is returned
149d962d52aSRuslan Ermilovfrom the uma subsystem's object cache.
150d962d52aSRuslan ErmilovThey are not called on each call to
1514919e8cbSAlfred Perlstein.Fn uma_zalloc
1524919e8cbSAlfred Perlsteinand
1534919e8cbSAlfred Perlstein.Fn uma_zfree
1544919e8cbSAlfred Perlsteinbut rather in a batch mode on several objects.
1554919e8cbSAlfred Perlstein.Pp
156b7e2b86cSGleb SmirnoffThe
157b7e2b86cSGleb Smirnoff.Fa flags
158b7e2b86cSGleb Smirnoffargument of the
159b7e2b86cSGleb Smirnoff.Fn uma_zcreate
160b7e2b86cSGleb Smirnoffis a subset of the following flags:
161b7e2b86cSGleb Smirnoff.Bl -tag -width "foo"
162b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_NOFREE
163b7e2b86cSGleb SmirnoffSlabs of the zone are never returned back to VM.
164b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_NODUMP
165b7e2b86cSGleb SmirnoffPages belonging to the zone will not be included into mini-dumps.
166ad97af7eSGleb Smirnoff.It Dv UMA_ZONE_PCPU
167ad97af7eSGleb SmirnoffAn allocation from zone would have
168ad97af7eSGleb Smirnoff.Va mp_ncpu
169ad97af7eSGleb Smirnoffshadow copies, that are privately assigned to CPUs.
170ad97af7eSGleb SmirnoffA CPU can address its private copy using base allocation address plus
171ad97af7eSGleb Smirnoffmultiple of current CPU id and
172ad97af7eSGleb Smirnoff.Fn sizeof "struct pcpu" :
173ad97af7eSGleb Smirnoff.Bd -literal -offset indent
174ad97af7eSGleb Smirnofffoo_zone = uma_zcreate(..., UMA_ZONE_PCPU);
175ad97af7eSGleb Smirnoff ...
176ad97af7eSGleb Smirnofffoo_base = uma_zalloc(foo_zone, ...);
177ad97af7eSGleb Smirnoff ...
178ad97af7eSGleb Smirnoffcritical_enter();
179ad97af7eSGleb Smirnofffoo_pcpu = (foo_t *)zpcpu_get(foo_base);
180ad97af7eSGleb Smirnoff/* do something with foo_pcpu */
181ad97af7eSGleb Smirnoffcritical_exit();
182ad97af7eSGleb Smirnoff.Ed
183b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_OFFPAGE
184b7e2b86cSGleb SmirnoffBy default book-keeping of items within a slab is done in the slab page itself.
185b7e2b86cSGleb SmirnoffThis flag explicitly tells subsystem that book-keeping structure should be
186b7e2b86cSGleb Smirnoffallocated separately from special internal zone.
187b7e2b86cSGleb SmirnoffThis flag requires either
188b7e2b86cSGleb Smirnoff.Dv UMA_ZONE_VTOSLAB
189b7e2b86cSGleb Smirnoffor
190b7e2b86cSGleb Smirnoff.Dv UMA_ZONE_HASH ,
191b7e2b86cSGleb Smirnoffsince subsystem requires a mechanism to find a book-keeping structure
1927c64ddd5SWarren Blockto an item being freed.
193b7e2b86cSGleb SmirnoffThe subsystem may choose to prefer offpage book-keeping for certain zones
194b7e2b86cSGleb Smirnoffimplicitly.
195b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_ZINIT
196b7e2b86cSGleb SmirnoffThe zone will have its
197b7e2b86cSGleb Smirnoff.Ft uma_init
198b7e2b86cSGleb Smirnoffmethod set to internal method that initializes a new allocated slab
199b7e2b86cSGleb Smirnoffto all zeros.
200b1edef17SJoel DahlDo not mistake
201b7e2b86cSGleb Smirnoff.Ft uma_init
202b7e2b86cSGleb Smirnoffmethod with
203b7e2b86cSGleb Smirnoff.Ft uma_ctor .
204b7e2b86cSGleb SmirnoffA zone with
205b7e2b86cSGleb Smirnoff.Dv UMA_ZONE_ZINIT
206b7e2b86cSGleb Smirnoffflag would not return zeroed memory on every
207b7e2b86cSGleb Smirnoff.Fn uma_zalloc .
208b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_HASH
209b7e2b86cSGleb SmirnoffThe zone should use an internal hash table to find slab book-keeping
210b7e2b86cSGleb Smirnoffstructure where an allocation being freed belongs to.
211b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_VTOSLAB
212b7e2b86cSGleb SmirnoffThe zone should use special field of
213b7e2b86cSGleb Smirnoff.Vt vm_page_t
214b7e2b86cSGleb Smirnoffto find slab book-keeping structure where an allocation being freed belongs to.
215b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_MALLOC
216b7e2b86cSGleb SmirnoffThe zone is for the
217b7e2b86cSGleb Smirnoff.Xr malloc 9
218b7e2b86cSGleb Smirnoffsubsystem.
219b7e2b86cSGleb Smirnoff.It Dv UMA_ZONE_VM
220b7e2b86cSGleb SmirnoffThe zone is for the VM subsystem.
22193f31533SJeff Roberson.It Dv UMA_ZONE_NUMA
22293f31533SJeff RobersonThe zone should use a first-touch NUMA policy rather than the round-robin
22393f31533SJeff Robersondefault. Callers that do not free memory on the same domain it is allocated
22493f31533SJeff Robersonfrom will cause mixing in per-cpu caches.  See
22593f31533SJeff Roberson.Xr numa 9 for more details.
226b7e2b86cSGleb Smirnoff.El
227b7e2b86cSGleb Smirnoff.Pp
2280aa028ffSDag-Erling SmørgravTo allocate an item from a zone, simply call
2297c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
2301437c79aSJeroen Ruigrok van der Wervenwith a pointer to that zone
2311437c79aSJeroen Ruigrok van der Wervenand set the
232acff84fbSJeroen Ruigrok van der Werven.Fa flags
233acff84fbSJeroen Ruigrok van der Wervenargument to selected flags as documented in
234acff84fbSJeroen Ruigrok van der Werven.Xr malloc 9 .
2351437c79aSJeroen Ruigrok van der WervenIt will return a pointer to an item if successful,
2361437c79aSJeroen Ruigrok van der Wervenor
2370aa028ffSDag-Erling Smørgrav.Dv NULL
2380aa028ffSDag-Erling Smørgravin the rare case where all items in the zone are in use and the
2391437c79aSJeroen Ruigrok van der Wervenallocator is unable to grow the zone
2402864c799SEdward Tomasz Napieralaand
2411437c79aSJeroen Ruigrok van der Werven.Dv M_NOWAIT
2421437c79aSJeroen Ruigrok van der Wervenis specified.
2430aa028ffSDag-Erling Smørgrav.Pp
2440aa028ffSDag-Erling SmørgravItems are released back to the zone from which they were allocated by
2450aa028ffSDag-Erling Smørgravcalling
2467c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
2470aa028ffSDag-Erling Smørgravwith a pointer to the zone and a pointer to the item.
24820ed0cb0SMatthew D FlemingIf
24920ed0cb0SMatthew D Fleming.Fa item
25020ed0cb0SMatthew D Flemingis
25120ed0cb0SMatthew D Fleming.Dv NULL ,
25220ed0cb0SMatthew D Flemingthen
25320ed0cb0SMatthew D Fleming.Fn uma_zfree
25420ed0cb0SMatthew D Flemingdoes nothing.
2555ca0c84eSThomas Moestl.Pp
2566a4c41d1SRemko LodderThe variations
2576a4c41d1SRemko Lodder.Fn uma_zalloc_arg
2586a4c41d1SRemko Lodderand
2596a4c41d1SRemko Lodder.Fn uma_zfree_arg
26093f31533SJeff Robersonallow callers to
2616a4c41d1SRemko Lodderspecify an argument for the
2626a4c41d1SRemko Lodder.Dv ctor
2636a4c41d1SRemko Lodderand
2646a4c41d1SRemko Lodder.Dv dtor
2656a4c41d1SRemko Lodderfunctions, respectively.
26693f31533SJeff RobersonThe
26793f31533SJeff Roberson.Fn uma_zalloc_domain
26893f31533SJeff Robersonfunction allows callers to specify a fixed
26993f31533SJeff Roberson.Xr numa 9 domain to allocate from.  This uses a guaranteed but slow path in
27093f31533SJeff Robersonthe allocator which reduces concurrency.  The
27193f31533SJeff Roberson.Fn uma_zfree_domain
27293f31533SJeff Robersonfunction should be used to return memory allocated in this fashion.  This
27393f31533SJeff Robersonfunction infers the domain from the pointer and does not require it as an
27493f31533SJeff Robersonargument.
2756a4c41d1SRemko Lodder.Pp
27655407559SJeroen Ruigrok van der WervenCreated zones,
27755407559SJeroen Ruigrok van der Wervenwhich are empty,
2785ca0c84eSThomas Moestlcan be destroyed using
2797c32182eSJeroen Ruigrok van der Werven.Fn uma_zdestroy ,
2805ca0c84eSThomas Moestlfreeing all memory that was allocated for the zone.
2815ca0c84eSThomas MoestlAll items allocated from the zone with
2827c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
2835ca0c84eSThomas Moestlmust have been freed with
2847c32182eSJeroen Ruigrok van der Werven.Fn uma_zfree
2855ca0c84eSThomas Moestlbefore.
286d7bbb21aSHartmut Brandt.Pp
287c4ae7908SLawrence StewartThe
288d7bbb21aSHartmut Brandt.Fn uma_zone_set_max
289c4ae7908SLawrence Stewartfunction limits the number of items
290c4ae7908SLawrence Stewart.Pq and therefore memory
291c4ae7908SLawrence Stewartthat can be allocated to
292c4ae7908SLawrence Stewart.Fa zone .
293d7bbb21aSHartmut BrandtThe
294d7bbb21aSHartmut Brandt.Fa nitems
295c4ae7908SLawrence Stewartargument specifies the requested upper limit number of items.
2961c6cae97SLawrence StewartThe effective limit is returned to the caller, as it may end up being higher
2971c6cae97SLawrence Stewartthan requested due to the implementation rounding up to ensure all memory pages
2981c6cae97SLawrence Stewartallocated to the zone are utilised to capacity.
299c4ae7908SLawrence StewartThe limit applies to the total number of items in the zone, which includes
300d7bbb21aSHartmut Brandtallocated items, free items and free items in the per-cpu caches.
301d7bbb21aSHartmut BrandtOn systems with more than one CPU it may not be possible to allocate
302d7bbb21aSHartmut Brandtthe specified number of items even when there is no shortage of memory,
303d7bbb21aSHartmut Brandtbecause all of the remaining free items may be in the caches of the
304d7bbb21aSHartmut Brandtother CPUs when the limit is hit.
305c4ae7908SLawrence Stewart.Pp
306c4ae7908SLawrence StewartThe
307c4ae7908SLawrence Stewart.Fn uma_zone_get_max
308c4ae7908SLawrence Stewartfunction returns the effective upper limit number of items for a zone.
309c4ae7908SLawrence Stewart.Pp
310c4ae7908SLawrence StewartThe
311c4ae7908SLawrence Stewart.Fn uma_zone_get_cur
312c4ae7908SLawrence Stewartfunction returns the approximate current occupancy of the zone.
313c4ae7908SLawrence StewartThe returned value is approximate because appropriate synchronisation to
3143102cfe2SGlen Barberdetermine an exact value is not performed by the implementation.
315c4ae7908SLawrence StewartThis ensures low overhead at the expense of potentially stale data being used
316c4ae7908SLawrence Stewartin the calculation.
3172f891cd5SPawel Jakub Dawidek.Pp
3182f891cd5SPawel Jakub DawidekThe
3192f891cd5SPawel Jakub Dawidek.Fn uma_zone_set_warning
3202f891cd5SPawel Jakub Dawidekfunction sets a warning that will be printed on the system console when the
3212f891cd5SPawel Jakub Dawidekgiven zone becomes full and fails to allocate an item.
32254503a13SJonathan T. LooneyThe warning will be printed no more often than every five minutes.
3232f891cd5SPawel Jakub DawidekWarnings can be turned off globally by setting the
3242f891cd5SPawel Jakub Dawidek.Va vm.zone_warnings
3252f891cd5SPawel Jakub Dawideksysctl tunable to
3262f891cd5SPawel Jakub Dawidek.Va 0 .
3270a5a3ccbSGleb Smirnoff.Pp
3280a5a3ccbSGleb SmirnoffThe
32954503a13SJonathan T. Looney.Fn uma_zone_set_maxaction
33054503a13SJonathan T. Looneyfunction sets a function that will be called when the given zone becomes full
33154503a13SJonathan T. Looneyand fails to allocate an item.
3327851d429SEdward Tomasz NapieralaThe function will be called with the zone locked.
3337851d429SEdward Tomasz NapieralaAlso, the function
3347851d429SEdward Tomasz Napieralathat called the allocation function may have held additional locks.
3357851d429SEdward Tomasz NapieralaTherefore,
33654503a13SJonathan T. Looneythis function should do very little work (similar to a signal handler).
33754503a13SJonathan T. Looney.Pp
33854503a13SJonathan T. LooneyThe
3390a5a3ccbSGleb Smirnoff.Fn SYSCTL_UMA_MAX parent nbr name access zone descr
3400a5a3ccbSGleb Smirnoffmacro declares a static
3410a5a3ccbSGleb Smirnoff.Xr sysctl
3420a5a3ccbSGleb Smirnoffoid that exports the effective upper limit number of items for a zone.
3430a5a3ccbSGleb SmirnoffThe
3440a5a3ccbSGleb Smirnoff.Fa zone
3450a5a3ccbSGleb Smirnoffargument should be a pointer to
3460a5a3ccbSGleb Smirnoff.Vt uma_zone_t .
3470a5a3ccbSGleb SmirnoffA read of the oid returns value obtained through
3480a5a3ccbSGleb Smirnoff.Fn uma_zone_get_max .
3490a5a3ccbSGleb SmirnoffA write to the oid sets new value via
3500a5a3ccbSGleb Smirnoff.Fn uma_zone_set_max .
3510a5a3ccbSGleb SmirnoffThe
3520a5a3ccbSGleb Smirnoff.Fn SYSCTL_ADD_UMA_MAX ctx parent nbr name access zone descr
3530a5a3ccbSGleb Smirnoffmacro is provided to create this type of oid dynamically.
3540a5a3ccbSGleb Smirnoff.Pp
3550a5a3ccbSGleb SmirnoffThe
3560a5a3ccbSGleb Smirnoff.Fn SYSCTL_UMA_CUR parent nbr name access zone descr
35762cb31dcSWarner Loshmacro declares a static read-only
3580a5a3ccbSGleb Smirnoff.Xr sysctl
3590a5a3ccbSGleb Smirnoffoid that exports the approximate current occupancy of the zone.
3600a5a3ccbSGleb SmirnoffThe
3610a5a3ccbSGleb Smirnoff.Fa zone
3620a5a3ccbSGleb Smirnoffargument should be a pointer to
3630a5a3ccbSGleb Smirnoff.Vt uma_zone_t .
3640a5a3ccbSGleb SmirnoffA read of the oid returns value obtained through
3650a5a3ccbSGleb Smirnoff.Fn uma_zone_get_cur .
3660a5a3ccbSGleb SmirnoffThe
3670a5a3ccbSGleb Smirnoff.Fn SYSCTL_ADD_UMA_CUR ctx parent nbr name zone descr
3680a5a3ccbSGleb Smirnoffmacro is provided to create this type of oid dynamically.
3690aa028ffSDag-Erling Smørgrav.Sh RETURN VALUES
3700aa028ffSDag-Erling SmørgravThe
3717c32182eSJeroen Ruigrok van der Werven.Fn uma_zalloc
3720aa028ffSDag-Erling Smørgravfunction returns a pointer to an item, or
3730aa028ffSDag-Erling Smørgrav.Dv NULL
3742864c799SEdward Tomasz Napieralaif the zone ran out of unused items
3752864c799SEdward Tomasz Napieralaand
3762864c799SEdward Tomasz Napierala.Dv M_NOWAIT
3772864c799SEdward Tomasz Napieralawas specified.
378*0766f278SJonathan T. Looney.Sh IMPLEMENTATION NOTES
379*0766f278SJonathan T. LooneyThe memory that these allocation calls return is not executable.
380*0766f278SJonathan T. LooneyThe
381*0766f278SJonathan T. Looney.Fn uma_zalloc
382*0766f278SJonathan T. Looneyfunction does not support the
383*0766f278SJonathan T. Looney.Dv M_EXEC
384*0766f278SJonathan T. Looneyflag to allocate executable memory.
385*0766f278SJonathan T. LooneyNot all platforms enforce a distinction between executable and
386*0766f278SJonathan T. Looneynon-executable memory.
3870aa028ffSDag-Erling Smørgrav.Sh SEE ALSO
3880aa028ffSDag-Erling Smørgrav.Xr malloc 9
3890aa028ffSDag-Erling Smørgrav.Sh HISTORY
3900aa028ffSDag-Erling SmørgravThe zone allocator first appeared in
3910aa028ffSDag-Erling Smørgrav.Fx 3.0 .
3929a795583SJeroen Ruigrok van der WervenIt was radically changed in
3939a795583SJeroen Ruigrok van der Werven.Fx 5.0
3949a795583SJeroen Ruigrok van der Wervento function as a slab allocator.
3950aa028ffSDag-Erling Smørgrav.Sh AUTHORS
3960aa028ffSDag-Erling Smørgrav.An -nosplit
3970aa028ffSDag-Erling SmørgravThe zone allocator was written by
3980aa028ffSDag-Erling Smørgrav.An John S. Dyson .
3999a795583SJeroen Ruigrok van der WervenThe zone allocator was rewritten in large parts by
4008a7314fcSBaptiste Daroussin.An Jeff Roberson Aq Mt jeff@FreeBSD.org
4019a795583SJeroen Ruigrok van der Wervento function as a slab allocator.
4020aa028ffSDag-Erling Smørgrav.Pp
4030aa028ffSDag-Erling SmørgravThis manual page was written by
4048a7314fcSBaptiste Daroussin.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
4059a795583SJeroen Ruigrok van der WervenChanges for UMA by
4068a7314fcSBaptiste Daroussin.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org .
407