.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\" $NetBSD: malloc.9,v 1.3 1996/11/11 00:05:11 lukem Exp $
.\" $FreeBSD: src/share/man/man9/malloc.9,v 1.13 2000/03/03 14:05:06 sheldonh Exp $
.Dd June 16, 1996
.Dt MALLOC 9
.Nm malloc ,
.Nm MALLOC ,
.Nm free ,
.Nd kernel memory management routines
.Fd #include <sys/types.h>
.Fd #include <sys/malloc.h>
.Ft void *
.Fn malloc "unsigned long size" "struct malloc_type *type" "int flags"
.Fn MALLOC "space" "cast" "unsigned long size" "struct malloc_type *type" "int flags"
.Fn free "void *addr" "struct malloc_type *type"
.Fn FREE "void *addr" "struct malloc_type *type"
macro variant is equivalent to
.Bd -literal -offset indent
Unlike its standard C library counterpart
.Pq Xr malloc 3 ,
the kernel version takes two more arguments. The
argument further qualifies
.Fn malloc No Ns 's
operational characteristics as follows:
.Bl -tag -width indent
.It Dv M_NOWAIT
if the request cannot be immediately fulfilled due to resource shortage.
may call sleep to wait for resources to be released by other processes.
If this flag is set,
rather then block. Note that
is defined to be 0, meaning that blocking operation is the default.
.It Dv M_ASLEEP
if the request cannot be immediately fulfilled due to a resource shortage.
M_ASLEEP is not useful alone and should always be or'd with M_NOWAIT to allow
malloc to call
immediately. It is expected that the caller will at some point call
and then retry the allocation. Depending on the routine in question, the
caller may decide to propagate the temporary failure up the call chain
and actually have some other higher level routine block on the async wait
renamed to something more obvious. This option has been depreciated and is
slowly being removed from the kernel, and so should not be used with any new
argument is used to perform statistics on memory usage, and for
basic sanity checks.
The statistics can be examined by
.Sq vmstat -m .
is defined using the
typedef via the
.Bd -literal -offset indent
/* sys/something/foo_extern.h */
/* sys/something/foo_main.c */
MALLOC_DEFINE(M_FOOBUF, "foobuffers", "Buffers to foo data into the ether");
/* sys/something/foo_subr.c */
MALLOC(buf, struct foo_buf *, sizeof *buf, M_FOOBUF, M_NOWAIT);
.Sh RETURN VALUES
returns a kernel virtual address that is suitably aligned for storage of
any type of object, or
if the request could not be satisfied and
was set. If
was set and
.Dv NULL ,
it will call
as a side effect.
.Dq malloc: bogus type
.Dq malloc: allocation too large
.Dq malloc: wrong bucket
.Dq malloc: lost data
.Dq free: address 0x%x out of range
.Dq free: type %d out of range
.Dq free: unaligned addr Aq description of object
.Dq free: item modified
.Dq free: multiple free[s]
.Dq Data modified on freelist: Aq description of object
Man(1) output converted with
Link to this Page
- enter. last edited on 11 January 2007 at 1:11 am by Q0f80.q.pppool.de