]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/vmem.9
bhnd(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.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 May 17, 2019
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 .Xr malloc 9
99 wait flag.
100 .El
101 .Pp
102 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103 .Fn vmem_add
104 adds a span of size
105 .Fa size
106 starting at
107 .Fa addr
108 to the arena.
109 Returns
110 0
111 on success,
112 .Dv ENOMEM
113 on failure.
114 .Fa flags
115 is
116 .Xr malloc 9
117 wait flag.
118 .Pp
119 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120 .Fn vmem_xalloc
121 allocates a resource from the arena.
122 .Bl -tag -width nocross
123 .It Fa vm
124 The arena which we allocate from.
125 .It Fa size
126 Specify the size of the allocation.
127 .It Fa align
128 If zero, don't care about the alignment of the allocation.
129 Otherwise, request a resource segment starting at
130 offset
131 .Fa phase
132 from an
133 .Fa align
134 aligned boundary.
135 .It Fa phase
136 See the above description of
137 .Fa align .
138 If
139 .Fa align
140 is zero,
141 .Fa phase
142 should be zero.
143 Otherwise,
144 .Fa phase
145 should be smaller than
146 .Fa align .
147 .It Fa nocross
148 Request a resource which doesn't cross
149 .Fa nocross
150 aligned boundary.
151 .It Fa minaddr
152 Specify the minimum address which can be allocated, or
153 .Dv VMEM_ADDR_MIN
154 if the caller does not care.
155 .It Fa maxaddr
156 Specify the maximum address which can be allocated, or
157 .Dv VMEM_ADDR_MAX
158 if the caller does not care.
159 .It Fa flags
160 A bitwise OR of an allocation strategy and a
161 .Xr malloc 9
162 wait flag.
163 The allocation strategy is one of:
164 .Bl -tag width indent
165 .It Dv M_FIRSTFIT
166 Prefer allocation performance.
167 .It Dv M_BESTFIT
168 Prefer space efficiency.
169 .It Dv M_NEXTFIT
170 Perform an address-ordered search for free addresses, beginning where
171 the previous search ended.
172 .El
173 .It Fa addrp
174 On success, if
175 .Fa addrp
176 is not
177 .Dv NULL ,
178 .Fn vmem_xalloc
179 overwrites it with the start address of the allocated span.
180 .El
181 .Pp
182 .\" ------------------------------------------------------------
183 .Fn vmem_xfree
184 frees resource allocated by
185 .Fn vmem_xalloc
186 to the arena.
187 .Bl -tag -width addr
188 .It Fa vm
189 The arena which we free to.
190 .It Fa addr
191 The resource being freed.
192 It must be the one returned by
193 .Fn vmem_xalloc .
194 Notably, it must not be the one from
195 .Fn vmem_alloc .
196 Otherwise, the behaviour is undefined.
197 .It Fa size
198 The size of the resource being freed.
199 It must be the same as the
200 .Fa size
201 argument used for
202 .Fn vmem_xalloc .
203 .El
204 .Pp
205 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206 .Fn vmem_alloc
207 allocates a resource from the arena.
208 .Bl -tag -width flags
209 .It Fa vm
210 The arena which we allocate from.
211 .It Fa size
212 Specify the size of the allocation.
213 .It Fa flags
214 A bitwise OR of an
215 .Nm
216 allocation strategy flag (see above) and a
217 .Xr malloc 9
218 sleep flag.
219 .It Fa addrp
220 On success, if
221 .Fa addrp
222 is not
223 .Dv NULL ,
224 .Fn vmem_alloc
225 overwrites it with the start address of the allocated span.
226 .El
227 .Pp
228 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 .Fn vmem_free
230 frees resource allocated by
231 .Fn vmem_alloc
232 to the arena.
233 .Bl -tag -width addr
234 .It Fa vm
235 The arena which we free to.
236 .It Fa addr
237 The resource being freed.
238 It must be the one returned by
239 .Fn vmem_alloc .
240 Notably, it must not be the one from
241 .Fn vmem_xalloc .
242 Otherwise, the behaviour is undefined.
243 .It Fa size
244 The size of the resource being freed.
245 It must be the same as the
246 .Fa size
247 argument used for
248 .Fn vmem_alloc .
249 .El
250 .Pp
251 .\" ------------------------------------------------------------
252 .Fn vmem_destroy
253 destroys a vmem arena.
254 .Bl -tag -width vm
255 .It Fa vm
256 The vmem arena being destroyed.
257 The caller should ensure that no one will use it anymore.
258 .El
259 .\" ------------------------------------------------------------
260 .Sh RETURN VALUES
261 .Fn vmem_create
262 returns a pointer to the newly allocated vmem_t.
263 Otherwise, it returns
264 .Dv NULL .
265 .Pp
266 On success,
267 .Fn vmem_xalloc
268 and
269 .Fn vmem_alloc
270 return 0.
271 Otherwise,
272 .Dv ENOMEM
273 is returned.
274 .\" ------------------------------------------------------------
275 .Sh CODE REFERENCES
276 The
277 .Nm
278 subsystem is implemented within the file
279 .Pa sys/kern/subr_vmem.c .
280 .\" ------------------------------------------------------------
281 .Sh SEE ALSO
282 .Xr malloc 9
283 .Rs
284 .%A Jeff Bonwick
285 .%A Jonathan Adams
286 .%T "Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources"
287 .%J "2001 USENIX Annual Technical Conference"
288 .%D 2001
289 .Re
290 .\" ------------------------------------------------------------
291 .Sh HISTORY
292 The
293 .Nm
294 allocator was originally implemented in
295 .Nx .
296 It was introduced in
297 .Fx 10.0 .
298 .Sh AUTHORS
299 .An -nosplit
300 Original implementation of
301 .Nm
302 was written by
303 .An "YAMAMOTO Takashi" .
304 The
305 .Fx
306 port was made by
307 .An "Jeff Roberson" .
308 .Sh BUGS
309 .Nm
310 relies on
311 .Xr malloc 9 ,
312 so it cannot be used as early during system bootstrap.