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
26 .\" $FreeBSD: src/share/man/man9/zone.9,v 1.9.2.4 2002/05/02 20:01:29 asmodai Exp $
45 .Fn zbootinit "vm_zone_t z" "char *name" "int size" "void *item" "int nitems"
47 .Fn zinitna "vm_zone_t z" "struct vm_object *obj" "char *name" "int size" "int nentries" "int flags" "int zalloc"
49 .Fn zinit "char *name" "int size" "int nentries" "int flags" "int zalloc"
51 .Fn zalloc "vm_zone_t z"
53 .Fn zfree "vm_zone_t z" "void *item"
55 .Fn zalloci "vm_zone_t z"
57 .Fn zfreei "vm_zone_t z" "void *item"
59 The zone allocator provides an efficient interface for managing
60 dynamically-sized collections of items of similar size.
61 The zone allocator can work with preallocated zones as well as with
62 runtime-allocated ones, and is therefore available much earlier in the
63 boot process than other memory management routines.
65 A zone is an extensible collection of items of identical size.
66 The zone allocator keeps track of which items are in use and which
67 are not, and provides functions for allocating items from the zone and
68 for releasing them back (which makes them available for later use).
70 The zone allocator stores state information inside the items proper
71 while they are not allocated,
72 so structures that will be managed by the zone allocator
73 and wish to use the type stable property of zones by leaving some fields
74 pre-filled between allocations, must reserve
75 two pointers at the very beginning for internal use by the zone
76 allocator, as follows:
79 struct my_item *z_rsvd1;
80 struct my_item *z_rsvd2;
81 /* rest of structure */
85 Alternatively they should assume those entries corrupted
86 after each allocation.
87 After the first allocation of an item,
88 it will have been cleared to zeroes, however subsequent allocations
89 will retain the contents as of the last free, with the exception of the
90 fields mentioned above.
92 Zones are created in one of two fashions, depending how far along the
95 If the VM system is fully initialized, a dynamically allocated zone can
100 argument should be a pointer to a short, descriptive name for the
101 zone; it is used for statistics and debugging purposes.
106 are the size of the items held by the zone and the initial size (in
107 items) of the zone, respectively.
110 argument should be set to
112 if there is a chance that items may be allocated from the zone in
113 interrupt context; note that in this case, the zone will never grow
122 indicates the number of VM pages by which the zone should grow every
125 If the VM system is not yet fully initialized, the zone allocator
126 cannot dynamically allocate VM pages from which to dole out items, so
127 the caller needs to provide a static pool of items.
128 In this case, the initialization is done in two stages: first,
130 is called before first use of the zone; later, when the VM system is
131 up, the initialization of the zone is completed by calling
134 The first argument to
136 is a pointer to a static
139 The second and third are the name of the zone and the size of the
141 The fourth argument is a pointer to a static array of items from which
142 the zone allocator will draw until the zone is fully initialized.
145 argument is the number of items in the array.
151 with the addition of a pointer to the zone to initialize, and a
153 .Vt "struct vm_object"
154 from which to allocate pages in the
158 To allocate an item from a zone, simply call
160 with a pointer to that zone; it will return a pointer to an item, or
162 in the rare case where all items in the zone are in use and the
163 allocator is unable to grow the zone.
166 is not interrupt safe.
167 For an interrupt safe allocation use
169 which has the same semantics as
172 Items are released back to the zone from which they were allocated by
175 with a pointer to the zone and a pointer to the item.
176 Use the corresponding
178 function if the allocation was done using
183 function returns 1 on success and 0 on failure; the only failure case
184 is inability to preallocate address space for an interrupt-safe zone.
188 function returns a pointer to a fully initialized
189 .Vt "struct vm_zone" ,
198 flag was specified and
200 failed to preallocate address space.
204 function returns a pointer to an item, or
206 if the zone ran out of unused items and the allocator was unable to
211 The zone allocator first appeared in
215 The zone allocator was written by
218 This manual page was written by
219 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .