Bump date for new pool_cache_invalidate_local().
[netbsd-mini2440.git] / share / man / man9 / pool_cache.9
blob6f6af60a4c17b574fbfdae226d1c43d784726b8a
1 .\"     $NetBSD: pool_cache.9,v 1.11 2009/10/08 21:54:45 jym Exp $
2 .\"
3 .\" Copyright (c)2003 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 .\" Copyright (c) 1997, 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
28 .\" All rights reserved.
29 .\"
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.
33 .\"
34 .\" Redistribution and use in source and binary forms, with or without
35 .\" modification, are permitted provided that the following conditions
36 .\" are met:
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.
42 .\"
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.
54 .\"
55 .\" ------------------------------------------------------------
56 .Dd October 9, 2009
57 .Dt POOL_CACHE 9
58 .Os
59 .\" ------------------------------------------------------------
60 .Sh NAME
61 .Nm pool_cache ,
62 .Nm pool_cache_init ,
63 .Nm pool_cache_destroy ,
64 .Nm pool_cache_get_paddr ,
65 .Nm pool_cache_get ,
66 .Nm pool_cache_put_paddr ,
67 .Nm pool_cache_put ,
68 .Nm pool_cache_destruct_object ,
69 .Nm pool_cache_invalidate ,
70 .Nm pool_cache_invalidate_local ,
71 .Nm pool_cache_sethiwat ,
72 .Nm pool_cache_setlowat
73 .Nd resource-pool cache manager
74 .\" ------------------------------------------------------------
75 .Sh SYNOPSIS
76 .In sys/pool.h
77 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 .Ft pool_cache_t
79 .Fn pool_cache_init \
80 "size_t size" "u_int align" "u_int align_offset" "int flags" \
81 "const char *name" "struct pool_allocator *palloc" "int ipl" \
82 "int (*ctor)(void *, void *, int)" "void (*dtor)(void *, void *)" "void *arg"
83 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 .Ft void
85 .Fn pool_cache_destroy \
86 "pool_cache_t pc"
87 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 .Ft void *
89 .Fn pool_cache_get_paddr \
90 "pool_cache_t pc" "int flags" "paddr_t *pap"
91 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 .Ft void *
93 .Fn pool_cache_get \
94 "pool_cache_t pc" "int flags"
95 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96 .Ft void
97 .Fn pool_cache_put_paddr \
98 "pool_cache_t pc" "void *object" "paddr_t pa"
99 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 .Ft void
101 .Fn pool_cache_put \
102 "pool_cache_t pc" "void *object"
103 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104 .Ft void
105 .Fn pool_cache_destruct_object \
106 "pool_cache_t pc" "void *object"
107 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 .Ft void
109 .Fn pool_cache_invalidate \
110 "pool_cache_t pc"
111 .Ft void
112 .Fn pool_cache_invalidate_local \
113 "pool_cache_t pc"
114 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115 .Ft void
116 .Fn pool_cache_sethiwat \
117 "pool_cache_t pc" "int nitems"
118 .Ft void
119 .Fn pool_cache_setlowat \
120 "pool_cache_t pc" "int nitems"
121 .\" ------------------------------------------------------------
122 .Sh DESCRIPTION
123 These utility routines provide management of pools of fixed-sized
124 areas of memory.
125 Resource pools set aside an amount of memory for exclusive use by the resource
126 pool owner.
127 This can be used by applications to guarantee the availability of a minimum
128 amount of memory needed to continue operation independent of the memory
129 resources currently available from the system-wide memory allocator.
131 Global and per-CPU caches of constructed objects are maintained.
132 The two levels of cache work together to allow for low overhead
133 allocation and release of objects, and improved L1/L2/L3 hardware
134 cache locality in multiprocessor systems.
135 .\" ------------------------------------------------------------
136 .Sh FUNCTIONS
137 .Bl -tag -width compact
138 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
139 .It Fn pool_cache_init "pc" "pp" "ctor" "dtor" "arg"
141 Allocate and initialize a pool cache.
142 The arguments are:
144 .Bl -tag -width four
145 .It Fa size
147 Specifies the size of the memory items managed by the pool.
148 .It Fa align
150 Specifies the memory address alignment of the items returned by
151 .Fn pool_cache_get .
152 This argument must be a power of two.
153 If zero,
154 the alignment defaults to an architecture-specific natural alignment.
155 .It Fa align_offset
157 The offset within an item to which the
158 .Fa align
159 parameter applies.
160 .It Fa flags
162 Should be set to zero or
163 .Dv PR_NOTOUCH .
165 .Dv PR_NOTOUCH
166 is given, free items are never used to keep internal state so that
167 the pool can be used for non memory backed objects.
168 .It Fa name
170 The name used to identify the object in diagnostic output.
171 .It Fa palloc
173 Should be typically be set to NULL, instructing
174 .Fn pool_cache_init
175 to select an appropriate back-end allocator.
176 Alternate allocators can be used to partition space from arbitrary sources.
177 Use of alternate allocators is not documented here as it is not a stable,
178 endorsed part of the API.
179 .It Fa ipl
181 Specifies an interrupt priority level that will block all interrupt
182 handlers that could potentially access the pool.
185 facility provides its own synchronization.
186 The users of any given
188 need not provide additional synchronization for access to it.
189 .It Fa ctor
191 Specifies a constructor used to initialize newly allocated objects.
192 If no constructor is required, specify
193 .Dv NULL .
194 .It Fa dtor
196 Specifies a destructor used to destroy cached objects prior to
197 their release to backing store.
198 If no destructor is required, specify
199 .Dv NULL .
200 .It Fa arg
202 This value of this argument will be passed to both the constructor
203 and destructor routines.
205 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206 .It Fn pool_cache_destroy "pc"
208 Destroy a pool cache
209 .Fa pc .
210 All other access to the cache must be stopped before this call
211 can be made.
212 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
213 .It Fn pool_cache_get_paddr "pc" "flags" "pap"
215 Get an object from a pool cache
216 .Fa pc .
218 .Fa pap
219 is not
220 .Dv NULL ,
221 physical address of the object or
222 .Dv POOL_PADDR_INVALID
223 will be returned via it.
224 .Fa flags
225 will be passed to
226 .Fn pool_get
227 function of the backing
228 .Xr pool 9
229 and the object constructor specified when the pool cache is created by
230 .Fn pool_cache_init .
231 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232 .It Fn pool_cache_get "pc" "flags"
234 .Fn pool_cache_get
235 is the same as
236 .Fn pool_cache_get_paddr
237 with
238 .Dv NULL
239 .Fa pap
240 argument.
241 It's implemented as a macro.
242 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
243 .It Fn pool_cache_put_paddr "pc" "object" "pa"
245 Put an object
246 .Fa object
247 back to the pool cache
248 .Fa pc .
249 .Fa pa
250 should be physical address of the object
251 .Fa object
253 .Dv POOL_PADDR_INVALID .
254 .Fa pp .
255 If the number of available items in the backing pool exceeds the maximum
256 pool size set by
257 .Fn pool_cache_sethiwat
258 and there are no outstanding requests for pool items,
259 the excess items will be returned to the system.
260 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261 .It Fn pool_cache_put "pc" "object"
263 .Fn pool_cache_put
264 is the same as
265 .Fn pool_cache_put_paddr
266 with
267 .Dv POOL_PADDR_INVALID
268 .Fa pa
269 argument.
270 It's implemented as a macro.
271 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
272 .It Fn pool_cache_destruct_object "pc" "object"
274 Force destruction of an object
275 .Fa object
276 and its release back into the pool.
277 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
278 .It Fn pool_cache_invalidate "pc"
280 Invalidate a pool cache
281 .Fa pc .
282 Destruct and release all objects in the global cache.
283 Per-CPU caches will not be invalidated by this call, meaning that it
284 is still possible to allocate "stale" items from the cache.
285 If relevant, the user must check for this condition when allocating
286 items.
287 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
288 .It Fn pool_cache_invalidate_local "pc"
290 Invalidate local, current CPU pool cache
291 .Fa pc .
292 Destruct and release all objects in the local, current CPU cache.
293 Only the Per-CPU caches associated to the current CPU calling the routine
294 will be invalidated, meaning that stale items can still be allocated from
295 other CPUs or the global cache.
296 It is the caller's responsibility to ensure that such conditions do
297 not occur.
298 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
299 .It Fn pool_cache_sethiwat "pc" "nitems"
301 A pool will attempt to increase its resource usage to keep up with the demand
302 for its items.
303 Conversely,
304 it will return unused memory to the system should the number of accumulated
305 unused items in the pool exceed a programmable limit.
306 The limits for the minimum and maximum number of items which a pool should keep
307 at hand are known as the high and low
308 .Sy watermarks .
310 The function
311 .Fn pool_cache_sethiwat
312 sets the backing pool's high water mark.
313 As items are returned and the total number of pages in the pool is larger
314 than the maximum set by this function,
315 any completely unused pages are released immediately.
316 If this function is not used to specify a maximum number of items,
317 the pages will remain associated with the pool until the system runs low
318 on memory,
319 at which point the VM system will try to reclaim unused pages.
320 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
321 .It Fn pool_cache_setlowat "pc" "nitems"
323 Set the minimum number of items to keep in the pool.
324 The number pages in the pool will not decrease below the required value to
325 accommodate the minimum number of items specified by this function.
327 .\" ------------------------------------------------------------
328 .Sh CODE REFERENCES
329 This section describes places within the
331 source tree where actual code implementing the
333 subsystem
334 can be found.
335 All pathnames are relative to
336 .Pa /usr/src .
340 subsystem is implemented within the file
341 .Pa sys/kern/subr_pool.c .
342 .Sh SEE ALSO
343 .Xr intro 9 ,
344 .Xr kmem 9 ,
345 .Xr memoryallocators 9 ,
346 .Xr pool 9