start adding .Mt to email addresses in man pages
[dragonfly.git] / share / man / man9 / zone.9
1 .\"-
2 .\" Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
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.
13 .\"
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
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD: src/share/man/man9/zone.9,v 1.9.2.4 2002/05/02 20:01:29 asmodai Exp $
27 .\"
28 .Dd January 27, 2001
29 .Dt ZONE 9
30 .Os
31 .Sh NAME
32 .Nm zbootinit ,
33 .Nm zinitna ,
34 .Nm zinit ,
35 .Nm zdestroy ,
36 .Nm zalloc ,
37 .Nm zfree ,
38 .Nd zone allocator
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/queue.h
42 .In vm/vm_zone.h
43 .Ft void
44 .Fn zbootinit "vm_zone_t z" "char *name" "int size" "void *item" "int nitems"
45 .Ft int
46 .Fn zinitna "vm_zone_t z" "struct vm_object *obj" "char *name" "int size" "int nentries" "int flags" "int zalloc"
47 .Ft vm_zone_t
48 .Fn zinit "char *name" "int size" "int nentries" "int flags" "int zalloc"
49 .Ft void
50 .Fn zdestroy "vm_zone_t z"
51 .Ft void *
52 .Fn zalloc "vm_zone_t z"
53 .Ft void
54 .Fn zfree "vm_zone_t z" "void *item"
55 .Sh DESCRIPTION
56 The zone allocator is deprecated.
57 Use
58 .In sys/objcache.h
59 for new developments.
60 .Pp
61 The zone allocator provides an efficient interface for managing
62 dynamically-sized collections of items of similar size.
63 The zone allocator can work with preallocated zones as well as with
64 runtime-allocated ones, and is therefore available much earlier in the
65 boot process than other memory management routines.
66 .Pp
67 A zone is an extensible collection of items of identical size.
68 The zone allocator keeps track of which items are in use and which
69 are not, and provides functions for allocating items from the zone and
70 for releasing them back (which makes them available for later use).
71 .Pp
72 The zone allocator stores state information inside the items proper
73 while they are not allocated,
74 so structures that will be managed by the zone allocator
75 and wish to use the type stable property of zones by leaving some fields
76 pre-filled between allocations, must reserve
77 two pointers at the very beginning for internal use by the zone
78 allocator, as follows:
79 .Bd -literal
80 struct my_item {
81         struct my_item  *z_rsvd1;
82         struct my_item  *z_rsvd2;
83         /* rest of structure */
84 };
85 .Ed
86 .Pp
87 Alternatively they should assume those entries corrupted
88 after each allocation.
89 After the first allocation of an item,
90 it will have been cleared to zeroes, however subsequent allocations
91 will retain the contents as of the last free, with the exception of the
92 fields mentioned above.
93 .Pp
94 Zones are created in one of two fashions, depending how far along the
95 boot process is.
96 .Pp
97 If the VM system is fully initialized, a dynamically allocated zone can
98 be created using
99 .Fn zinit .
100 The
101 .Fa name
102 argument should be a pointer to a short, descriptive name for the
103 zone; it is used for statistics and debugging purposes.
104 The
105 .Fa size
106 and
107 .Fa nentries
108 are the size of the items held by the zone and the initial size (in
109 items) of the zone, respectively.
110 The
111 .Fa flags
112 argument should have the
113 .Dv ZONE_INTERRUPT
114 bit set if there is a chance that items may be allocated from the zone in
115 interrupt context; note that in this case, the zone will never grow
116 larger than
117 .Fa nentries
118 items.
119 The
120 .Fa flags
121 argument should have the
122 .Dv ZONE_DESTROYABLE
123 bit set if the zone is to be destroyed with
124 .Fn zdestroy .
125 The final argument,
126 .Fa zalloc ,
127 indicates the number of VM pages by which the zone should grow every
128 time it fills up.
129 .Pp
130 If the VM system is not yet fully initialized, the zone allocator
131 cannot dynamically allocate VM pages from which to dole out items, so
132 the caller needs to provide a static pool of items.
133 In this case, the initialization is done in two stages: first,
134 .Fn zbootinit
135 is called before first use of the zone; later, when the VM system is
136 up, the initialization of the zone is completed by calling
137 .Fn zinitna .
138 .Pp
139 The first argument to
140 .Fn zbootinit
141 is a pointer to a static
142 .Vt "struct vm_zone"
143 to initialize.
144 The second and third are the name of the zone and the size of the
145 items it will hold.
146 The fourth argument is a pointer to a static array of items from which
147 the zone allocator will draw until the zone is fully initialized.
148 The
149 .Fa nitems
150 argument is the number of items in the array.
151 .Pp
152 The arguments to
153 .Fa zinitna
154 are the same as for
155 .Fa zinit ,
156 with the addition of a pointer to the zone to initialize, and a
157 pointer to a
158 .Vt "struct vm_object"
159 from which to allocate pages in the
160 .Dv ZONE_INTERRUPT
161 case.
162 .Pp
163 To release all the memory allocated for a zone, call
164 .Fn zdestroy .
165 Only zones created with
166 .Fn zinit
167 and with the
168 .Dv ZONE_DESTROYABLE
169 flag can be destroyed.
170 .Pp
171 To allocate an item from a zone, simply call
172 .Fn zalloc
173 with a pointer to that zone; it will return a pointer to an item, or
174 .Dv NULL
175 in the rare case where all items in the zone are in use and the
176 allocator is unable to grow the zone.
177 .Pp
178 Items are released back to the zone from which they were allocated by
179 calling
180 .Fn zfree
181 with a pointer to the zone and a pointer to the item.
182 .Pp
183 The zone functions are not SMP-safe.
184 The MP lock must be held while calling them.
185 .Sh RETURN VALUES
186 The
187 .Fn zinitna
188 function returns 1 on success and 0 on failure; the only failure case
189 is inability to preallocate address space for an interrupt-safe zone.
190 .Pp
191 The
192 .Fn zinit
193 function returns a pointer to a fully initialized
194 .Vt "struct vm_zone" ,
195 or
196 .Dv NULL
197 if it was unable to
198 .Fn kmalloc
199 a
200 .Vt "struct vm_zone"
201 or the
202 .Dv ZONE_INTERRUPT
203 flag was specified and
204 .Fn zinitna
205 failed to preallocate address space.
206 .Pp
207 The
208 .Fn zalloc
209 function returns a pointer to an item, or
210 .Dv NULL
211 if the zone ran out of unused items and the allocator was unable to
212 enlarge it.
213 .Sh SEE ALSO
214 .Xr memory 9
215 .Sh HISTORY
216 The zone allocator first appeared in
217 .Fx 3.0 .
218 .Sh AUTHORS
219 .An -nosplit
220 The zone allocator was written by
221 .An John S. Dyson .
222 .Pp
223 This manual page was written by
224 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq Mt des@FreeBSD.org .