]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man9/vmem.9
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / man / man9 / vmem.9
1 .\"     $NetBSD: vmem.9,v 1.15 2013/01/29 22:02:17 wiz Exp $
2 .\"
3 .\" Copyright (c)2006 YAMAMOTO Takashi,
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .\" ------------------------------------------------------------
30 .Dd July 12, 2013
31 .Dt VMEM 9
32 .Os
33 .\" ------------------------------------------------------------
34 .Sh NAME
35 .Nm vmem
36 .Nd general purpose resource allocator
37 .\" ------------------------------------------------------------
38 .Sh SYNOPSIS
39 .In sys/vmem.h
40 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 .Ft vmem_t *
42 .Fn vmem_create \
43 "const char *name" "vmem_addr_t base" "vmem_size_t size" "vmem_size_t quantum" \
44 "vmem_size_t qcache_max" "int flags"
45 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 .Ft int
47 .Fn vmem_add \
48 "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size" "int flags"
49 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 .Ft int
51 .Fn vmem_xalloc \
52 "vmem_t *vm" "const vmem_size_t size" "vmem_size_t align" \
53 "const vmem_size_t phase" "const vmem_size_t nocross" \
54 "const vmem_addr_t minaddr" "const vmem_addr_t maxaddr" "int flags" \
55 "vmem_addr_t *addrp"
56 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 .Ft void
58 .Fn vmem_xfree "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
59 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 .Ft int
61 .Fn vmem_alloc "vmem_t *vm" "vmem_size_t size" "int flags" "vmem_addr_t *addrp"
62 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 .Ft void
64 .Fn vmem_free "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
65 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 .Ft void
67 .Fn vmem_destroy "vmem_t *vm"
68 .\" ------------------------------------------------------------
69 .Sh DESCRIPTION
70 The
71 .Nm
72 is a general purpose resource allocator.
73 Despite its name, it can be used for arbitrary resources
74 other than virtual memory.
75 .Pp
76 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 .Fn vmem_create
78 creates a new vmem arena.
79 .Bl -tag -width qcache_max
80 .It Fa name
81 The string to describe the vmem.
82 .It Fa base
83 The start address of the initial span.
84 Pass
85 .Dv 0
86 if no initial span is required.
87 .It Fa size
88 The size of the initial span.
89 Pass
90 .Dv 0
91 if no initial span is required.
92 .It Fa quantum
93 The smallest unit of allocation.
94 .It Fa qcache_max
95 The largest size of allocations which can be served by quantum cache.
96 It is merely a hint and can be ignored.
97 .It Fa flags
98 Combination of
99 .Xr malloc 9
100 wait flag and
101 .Nm
102 allocation strategy flag:
103 .Bl -tag -width M_FIRSTFIT
104 .It Dv M_FIRSTFIT
105 Prefer allocation performance.
106 .It Dv M_BESTFIT
107 Prefer space efficiency.
108 .El
109 .El
110 .Pp
111 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112 .Fn vmem_add
113 adds a span of size
114 .Fa size
115 starting at
116 .Fa addr
117 to the arena.
118 Returns
119 0
120 on success,
121 .Dv ENOMEM
122 on failure.
123 .Fa flags
124 is
125 .Xr malloc 9
126 wait flag.
127 .Pp
128 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129 .Fn vmem_xalloc
130 allocates a resource from the arena.
131 .Bl -tag -width nocross
132 .It Fa vm
133 The arena which we allocate from.
134 .It Fa size
135 Specify the size of the allocation.
136 .It Fa align
137 If zero, don't care about the alignment of the allocation.
138 Otherwise, request a resource segment starting at
139 offset
140 .Fa phase
141 from an
142 .Fa align
143 aligned boundary.
144 .It Fa phase
145 See the above description of
146 .Fa align .
147 If
148 .Fa align
149 is zero,
150 .Fa phase
151 should be zero.
152 Otherwise,
153 .Fa phase
154 should be smaller than
155 .Fa align .
156 .It Fa nocross
157 Request a resource which doesn't cross
158 .Fa nocross
159 aligned boundary.
160 .It Fa minaddr
161 Specify the minimum address which can be allocated, or
162 .Dv VMEM_ADDR_MIN
163 if the caller does not care.
164 .It Fa maxaddr
165 Specify the maximum address which can be allocated, or
166 .Dv VMEM_ADDR_MAX
167 if the caller does not care.
168 .It Fa flags
169 A bitwise OR of an allocation strategy and a
170 .Xr malloc 9
171 wait flag.
172 The allocation strategy is one of
173 .Dv M_FIRSTFIT
174 and
175 .Dv M_BESTFIT .
176 .It Fa addrp
177 On success, if
178 .Fa addrp
179 is not
180 .Dv NULL ,
181 .Fn vmem_xalloc
182 overwrites it with the start address of the allocated span.
183 .El
184 .Pp
185 .\" ------------------------------------------------------------
186 .Fn vmem_xfree
187 frees resource allocated by
188 .Fn vmem_xalloc
189 to the arena.
190 .Bl -tag -width addr
191 .It Fa vm
192 The arena which we free to.
193 .It Fa addr
194 The resource being freed.
195 It must be the one returned by
196 .Fn vmem_xalloc .
197 Notably, it must not be the one from
198 .Fn vmem_alloc .
199 Otherwise, the behaviour is undefined.
200 .It Fa size
201 The size of the resource being freed.
202 It must be the same as the
203 .Fa size
204 argument used for
205 .Fn vmem_xalloc .
206 .El
207 .Pp
208 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
209 .Fn vmem_alloc
210 allocates a resource from the arena.
211 .Bl -tag -width flags
212 .It Fa vm
213 The arena which we allocate from.
214 .It Fa size
215 Specify the size of the allocation.
216 .It Fa flags
217 A bitwise OR of an
218 .Nm
219 allocation strategy flag (see above) and a
220 .Xr malloc 9
221 sleep flag.
222 .It Fa addrp
223 On success, if
224 .Fa addrp
225 is not
226 .Dv NULL ,
227 .Fn vmem_alloc
228 overwrites it with the start address of the allocated span.
229 .El
230 .Pp
231 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232 .Fn vmem_free
233 frees resource allocated by
234 .Fn vmem_alloc
235 to the arena.
236 .Bl -tag -width addr
237 .It Fa vm
238 The arena which we free to.
239 .It Fa addr
240 The resource being freed.
241 It must be the one returned by
242 .Fn vmem_alloc .
243 Notably, it must not be the one from
244 .Fn vmem_xalloc .
245 Otherwise, the behaviour is undefined.
246 .It Fa size
247 The size of the resource being freed.
248 It must be the same as the
249 .Fa size
250 argument used for
251 .Fn vmem_alloc .
252 .El
253 .Pp
254 .\" ------------------------------------------------------------
255 .Fn vmem_destroy
256 destroys a vmem arena.
257 .Bl -tag -width vm
258 .It Fa vm
259 The vmem arena being destroyed.
260 The caller should ensure that no one will use it anymore.
261 .El
262 .\" ------------------------------------------------------------
263 .Sh RETURN VALUES
264 .Fn vmem_create
265 returns a pointer to the newly allocated vmem_t.
266 Otherwise, it returns
267 .Dv NULL .
268 .Pp
269 On success,
270 .Fn vmem_xalloc
271 and
272 .Fn vmem_alloc
273 return 0.
274 Otherwise,
275 .Dv ENOMEM
276 is returned.
277 .\" ------------------------------------------------------------
278 .Sh CODE REFERENCES
279 The
280 .Nm
281 subsystem is implemented within the file
282 .Pa sys/kern/subr_vmem.c .
283 .\" ------------------------------------------------------------
284 .Sh SEE ALSO
285 .Xr malloc 9
286 .Rs
287 .%A Jeff Bonwick
288 .%A Jonathan Adams
289 .%T "Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources"
290 .%J "2001 USENIX Annual Technical Conference"
291 .%D 2001
292 .Re
293 .\" ------------------------------------------------------------
294 .Sh HISTORY
295 The
296 .Nm
297 allocator was originally implemented in
298 .Nx .
299 It was introduced in
300 .Fx 10.0 .
301 .Sh AUTHORS
302 .An -nosplit
303 Original implementation of
304 .Nm
305 was written by
306 .An "YAMAMOTO Takashi" .
307 The
308 .Fx
309 port was made by
310 .An "Jeff Roberson" .
311 .Sh BUGS
312 .Nm
313 relies on
314 .Xr malloc 9 ,
315 so it cannot be used as early during system bootstrap.