1 .\" $NetBSD: vmem.9,v 1.7 2009/12/21 22:49:18 dyoung Exp $
3 .\" Copyright (c)2006 YAMAMOTO Takashi,
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
27 .\" ------------------------------------------------------------
31 .\" ------------------------------------------------------------
34 .Nd virtual memory allocator
35 .\" ------------------------------------------------------------
38 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 "const char *name" "vmem_addr_t base" "vmem_size_t size" "vmem_size_t quantum" \
42 "vmem_addr_t (*allocfn)(vmem_t *, vmem_size_t, vmem_size_t *, vm_flag_t)" \
43 "void (*freefn)(vmem_t *, vmem_addr_t, vmem_size_t)" \
44 "vmem_t *source" "vmem_size_t qcache_max" "vm_flag_t flags" "int ipl"
45 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size" "vm_flag_t flags"
49 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 "vmem_t *vm" "vmem_size_t size" "vmem_size_t align" \
53 "vmem_size_t phase" "vmem_size_t nocross" "vmem_addr_t minaddr" \
54 "vmem_addr_t maxaddr" "vm_flag_t flags"
55 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 .Fn vmem_xfree "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
58 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 .Fn vmem_alloc "vmem_t *vm" "vmem_size_t size" "vm_flag_t flags"
61 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 .Fn vmem_free "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
64 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 .Fn vmem_destroy "vmem_t *vm"
67 .\" ------------------------------------------------------------
71 is a general purpose resource allocator.
72 Despite its name, it can be used for arbitrary resources
73 other than virtual memory.
75 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 creates a new vmem arena.
79 .Bl -tag -width qcache_max
81 The string to describe the vmem.
83 The start address of the initial span.
86 if no initial span is required.
88 The size of the initial span.
90 The smallest unit of allocation.
92 The callback function used to import spans from the backend arena.
99 to disable automatic imports.
105 .Fa "\*[Am]actualsize"
108 to import a span of size at least
111 should accept the same
118 to indicate failure, or
119 else the starting address of the imported span.
122 succeeds, it must write the actual size of the allocation to
124 The actual size will always be greater than or equal to the requested size.
126 The callback function used to free spans to the backend arena.
136 .Fn "(*freefn)" source addr size
143 that was previously allocated by
153 as the first argument of
158 The largest size of allocations which can be served by quantum cache.
159 It is merely a hint and can be ignored.
162 .Bl -tag -width VM_NOSLEEP
164 Can sleep until enough resources are available.
169 if there are not enough resources available.
172 Interrupt level to be blocked for allocating from vmem.
175 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
187 .Bl -tag -width VM_NOSLEEP
189 Can sleep until enough resources are available.
194 if there are not enough resources available.
197 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199 allocates a resource from the arena.
201 .Bl -tag -width nocross
203 The arena which we allocate from.
205 Specify the size of the allocation.
207 If zero, don't care about the alignment of the allocation.
208 Otherwise, request a resource segment starting at
215 See the above description of
224 should be smaller than
227 Request a resource which doesn't cross
231 If non-zero, specify the minimum address which can be allocated.
233 If non-zero, specify the maximum address + 1 which can be allocated.
235 A bitwise OR of an allocation strategy and a sleep flag.
237 The allocation strategy is one of:
238 .Bl -tag -width VM_INSTANTFIT
240 Prefer space efficiency.
245 The sleep flag should be one of:
246 .Bl -tag -width VM_NOSLEEP
248 Can sleep until enough resources are available.
253 if there are not enough resources available.
257 .\" ------------------------------------------------------------
259 frees resource allocated by
265 The arena which we free to.
267 The resource being freed.
268 It must be the one returned by
270 Notably, it must not be the one from
272 Otherwise, the behaviour is undefined.
274 The size of the resource being freed.
275 It must be the same as the
281 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
283 allocates a resource from the arena.
285 .Bl -tag -width flags
287 The arena which we allocate from.
289 Specify the size of the allocation.
291 A bitwise OR of an allocation strategy and a sleep flag.
293 The allocation strategy is one of:
294 .Bl -tag -width VM_INSTANTFIT
296 Prefer space efficiency.
301 The sleep flag should be one of:
302 .Bl -tag -width VM_NOSLEEP
304 Can sleep until enough resources are available.
309 if there are not enough resources available.
313 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
315 frees resource allocated by
321 The arena which we free to.
323 The resource being freed.
324 It must be the one returned by
326 Notably, it must not be the one from
328 Otherwise, the behaviour is undefined.
330 The size of the resource being freed.
331 It must be the same as the
337 .\" ------------------------------------------------------------
339 destroys a vmem arena.
343 The vmem arena being destroyed.
344 The caller should ensure that no one will use it anymore.
346 .\" ------------------------------------------------------------
349 return a pointer to the newly allocated vmem_t.
350 Otherwise, it returns
357 return an allocated vmem_addr_t.
361 .\" ------------------------------------------------------------
363 This section describes places within the
365 source tree where actual code implementing the
367 subsystem can be found.
368 All pathnames are relative to
373 subsystem is implemented within the file
374 .Pa sys/kern/subr_vmem.c .
375 .\" ------------------------------------------------------------
379 .Xr memoryallocators 9 ,
384 .%T "Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources"
385 .%J "2001 USENIX Annual Technical Conference"
388 .\" ------------------------------------------------------------
390 This implementation of
393 .An YAMAMOTO Takashi .
396 cannot manage a resource that starts at 0, because it reserves the
400 for indicating errors.
403 cannot manage a resource that ends at the maximum
405 This is an implementation limitation.
413 so it cannot be used as early during system bootstrap as