1 .\" $NetBSD: extent.9,v 1.27 2007/03/07 00:41:17 dogcow Exp $
3 .\" Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe and Greg Hudson.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .Dd September 23, 1996
38 .Nm extent_alloc_subregion ,
39 .Nm extent_alloc_region ,
42 .Nd general purpose extent manager
47 .Fn extent_create "char *name" "u_long start" "u_long end" "int mtype" "void *storage" "size_t storagesize" "int flags"
49 .Fn extent_destroy "struct extent *ex"
51 .Fn extent_alloc "struct extent *ex" "u_long size" "u_long alignment" "u_long boundary" "int flags" "u_long *result"
53 .Fn extent_alloc_subregion "struct extent *ex" "u_long substart" "u_long subend" "u_long size" "u_long alignment" "u_long boundary" "u_long flags" "u_long *result"
55 .Fn extent_alloc1 "struct extent *ex" "u_long size" "u_long alignment" "u_long skew" "u_long boundary" "int flags" "u_long *result"
57 .\" too many arguments for a single .Fn
58 .Fo extent_alloc_subregion1
59 .Fa "struct extent *ex"
63 .Fa "u_long alignment"
70 .Fn extent_alloc_region "struct extent *ex" "u_long start" "u_long size" "int flags"
72 .Fn extent_free "struct extent *ex" "u_long start" "u_long size" "int flags"
74 .Fn extent_print "struct extent *ex"
78 extent manager provides management of areas of memory or
79 other number spaces (such as I/O ports).
80 An opaque structure called an
82 keeps track of allocated regions within the number space.
85 creates an extent map managing the space from
90 All memory allocation will use the memory type
96 The extent map will have the name
98 used for identification in case of an error.
101 is specified, only entire regions may be freed within the extent map,
102 but internal coalescing of regions is disabled so that
104 will never have to allocate a region descriptor and therefore will
106 The caller must specify one of the flags
110 specifying whether it is okay to wait for memory allocated for
113 There are some applications which may want to use an extent map but
118 These applications may provide pre-allocated storage for
119 all descriptor overhead with the arguments
123 An extent of this type is called a
125 If the application can safely use
132 A fixed extent has a fixed number of region descriptors, so care
133 should be taken to provide enough storage for them; alternatively, the
136 may be passed to allocation requests to indicate that a fixed extent
137 map may be extended using a call to
141 destroys the extent map
143 freeing all allocated regions.
144 If the extent is not a fixed extent, the region and internal extent
145 descriptors themselves are freed.
146 This function always succeeds.
149 allocates a region in extent
153 that fits the provided parameters.
154 There are two distinct allocation policies, which are selected by the
157 .Bl -tag -offset indent -width "XXXXXXXXX"
159 Allocate the first region that fits the provided parameters, regardless
160 of resulting extent fragmentation.
162 Allocate the smallest region that is capable of holding the request,
163 thus minimizing fragmentation of the extent.
166 The caller must specify if waiting for space in the extent is allowed
171 is not specified, the allocation will fail if the request can not be
172 satisfied without sleeping.
173 The caller must also specify, using the
177 flags, if waiting for overhead allocation is allowed.
178 The request will be aligned to
181 Alignment values must be a power of 2.
182 If no alignment is necessary, the value 1 should be specified.
185 is nonzero, the allocated region will not cross any of the numbers
186 which are a multiple of
188 If the caller specifies the
190 flag, the boundary lines begin at zero.
191 Otherwise, the boundary lines begin at the beginning of the extent.
192 The allocated region may begin on a boundary address, but the end of
193 the region will not touch nor cross it.
194 A boundary argument smaller than the size of the request is invalid.
195 Upon successful completion,
197 will contain the start of the allocated region.
199 .Fn extent_alloc_subregion
202 but it allows the caller to specify that the allocated region must
203 fall within the subregion from
208 The other arguments and the return values of
209 .Fn extent_alloc_subregion
210 are otherwise the same as those of
213 .Fn extent_alloc_region
214 allocates the specific region in the extent map
220 The caller must specify whether it is okay to wait for the indicated
221 region to be free using the flag
225 is not specified, the allocation will fail if the request can not be
226 satisfied without sleeping.
227 The caller must also specify, using the
231 flags, if waiting for overhead allocation is allowed.
236 .Fn extent_alloc_subregion1
237 functions are extensions that take one additional argument,
239 that modifies the requested alignment result in the following way:
241 .Pq Fa result No - Fa skew
246 must be a smaller number than
248 Also, a boundary argument smaller than the sum of the requested skew
249 and the size of the request is invalid.
258 If the extent has the
260 property, only entire regions may be freed.
261 If the extent has the
263 property and the caller attempts to free a partial region, behavior is
265 The caller must specify one of the flags
269 to specify whether waiting for memory is okay; these flags have
270 meaning in the event that allocation of a region descriptor is
271 required during the freeing process.
272 This situation occurs only when a partial region that begins and ends
273 in the middle of another region is freed.
274 Behavior is undefined if invalid arguments are provided.
277 Print out information about extent
279 This function always succeeds.
280 Behavior is undefined if invalid arguments are provided.
282 The extent manager performs all necessary locking on the extent map
283 itself, and any other data structures internal to the extent manager.
284 The locks used by the extent manager are simplelocks, and will never sleep
289 This should be taken into account when designing the locking protocol
290 for users of the extent manager.
292 The behavior of all extent manager functions is undefined if given
295 returns the extent map on success, or
297 if it fails to allocate storage for the extent map.
298 It always succeeds when creating a fixed extent or when given the flag
301 .Fn extent_alloc_region ,
302 .Fn extent_alloc_subregion ,
305 return one of the following values:
306 .Bl -tag -offset indent -width "XXXXXXXX"
308 Operation was successful.
312 is specified, the extent manager was not able to allocate a region
313 descriptor for the new region or to split a region when freeing a
316 Requested region is not available and
320 Process received a signal while waiting for the requested region to
321 become available in the extent.
326 Here is an example of a (useless) function that uses several of the
327 extent manager routines.
332 struct extent *foo_ex;
337 * Extent "foo" manages a 256k region starting at 0x0 and
338 * only allows complete regions to be freed so that
339 * extent_free() never needs to allocate memory.
341 foo_ex = extent_create("foo", 0x0, 0x3ffff, M_DEVBUF,
342 NULL, 0, EX_WAITOK | EX_NOCOALESCE);
345 * Allocate an 8k region, aligned to a 4k boundary, which
346 * does not cross any of the 3 64k boundaries (at 64k,
347 * 128k, and 192k) within the extent.
349 error = extent_alloc(foo_ex, 0x2000, 0x1000, 0x10000,
350 EX_NOWAIT, \*[Am]region_start);
355 * Give up the extent.
357 extent_destroy(foo_ex);
361 This section describes places within the
364 actual code implementing or using the extent manager can be found.
365 All pathnames are relative to
368 The extent manager itself is implemented within the file
369 .Pa sys/kern/subr_extent.c .
370 Function prototypes for the framework are located in
371 .Pa sys/sys/extent.h .
373 The i386 bus management code uses the extent manager for managing I/O
374 ports and I/O memory.
375 This code is in the file
376 .Pa sys/arch/i386/i386/machdep.c .
382 extent manager appeared in
387 extent manager was architected and implemented by
389 .Aq thorpej@NetBSD.org .
390 .An Matthias Drochner
391 .Aq drochner@zelux6.zel.kfa-juelich.de
392 contributed to the initial testing and optimization of the implementation.
395 contributed many architectural suggestions.