MALLOC(9) 386BSD Kernel Programmer's Manual MALLOC(9)
NAME
malloc - kernel dynamic memory allocator
SYNOPSIS
#include "malloc.h"
void *
malloc(u_long size, int type, int flags)
void
free(void *addr, int type)
DESCRIPTION
Most shared resources in the 386BSD kernel are dynamically allocated on
demand to serve need (with administrative bounds present to avoid system
overrun). The malloc() function is used to allocate small (<= 64KB)
portions of memory in the kernel, and is especially useful in sub-page
sized allocations, since it maintains a free pool of page fragments to
allocate from.
While this function superfically resembles the user mode malloc(3)
function, it has two additional arguments. Associated with each
allocation is a type which tags allocations of a given kind for use in
statistics and run-away allocation prevention. In addition, malloc() has
a flags argument to select optional handling (M_NOWAIT is the most common
option, allowing the function to be used from interrupt level by
disallowing a block if no space available).
The malloc() function obtains memory for its pool from the virtual memory
system via the kmem(9) facility.
The free() function returns used memory to the memory pool. If a surplus
of memory is present in the allocator's pool, it will attempt to return
whole pages back to the kmem(9) facility. As such, it defers to the
virtual memory system as the primary location where memory resource
resides.
Since the virtual memory system itself makes use of malloc() for its
operation, care is taken to avoid recursion.
RETURN VALUES
The malloc() function returns a address of the allocated resource if
successful; otherwise a null address is returned.
SEE ALSO
kmem(9)
386BSD Release 1.0 August 29, 1994 1