xref: /dflybsd-src/share/man/man9/contigmalloc.9 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino.\"
2*86d7f5d3SJohn Marino.\" Copyright (c) 2004 Joseph Koshy
3*86d7f5d3SJohn Marino.\" All rights reserved.
4*86d7f5d3SJohn Marino.\"
5*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino.\" are met:
8*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
12*86d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
13*86d7f5d3SJohn Marino.\"
14*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
15*86d7f5d3SJohn Marino.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16*86d7f5d3SJohn Marino.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17*86d7f5d3SJohn Marino.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
18*86d7f5d3SJohn Marino.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19*86d7f5d3SJohn Marino.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20*86d7f5d3SJohn Marino.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21*86d7f5d3SJohn Marino.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22*86d7f5d3SJohn Marino.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23*86d7f5d3SJohn Marino.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24*86d7f5d3SJohn Marino.\" POSSIBILITY OF SUCH DAMAGE.
25*86d7f5d3SJohn Marino.\"
26*86d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man9/contigmalloc.9,v 1.5 2005/01/21 08:36:40 ru Exp $
27*86d7f5d3SJohn Marino.\" $DragonFly: src/share/man/man9/contigmalloc.9,v 1.1 2008/01/19 08:23:17 swildner Exp $
28*86d7f5d3SJohn Marino.\"
29*86d7f5d3SJohn Marino.Dd January 19, 2008
30*86d7f5d3SJohn Marino.Dt CONTIGMALLOC 9
31*86d7f5d3SJohn Marino.Os
32*86d7f5d3SJohn Marino.Sh NAME
33*86d7f5d3SJohn Marino.Nm contigmalloc ,
34*86d7f5d3SJohn Marino.Nm contigfree
35*86d7f5d3SJohn Marino.Nd manage contiguous kernel physical memory
36*86d7f5d3SJohn Marino.Sh SYNOPSIS
37*86d7f5d3SJohn Marino.In sys/types.h
38*86d7f5d3SJohn Marino.In sys/malloc.h
39*86d7f5d3SJohn Marino.Ft "void *"
40*86d7f5d3SJohn Marino.Fo contigmalloc
41*86d7f5d3SJohn Marino.Fa "unsigned long size"
42*86d7f5d3SJohn Marino.Fa "struct malloc_type *type"
43*86d7f5d3SJohn Marino.Fa "int flags"
44*86d7f5d3SJohn Marino.Fa "vm_paddr_t low"
45*86d7f5d3SJohn Marino.Fa "vm_paddr_t high"
46*86d7f5d3SJohn Marino.Fa "unsigned long alignment"
47*86d7f5d3SJohn Marino.Fa "unsigned long boundary"
48*86d7f5d3SJohn Marino.Fc
49*86d7f5d3SJohn Marino.Ft void
50*86d7f5d3SJohn Marino.Fo contigfree
51*86d7f5d3SJohn Marino.Fa "void *addr"
52*86d7f5d3SJohn Marino.Fa "unsigned long size"
53*86d7f5d3SJohn Marino.Fa "struct malloc_type *type"
54*86d7f5d3SJohn Marino.Fc
55*86d7f5d3SJohn Marino.Sh DESCRIPTION
56*86d7f5d3SJohn MarinoThe
57*86d7f5d3SJohn Marino.Fn contigmalloc
58*86d7f5d3SJohn Marinofunction allocates
59*86d7f5d3SJohn Marino.Fa size
60*86d7f5d3SJohn Marinobytes of contiguous physical memory that is aligned to
61*86d7f5d3SJohn Marino.Fa alignment
62*86d7f5d3SJohn Marinobytes, and which does not cross a boundary of
63*86d7f5d3SJohn Marino.Fa boundary
64*86d7f5d3SJohn Marinobytes.
65*86d7f5d3SJohn MarinoIf successful, the allocation will reside between physical addresses
66*86d7f5d3SJohn Marino.Fa low
67*86d7f5d3SJohn Marinoand
68*86d7f5d3SJohn Marino.Fa high .
69*86d7f5d3SJohn MarinoThe returned pointer points to a wired kernel virtual
70*86d7f5d3SJohn Marinoaddress range of
71*86d7f5d3SJohn Marino.Fa size
72*86d7f5d3SJohn Marinobytes allocated from the kernel virtual address (KVA) map.
73*86d7f5d3SJohn MarinoThe
74*86d7f5d3SJohn Marino.Fa type
75*86d7f5d3SJohn Marinoargument is ignored.
76*86d7f5d3SJohn Marino.Pp
77*86d7f5d3SJohn MarinoThe
78*86d7f5d3SJohn Marino.Fa flags
79*86d7f5d3SJohn Marinoparameter modifies
80*86d7f5d3SJohn Marino.Fn contigmalloc Ns Ap s
81*86d7f5d3SJohn Marinobehavior as follows:
82*86d7f5d3SJohn Marino.Bl -tag -width ".Dv M_WAITOK" -offset indent
83*86d7f5d3SJohn Marino.It Dv M_WAITOK
84*86d7f5d3SJohn MarinoCauses
85*86d7f5d3SJohn Marino.Fn contigmalloc
86*86d7f5d3SJohn Marinoto try flushing the active page queue in its second pass.
87*86d7f5d3SJohn MarinoNote that (unlike
88*86d7f5d3SJohn Marino.Fn kmalloc M_WAITOK )
89*86d7f5d3SJohn Marino.Fn contigmalloc M_WAITOK
90*86d7f5d3SJohn Marinocan still return NULL.
91*86d7f5d3SJohn Marino.It Dv M_ZERO
92*86d7f5d3SJohn MarinoCauses the allocated physical memory to be zero filled.
93*86d7f5d3SJohn Marino.El
94*86d7f5d3SJohn Marino.Pp
95*86d7f5d3SJohn MarinoOther flags (if present) are ignored.
96*86d7f5d3SJohn Marino.Pp
97*86d7f5d3SJohn MarinoThe
98*86d7f5d3SJohn Marino.Fn contigfree
99*86d7f5d3SJohn Marinofunction deallocates memory allocated by a previous call to
100*86d7f5d3SJohn Marino.Fn contigmalloc .
101*86d7f5d3SJohn Marino.Sh IMPLEMENTATION NOTES
102*86d7f5d3SJohn MarinoThe
103*86d7f5d3SJohn Marino.Fn contigmalloc
104*86d7f5d3SJohn Marinofunction does not sleep waiting for memory resources to be freed up,
105*86d7f5d3SJohn Marinobut instead scans available physical memory a small number of times
106*86d7f5d3SJohn Marinofor a suitably sized free address range before giving up.
107*86d7f5d3SJohn MarinoMemory allocation is done on a first-fit basis, starting from the
108*86d7f5d3SJohn Marinotop of the provided address range.
109*86d7f5d3SJohn Marino.Sh RETURN VALUES
110*86d7f5d3SJohn MarinoThe
111*86d7f5d3SJohn Marino.Fn contigmalloc
112*86d7f5d3SJohn Marinofunction returns a kernel virtual address if allocation succeeds,
113*86d7f5d3SJohn Marinoor
114*86d7f5d3SJohn Marino.Dv NULL
115*86d7f5d3SJohn Marinootherwise.
116*86d7f5d3SJohn Marino.Sh EXAMPLES
117*86d7f5d3SJohn Marino.Bd -literal
118*86d7f5d3SJohn Marinovoid *p;
119*86d7f5d3SJohn Marinop = contigmalloc(8192, M_DEVBUF, M_ZERO, 0, (1L << 22),
120*86d7f5d3SJohn Marino    32 * 1024, 1024 * 1024);
121*86d7f5d3SJohn Marino.Ed
122*86d7f5d3SJohn Marino.Pp
123*86d7f5d3SJohn MarinoAsk for 8192 bytes of zero-filled memory residing between physical
124*86d7f5d3SJohn Marinoaddress 0 and 4194303 inclusive, aligned to a 32K boundary and not
125*86d7f5d3SJohn Marinocrossing a 1M address boundary.
126*86d7f5d3SJohn Marino.Sh DIAGNOSTICS
127*86d7f5d3SJohn MarinoThe
128*86d7f5d3SJohn Marino.Fn contigmalloc
129*86d7f5d3SJohn Marinofunction will panic if
130*86d7f5d3SJohn Marino.Fa size
131*86d7f5d3SJohn Marinois zero, or if
132*86d7f5d3SJohn Marino.Fa alignment
133*86d7f5d3SJohn Marinoor
134*86d7f5d3SJohn Marino.Fa boundary
135*86d7f5d3SJohn Marinois not a power of two.
136*86d7f5d3SJohn Marino.Sh SEE ALSO
137*86d7f5d3SJohn Marino.Xr kmalloc 9
138