|
contig_malloc(9r)
Contents
|
contig_malloc - General: Allocates physically contiguous
memory
#include <sys/malloc.h>
void * contig_malloc(
u_long size,
u_long alignment,
u_long addrlimit,
int type,
int flag );
Specifies the size of the memory (in bytes) to allocate.
Specifies the alignment of the memory to be allocated. For
example, for a 256-byte alignment, you should pass the
value 256. A 0 (zero) value means there is no alignment
requirement. Specifies that the address of all the allocated
memory should be less than or equal to this address.
A 0 (zero) value means that there is no address limit
requirement. Specifies the purpose for which the memory
is being allocated (or freed). The memory type constants
are defined in the file /usr/sys/include/sys/malloc.h.
Examples of memory type constants are M_DEVBUF (device
driver memory), M_KTABLE (kernel table memory), M_RTABLE
(routing tables memory), M_EXEMPT (exempt memory), and so
forth. Specifies one of the following flags defined in
/usr/sys/include/sys/malloc.h: Signifies that contig_malloc
should zero the allocated memory. Signifies that contig_malloc
can block. Signifies that contig_malloc cannot
block.
The contig_malloc routine allocates physically contiguous
memory during the boot process (before single-user mode).
The routine carves out an area of physically contiguous
memory from a contiguous memory buffer and allocates memory
from this buffer with proper alignment. The call to
contig_malloc is the same for statically or dynamically
configured kernel modules. However, the point or points in
time in which the statically or dynamically configured
kernel module requests the memory differ.
A statically configured kernel module typically needs to
call contig_malloc only before single-user mode. In this
case, contig_malloc obtains the memory from the contiguous
memory buffer. When a statically configured kernel module
frees this physically contiguous memory (by calling the
contig_free routine), the memory is returned to the virtual
memory subsystem.
A dynamically configured kernel module typically needs
physically contiguous memory after single-user mode. As
stated previously, contig_malloc carves out an area of
physically contiguous memory from a contiguous memory
buffer before single-user mode. Thus, this memory would
not be available to the dynamically configured kernel module
after single-user mode. To solve this problem, a
dynamically configured kernel module calls contig_malloc
by defining the CMA_Option attribute in the sysconfigtab
file fragment.
The cma_dd subsystem calls contig_malloc on behalf of
dynamically configured kernel modules and obtains the memory
allocation size (and other information) from the
CMA_Option attribute field. In this case, contig_malloc
allocates physically contiguous memory from the contiguous
memory buffer and places it in a saved memory pool. When a
dynamically configured kernel module needs to call contig_malloc
after single-user mode, the physically contiguous
memory comes from this saved memory pool. When a
dynamically configured kernel module frees this physically
contiguous memory (by calling the contig_free routine),
the memory is returned to the saved memory pool (not to
the virtual memory subsystem). Thus, this physically contiguous
memory is available to the dynamically configured
kernel module upon subsequent reload requests that occur
after single-user mode.
An exempt region of memory can be allocated through the
use of contig_malloc. This can be done in a pseudo device
driver in the postconfig_callback routine. ( Exempt memory
is memory managed by UNIX, but not included in testing
and core dumps.)
Allocating exempt memory follows the same guidelines that
a normal contiguous malloc would follow except: The type
field would be M_EXEMPT, trackable with vmstat -M. The
addrlimit field has been overloaded to allow specification
of a starting address. (The starting address is a physical
address.) If an address is specified and not available,
the call will return a failure. Use of the alignment
parameter is useless in this case. A call would look
like:
addr = contig_malloc(size, alignment, start_addr,
M_EXEMPT, flags);
Where: Indicates the allocation size in bytes (this
must be specified) Indicates the allocation alignment
if no start_addr or zero to default to base
page size. Indicates the base start address to
allocate from or 0 if no preference.
This can also be done using the sysconfigtab entry. Under
cma_dd:
CMA_option = size - 0x40000, alignment - 0, Addrlimit - 0,
Type - 143, Flag - 1
The arguments are the same as in the example call. 143
corresponds to what is in malloc.h. Note that the returned
addr will have the low bit set if there is a bad page in
the allocated region.
Upon successful completion, contig_malloc returns a
pointer to the allocated memory. If contig_malloc cannot
allocate the requested memory, it returns a null pointer.
Routines: contig_free(9r)
contig_malloc(9r)
[ Back ] |