DESCRIPTION

The extent manager provides management of areas of memory or other enu-
merable spaces (such as I/O ports). An opaque structure called an extentmap keeps track of allocated regions within the enumerable space.
extent_create() creates an extent map managing the space from start to
end inclusive. All memory allocation will use the memory type mtype
(see malloc(9)). The extent map will have the name name, used for iden-
tification in case of errors or in ddb(4)show extents. If the flag
EX_NOCOALESCE is set, internal coalescing of regions is disabled, and
only entire regions may be freed within the extent map, so that
extent_free() will never have to allocate a region descriptor.
Some applications may want to use an extent map but can't use malloc()
and free(). These applications may provide pre-allocated storage for all
descriptor overhead with the arguments storage and storagesize. An extent
of this type is called a fixed extent. If the application can safely use
malloc() and free(), storage should be NULL. A fixed extent has a fixed
number of region descriptors, so care should be taken to provide enough
storage for them; alternatively, the flag EX_MALLOCOK may be passed to
extent requests to indicate that a fixed extent map may be extended using
a call to malloc().
The caller should pass the flag EX_WAITOK or EX_NOWAIT to extent func-
tions that have a memory overhead, to specify whether it is okay to wait.
These functions are extent_create() (non fixed extents), extent_free()
(unless EX_NOCOALESCE is set), extent_alloc(), extent_alloc_subregion()
and extent_alloc_region().
extent_destroy() destroys the extent map ex, freeing all allocated re-
gions. If the extent is not a fixed extent, the region and internal ex-
tent descriptors themselves are freed. This function always succeeds.
extent_alloc() allocates a region in the extent map ex of size size that
fits the provided parameters. There are two distinct allocation policies,
which are selected by the flags argument:
EX_FAST Allocate the first region that fits the provided parame-
ters, regardless of resulting extent fragmentation.
default Allocate the smallest region that is capable of holding
the request, thus minimizing fragmentation of the ex-
tent.
The caller may specify that it is okay to wait for space to become free
in the extent by setting the flag EX_WAITSPACE. If EX_WAITSPACE is not
set, the allocation will fail if the request can not be satisfied without
sleeping.
The request will be aligned to a multiple of alignment. That value must
be a power of 2. If no alignment is necessary, the value EX_NOALIGN
should be specified. If skew is non-zero, it modifies the requested
alignment result in the following way: the value (result - skew) is
aligned to alignment boundaries. skew must be a smaller number than
alignment. If boundary is not EX_NOBOUNDARY, the allocated region will
not cross any boundary lines, spaced boundary apart. If the caller speci-
fies the EX_BOUNDZERO flag, boundary lines begin at zero. Otherwise,
boundary lines begin at the beginning of the extent. The allocated region
may begin on a boundary line, but the end of the region will not touch
nor cross a boundary line. A boundary argument smaller than the sum of
the requested skew and the size of the request is invalid. Upon success-
ful completion, *result will contain the start of the allocated region.
extent_alloc_subregion() is a generalized version of extent_alloc() that
also allows the caller to specify that the allocated region must fall
within the subregion from substart to subend inclusive.
extent_alloc_region() allocates the specific region in the extent map ex
beginning at start with the size size. The caller may specify that it is
okay to wait for the indicated region to be free by setting the flag
EX_WAITSPACE. If EX_WAITSPACE is not set, the allocation will fail if the
request can not be satisfied without sleeping.
extent_free() frees a region of size bytes starting at start in the ex-
tent map ex. If the extent has the EX_NOCOALESCE property, only entire
regions may be freed. If the extent has the EX_NOCOALESCE property and
the caller attempts to free a partial region, behavior is undefined. If
called on an extent without the EX_NOCOALESCE property, this function can
fail with error codes listed below, otherwise this function will always
succeed.
extent_print() Prints out information about extent ex. This function al-
ways succeeds.

RETURN VALUES

The behavior of all extent manager functions is undefined if given in-
valid arguments. extent_create() returns the extent map on success, or
NULL if it fails to allocate storage for the extent map. It always
succeeds when creating a fixed extent or when given the flag EX_WAITOK.
extent_alloc(), extent_alloc_region(), extent_alloc_subregion(), and
extent_free() return one of the following values:
0 Operation was successful.
ENOMEM If EX_NOWAIT is specified, the extent manager was not
able to allocate a region descriptor for the new region
or to split a region when freeing a partial region.
EAGAIN Requested region is not available and EX_WAITSPACE was
not specified.
EINTR Process received a signal while waiting for the requested
region to become available in the extent.

CODE REFERENCES

The extent manager itself is implemented within the file
sys/kern/subr_extent.c.
The i386 bus management code uses the extent manager for managing I/O
ports and I/O memory. See sys/arch/i386/i386/machdep.c.