|MALLOC(9)||Kernel Developer's Manual||MALLOC(9)|
kernel memory allocator
size, int type,
nmemb, size_t size,
*addr, int type,
function allocates uninitialized memory in kernel address space for an
object whose size is specified by size.
function is the same as
malloc(), but allocates
space for an array of nmemb objects and checks for
function releases memory at address addr that was
previously allocated by
mallocarray() for re-use. The same object size
originally provided to
malloc() should be specified
by size, because
operate faster knowing this. If tracking the size is difficult, specify
size as 0. If addr is a null
pointer, no action occurs.
The flags argument affects the
operational characteristics of
mallocarray() as follows:
malloc() may call sleep to wait for resources to be released by other processes.
malloc() to return
NULLif the request cannot be immediately fulfilled due to resource shortage.
M_WAITOKcase, if not enough memory is available, return
NULLinstead of calling panic(9). If
mallocarray() detects an overflow or
malloc() detects an excessive allocation, return
NULLinstead of calling panic(9).
M_WAITOK must be specified via the
The type argument broadly identifies the
kernel subsystem for which the allocated memory was needed, and is commonly
used to maintain statistics about kernel memory usage. These statistics can
be examined using vmstat(8) or
systat(1) if either of the kernel
The following types are currently defined:
mallocarray() can be called during autoconf, from
process context, or from interrupt context if
M_NOWAIT is passed via flags.
They can't be called from interrupt context if
M_WAITOK is passed via
free() can be called during autoconf, from
process context, or from interrupt context.
mallocarray() return a kernel virtual address that
is suitably aligned for storage of any type of object.
A kernel compiled with the
configuration option attempts to detect memory corruption caused by such
things as writing outside the allocated area and unbalanced calls to
free(). Failing consistency checks will cause a
panic or a system console message:
|February 3, 2022||OpenBSD-current|