void
pool_init(
struct pool *pp
size_t size
u_int align
u_int align_offset
int flags
const char *wchan
struct pool_allocator *palloc
int ipl
)
void
pool_destroy(
struct pool *pp
)
void
*
pool_get(
struct pool *pp
, int flags
)
void
pool_put(
struct pool *pp
, void *item
)
int
pool_prime(
struct pool *pp
, int nitems
)
void
pool_sethiwat(
struct pool *pp
, int n
)
void
pool_setlowat(
struct pool *pp
, int n
)
)
initializes a resource pool.
The arguments are:
pp
size
align
).
This argument must be a power of two.
If zero,
the alignment defaults to an architecture-specific natural alignment.
align_offset
align
parameter applies.
flags
PR_NOTOUCH
.
If
PR_NOTOUCH
is given, free items are never used to keep internal state so that
the pool can be used for non memory backed objects.
wchan
)
must wait for items to be returned to the pool.
palloc
NULL
or
pool_allocator_kmem
,
in which case the default kernel memory allocator will be used.
It can also be set to
pool_allocator_nointr
when the pool will never be accessed from interrupt context.
ipl
The
POOL_INIT()
macro can be used to both declare and initialize a resource pool.
The
POOL_INIT(
)
macro has the same arguments as the
pool_init(
)
function and the resource pool will be initialized automatically
during system startup.
)
destroys a resource pool.
It takes a single argument
pp
identifying the pool resource instance.
)
allocates an item from the pool and returns a pointer to it.
The arguments are:
pp
flags
PR_NOWAIT
is given,
pool_get(
)
returns
NULL
.
If
PR_WAITOK
is given and allocation is attempted with no resources available,
the function will sleep until items are returned to the pool.
If both
PR_LIMITFAIL
and
PR_WAITOK
are specified, and the pool has reached its hard limit,
pool_get(
)
will return
NULL
without waiting, allowing the caller to do its own garbage collection;
however, it will still wait if the pool is not yet at its hard limit.
)
returns the pool item pointed at by
item
to the resource pool identified by the pool handle
pp
.
If the number of available items in the pool exceeds the maximum pool
size set by
pool_sethiwat(
)
and there are no outstanding requests for pool items,
the excess items will be returned to the system.
The arguments to
pool_put(
)
are:
pp
item
).
)
adds items to the pool.
Storage space for the items is allocated by using the page allocation
routine specified to
pool_create(
).
The arguments to
pool_prime()
are:
pp
nitems
This function may return
ENOMEM
in case the requested number of items could not be allocated.
Otherwise,
the return value is 0.
)
and
pool_setlowat(
)
set a pool's high and low watermarks, respectively.
pool_sethiwat()
pp
n
pool_setlowat()
pp
n
),
this function does not allocate the necessary memory up-front.
The pool resource code uses a per-pool lock to protect its internal state.
If any pool functions are called in an interrupt context,
the caller must block all interrupts that might cause the
code to be reentered.
Additionally, the functions
pool_init()
and
pool_destroy(
)
should never be called in interrupt context.
POOL_DIAGNOSTIC
.
sys/kern/subr_pool.c
.