1 .\" $NetBSD: pool_cache.9,v 1.13 2009/10/15 20:50:13 thorpej Exp $
3 .\" Copyright (c)2003 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 .\" Copyright (c) 1997, 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
28 .\" All rights reserved.
30 .\" This code is derived from software contributed to The NetBSD Foundation
31 .\" by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace
32 .\" Simulation Facility, NASA Ames Research Center, and by Andrew Doran.
34 .\" Redistribution and use in source and binary forms, with or without
35 .\" modification, are permitted provided that the following conditions
37 .\" 1. Redistributions of source code must retain the above copyright
38 .\" notice, this list of conditions and the following disclaimer.
39 .\" 2. Redistributions in binary form must reproduce the above copyright
40 .\" notice, this list of conditions and the following disclaimer in the
41 .\" documentation and/or other materials provided with the distribution.
43 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
44 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
45 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
47 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 .\" POSSIBILITY OF SUCH DAMAGE.
55 .\" ------------------------------------------------------------
59 .\" ------------------------------------------------------------
63 .Nm pool_cache_destroy ,
64 .Nm pool_cache_get_paddr ,
66 .Nm pool_cache_put_paddr ,
68 .Nm pool_cache_destruct_object ,
69 .Nm pool_cache_invalidate ,
70 .Nm pool_cache_sethiwat ,
71 .Nm pool_cache_setlowat
72 .Nd resource-pool cache manager
73 .\" ------------------------------------------------------------
76 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 "size_t size" "u_int align" "u_int align_offset" "int flags" \
80 "const char *name" "struct pool_allocator *palloc" "int ipl" \
81 "int (*ctor)(void *, void *, int)" "void (*dtor)(void *, void *)" "void *arg"
82 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 .Fn pool_cache_destroy \
86 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 .Fn pool_cache_get_paddr \
89 "pool_cache_t pc" "int flags" "paddr_t *pap"
90 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
93 "pool_cache_t pc" "int flags"
94 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 .Fn pool_cache_put_paddr \
97 "pool_cache_t pc" "void *object" "paddr_t pa"
98 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 "pool_cache_t pc" "void *object"
102 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104 .Fn pool_cache_destruct_object \
105 "pool_cache_t pc" "void *object"
106 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 .Fn pool_cache_invalidate \
110 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112 .Fn pool_cache_sethiwat \
113 "pool_cache_t pc" "int nitems"
115 .Fn pool_cache_setlowat \
116 "pool_cache_t pc" "int nitems"
117 .\" ------------------------------------------------------------
119 These utility routines provide management of pools of fixed-sized
121 Resource pools set aside an amount of memory for exclusive use by the resource
123 This can be used by applications to guarantee the availability of a minimum
124 amount of memory needed to continue operation independent of the memory
125 resources currently available from the system-wide memory allocator.
127 Global and per-CPU caches of constructed objects are maintained.
128 The two levels of cache work together to allow for low overhead
129 allocation and release of objects, and improved L1/L2/L3 hardware
130 cache locality in multiprocessor systems.
131 .\" ------------------------------------------------------------
133 .Bl -tag -width compact
134 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135 .It Fn pool_cache_init "size" "align" "align_offset" "flags" \
136 "name" "palloc" "ipl" "ctor" "dtor" "arg"
138 Allocate and initialize a pool cache.
144 Specifies the size of the memory items managed by the pool.
147 Specifies the memory address alignment of the items returned by
149 This argument must be a power of two.
151 the alignment defaults to an architecture-specific natural alignment.
154 The offset within an item to which the
159 Should be set to zero or
163 is given, free items are never used to keep internal state so that
164 the pool can be used for non memory backed objects.
167 The name used to identify the object in diagnostic output.
170 Should be typically be set to NULL, instructing
172 to select an appropriate back-end allocator.
173 Alternate allocators can be used to partition space from arbitrary sources.
174 Use of alternate allocators is not documented here as it is not a stable,
175 endorsed part of the API.
178 Specifies an interrupt priority level that will block all interrupt
179 handlers that could potentially access the pool.
182 facility provides its own synchronization.
183 The users of any given
185 need not provide additional synchronization for access to it.
188 Specifies a constructor used to initialize newly allocated objects.
189 If no constructor is required, specify
193 Specifies a destructor used to destroy cached objects prior to
194 their release to backing store.
195 If no destructor is required, specify
199 This value of this argument will be passed to both the constructor
200 and destructor routines.
202 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
203 .It Fn pool_cache_destroy "pc"
207 All other access to the cache must be stopped before this call
209 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210 .It Fn pool_cache_get_paddr "pc" "flags" "pap"
212 Get an object from a pool cache
218 physical address of the object or
219 .Dv POOL_PADDR_INVALID
220 will be returned via it.
224 function of the backing
226 and the object constructor specified when the pool cache is created by
227 .Fn pool_cache_init .
228 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229 .It Fn pool_cache_get "pc" "flags"
233 .Fn pool_cache_get_paddr
238 It's implemented as a macro.
239 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 .It Fn pool_cache_put_paddr "pc" "object" "pa"
244 back to the pool cache
247 should be physical address of the object
250 .Dv POOL_PADDR_INVALID .
252 If the number of available items in the backing pool exceeds the maximum
254 .Fn pool_cache_sethiwat
255 and there are no outstanding requests for pool items,
256 the excess items will be returned to the system.
257 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
258 .It Fn pool_cache_put "pc" "object"
262 .Fn pool_cache_put_paddr
264 .Dv POOL_PADDR_INVALID
267 It's implemented as a macro.
268 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
269 .It Fn pool_cache_destruct_object "pc" "object"
271 Force destruction of an object
273 and its release back into the pool.
274 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
275 .It Fn pool_cache_invalidate "pc"
277 Invalidate a pool cache
279 All objects in the cache will be destructed and freed back to the pool
281 For pool caches that vend constructed objects, consumers of this API
282 must take care to provide proper synchronization between the input to
283 the constructor and cache invalidation.
284 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
285 .It Fn pool_cache_sethiwat "pc" "nitems"
287 A pool will attempt to increase its resource usage to keep up with the demand
290 it will return unused memory to the system should the number of accumulated
291 unused items in the pool exceed a programmable limit.
292 The limits for the minimum and maximum number of items which a pool should keep
293 at hand are known as the high and low
297 .Fn pool_cache_sethiwat
298 sets the backing pool's high water mark.
299 As items are returned and the total number of pages in the pool is larger
300 than the maximum set by this function,
301 any completely unused pages are released immediately.
302 If this function is not used to specify a maximum number of items,
303 the pages will remain associated with the pool until the system runs low
305 at which point the VM system will try to reclaim unused pages.
306 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307 .It Fn pool_cache_setlowat "pc" "nitems"
309 Set the minimum number of items to keep in the pool.
310 The number pages in the pool will not decrease below the required value to
311 accommodate the minimum number of items specified by this function.
313 .\" ------------------------------------------------------------
315 This section describes places within the
317 source tree where actual code implementing the
321 All pathnames are relative to
326 subsystem is implemented within the file
327 .Pa sys/kern/subr_pool.c .
331 .Xr memoryallocators 9 ,