Index Index for
Section 9
Index Alphabetical
listing for C
Index Bottom of
page

contig_malloc(9r)

NAME

contig_malloc - General: Allocates physically contiguous memory

SYNOPSIS

#include <sys/malloc.h> void * contig_malloc( u_long size, u_long alignment, u_long addrlimit, int type, int flag );

ARGUMENTS

size Specifies the size of the memory (in bytes) to allocate. alignment 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. addrlimit 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. type 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), and so forth. flag Specifies one of the following flags defined in /usr/sys/include/sys/malloc.h: M_ZERO Signifies that contig_malloc should zero the allocated memory. M_WAITOK Signifies that contig_malloc can block. M_NOWAIT Signifies that contig_malloc cannot block.

DESCRIPTION

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 drivers. However, the point or points in time in which the statically or dynamically configured driver requests the memory differ. A statically configured driver 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 driver frees this physically contiguous memory (by calling the contig_free routine), the memory is returned to the virtual memory subsystem. A dynamically configured driver 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 driver after single-user mode. To solve this problem, a dynamically configured driver 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 device drivers 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 driver needs to call contig_malloc after single-user mode, the physically contiguous memory comes from this saved memory pool. When a dynamically configured driver 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 driver upon subsequent reload requests that occur after single-user mode.

RETURN VALUES

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.

SEE ALSO

Routines: contig_free(9r)

Index Index for
Section 9
Index Alphabetical
listing for C
Index Top of
page