2 .\" Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 .Nm uma_zone_set_warning
49 .Fa "char *name" "int size"
50 .Fa "uma_ctor ctor" "uma_dtor dtor" "uma_init uminit" "uma_fini fini"
51 .Fa "int align" "uint16_t flags"
54 .Fn uma_zalloc "uma_zone_t zone" "int flags"
56 .Fn uma_zalloc_arg "uma_zone_t zone" "void *arg" "int flags"
58 .Fn uma_zfree "uma_zone_t zone" "void *item"
60 .Fn uma_zfree_arg "uma_zone_t zone" "void *item" "void *arg"
62 .Fn uma_zdestroy "uma_zone_t zone"
64 .Fn uma_zone_set_max "uma_zone_t zone" "int nitems"
66 .Fn uma_zone_get_max "uma_zone_t zone"
68 .Fn uma_zone_get_cur "uma_zone_t zone"
70 .Fn uma_zone_set_warning "uma_zone_t zone" "const char *warning"
72 The zone allocator provides an efficient interface for managing
73 dynamically-sized collections of items of similar size.
74 The zone allocator can work with preallocated zones as well as with
75 runtime-allocated ones, and is therefore available much earlier in the
76 boot process than other memory management routines.
78 A zone is an extensible collection of items of identical size.
79 The zone allocator keeps track of which items are in use and which
80 are not, and provides functions for allocating items from the zone and
81 for releasing them back (which makes them available for later use).
83 After the first allocation of an item,
84 it will have been cleared to zeroes, however subsequent allocations
85 will retain the contents as of the last free.
89 function creates a new zone from which items may then be allocated from.
92 argument is a text name of the zone for debugging and stats; this memory
93 should not be freed until the zone has been deallocated.
99 arguments are callback functions that are called by
100 the uma subsystem at the time of the call to
105 Their purpose is to provide hooks for initializing or
106 destroying things that need to be done at the time of the allocation
107 or release of a resource.
113 might be to adjust a global count of the number of objects allocated.
119 arguments are used to optimize the allocation of
120 objects from the zone.
121 They are called by the uma subsystem whenever
122 it needs to allocate or free several items to satisfy requests or memory
128 callbacks might be to
129 initialize and destroy mutexes contained within the object.
131 allow one to re-use already initialized mutexes when an object is returned
132 from the uma subsystem's object cache.
133 They are not called on each call to
137 but rather in a batch mode on several objects.
139 To allocate an item from a zone, simply call
141 with a pointer to that zone
144 argument to selected flags as documented in
146 It will return a pointer to an item if successful,
149 in the rare case where all items in the zone are in use and the
150 allocator is unable to grow the zone
155 Items are released back to the zone from which they were allocated by
158 with a pointer to the zone and a pointer to the item.
172 specify an argument for the
176 functions, respectively.
180 can be destroyed using
182 freeing all memory that was allocated for the zone.
183 All items allocated from the zone with
185 must have been freed with
191 function limits the number of items
192 .Pq and therefore memory
193 that can be allocated to
197 argument specifies the requested upper limit number of items.
198 The effective limit is returned to the caller, as it may end up being higher
199 than requested due to the implementation rounding up to ensure all memory pages
200 allocated to the zone are utilised to capacity.
201 The limit applies to the total number of items in the zone, which includes
202 allocated items, free items and free items in the per-cpu caches.
203 On systems with more than one CPU it may not be possible to allocate
204 the specified number of items even when there is no shortage of memory,
205 because all of the remaining free items may be in the caches of the
206 other CPUs when the limit is hit.
210 function returns the effective upper limit number of items for a zone.
214 function returns the approximate current occupancy of the zone.
215 The returned value is approximate because appropriate synchronisation to
216 determine an exact value is not performed by the implementation.
217 This ensures low overhead at the expense of potentially stale data being used
221 .Fn uma_zone_set_warning
222 function sets a warning that will be printed on the system console when the
223 given zone becomes full and fails to allocate an item.
224 The warning will be printed not often than every five minutes.
225 Warnings can be turned off globally by setting the
232 function returns a pointer to an item, or
234 if the zone ran out of unused items
241 The zone allocator first appeared in
243 It was radically changed in
245 to function as a slab allocator.
248 The zone allocator was written by
250 The zone allocator was rewritten in large parts by
251 .An Jeff Roberson Aq jeff@FreeBSD.org
252 to function as a slab allocator.
254 This manual page was written by
255 .An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
257 .An Jeroen Ruigrok van der Werven Aq asmodai@FreeBSD.org .