186d7f5d3SJohn Marino.\" 286d7f5d3SJohn Marino.\" Copyright (c) 2004 Joseph Koshy 386d7f5d3SJohn Marino.\" All rights reserved. 486d7f5d3SJohn Marino.\" 586d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 686d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 786d7f5d3SJohn Marino.\" are met: 886d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 986d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 1086d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 1186d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 1286d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 1386d7f5d3SJohn Marino.\" 1486d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 1586d7f5d3SJohn Marino.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1686d7f5d3SJohn Marino.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1786d7f5d3SJohn Marino.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE 1886d7f5d3SJohn Marino.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1986d7f5d3SJohn Marino.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2086d7f5d3SJohn Marino.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2186d7f5d3SJohn Marino.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2286d7f5d3SJohn Marino.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2386d7f5d3SJohn Marino.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2486d7f5d3SJohn Marino.\" POSSIBILITY OF SUCH DAMAGE. 2586d7f5d3SJohn Marino.\" 2686d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man9/contigmalloc.9,v 1.5 2005/01/21 08:36:40 ru Exp $ 2786d7f5d3SJohn Marino.\" $DragonFly: src/share/man/man9/contigmalloc.9,v 1.1 2008/01/19 08:23:17 swildner Exp $ 2886d7f5d3SJohn Marino.\" 2986d7f5d3SJohn Marino.Dd January 19, 2008 3086d7f5d3SJohn Marino.Dt CONTIGMALLOC 9 3186d7f5d3SJohn Marino.Os 3286d7f5d3SJohn Marino.Sh NAME 3386d7f5d3SJohn Marino.Nm contigmalloc , 3486d7f5d3SJohn Marino.Nm contigfree 3586d7f5d3SJohn Marino.Nd manage contiguous kernel physical memory 3686d7f5d3SJohn Marino.Sh SYNOPSIS 3786d7f5d3SJohn Marino.In sys/types.h 3886d7f5d3SJohn Marino.In sys/malloc.h 3986d7f5d3SJohn Marino.Ft "void *" 4086d7f5d3SJohn Marino.Fo contigmalloc 4186d7f5d3SJohn Marino.Fa "unsigned long size" 4286d7f5d3SJohn Marino.Fa "struct malloc_type *type" 4386d7f5d3SJohn Marino.Fa "int flags" 4486d7f5d3SJohn Marino.Fa "vm_paddr_t low" 4586d7f5d3SJohn Marino.Fa "vm_paddr_t high" 4686d7f5d3SJohn Marino.Fa "unsigned long alignment" 4786d7f5d3SJohn Marino.Fa "unsigned long boundary" 4886d7f5d3SJohn Marino.Fc 4986d7f5d3SJohn Marino.Ft void 5086d7f5d3SJohn Marino.Fo contigfree 5186d7f5d3SJohn Marino.Fa "void *addr" 5286d7f5d3SJohn Marino.Fa "unsigned long size" 5386d7f5d3SJohn Marino.Fa "struct malloc_type *type" 5486d7f5d3SJohn Marino.Fc 5586d7f5d3SJohn Marino.Sh DESCRIPTION 5686d7f5d3SJohn MarinoThe 5786d7f5d3SJohn Marino.Fn contigmalloc 5886d7f5d3SJohn Marinofunction allocates 5986d7f5d3SJohn Marino.Fa size 6086d7f5d3SJohn Marinobytes of contiguous physical memory that is aligned to 6186d7f5d3SJohn Marino.Fa alignment 6286d7f5d3SJohn Marinobytes, and which does not cross a boundary of 6386d7f5d3SJohn Marino.Fa boundary 6486d7f5d3SJohn Marinobytes. 6586d7f5d3SJohn MarinoIf successful, the allocation will reside between physical addresses 6686d7f5d3SJohn Marino.Fa low 6786d7f5d3SJohn Marinoand 6886d7f5d3SJohn Marino.Fa high . 6986d7f5d3SJohn MarinoThe returned pointer points to a wired kernel virtual 7086d7f5d3SJohn Marinoaddress range of 7186d7f5d3SJohn Marino.Fa size 7286d7f5d3SJohn Marinobytes allocated from the kernel virtual address (KVA) map. 7386d7f5d3SJohn MarinoThe 7486d7f5d3SJohn Marino.Fa type 7586d7f5d3SJohn Marinoargument is ignored. 7686d7f5d3SJohn Marino.Pp 7786d7f5d3SJohn MarinoThe 7886d7f5d3SJohn Marino.Fa flags 7986d7f5d3SJohn Marinoparameter modifies 8086d7f5d3SJohn Marino.Fn contigmalloc Ns Ap s 8186d7f5d3SJohn Marinobehavior as follows: 8286d7f5d3SJohn Marino.Bl -tag -width ".Dv M_WAITOK" -offset indent 8386d7f5d3SJohn Marino.It Dv M_WAITOK 8486d7f5d3SJohn MarinoCauses 8586d7f5d3SJohn Marino.Fn contigmalloc 8686d7f5d3SJohn Marinoto try flushing the active page queue in its second pass. 8786d7f5d3SJohn MarinoNote that (unlike 8886d7f5d3SJohn Marino.Fn kmalloc M_WAITOK ) 8986d7f5d3SJohn Marino.Fn contigmalloc M_WAITOK 9086d7f5d3SJohn Marinocan still return NULL. 9186d7f5d3SJohn Marino.It Dv M_ZERO 9286d7f5d3SJohn MarinoCauses the allocated physical memory to be zero filled. 9386d7f5d3SJohn Marino.El 9486d7f5d3SJohn Marino.Pp 9586d7f5d3SJohn MarinoOther flags (if present) are ignored. 9686d7f5d3SJohn Marino.Pp 9786d7f5d3SJohn MarinoThe 9886d7f5d3SJohn Marino.Fn contigfree 9986d7f5d3SJohn Marinofunction deallocates memory allocated by a previous call to 10086d7f5d3SJohn Marino.Fn contigmalloc . 10186d7f5d3SJohn Marino.Sh IMPLEMENTATION NOTES 10286d7f5d3SJohn MarinoThe 10386d7f5d3SJohn Marino.Fn contigmalloc 10486d7f5d3SJohn Marinofunction does not sleep waiting for memory resources to be freed up, 10586d7f5d3SJohn Marinobut instead scans available physical memory a small number of times 10686d7f5d3SJohn Marinofor a suitably sized free address range before giving up. 10786d7f5d3SJohn MarinoMemory allocation is done on a first-fit basis, starting from the 10886d7f5d3SJohn Marinotop of the provided address range. 10986d7f5d3SJohn Marino.Sh RETURN VALUES 11086d7f5d3SJohn MarinoThe 11186d7f5d3SJohn Marino.Fn contigmalloc 11286d7f5d3SJohn Marinofunction returns a kernel virtual address if allocation succeeds, 11386d7f5d3SJohn Marinoor 11486d7f5d3SJohn Marino.Dv NULL 11586d7f5d3SJohn Marinootherwise. 11686d7f5d3SJohn Marino.Sh EXAMPLES 11786d7f5d3SJohn Marino.Bd -literal 11886d7f5d3SJohn Marinovoid *p; 11986d7f5d3SJohn Marinop = contigmalloc(8192, M_DEVBUF, M_ZERO, 0, (1L << 22), 12086d7f5d3SJohn Marino 32 * 1024, 1024 * 1024); 12186d7f5d3SJohn Marino.Ed 12286d7f5d3SJohn Marino.Pp 12386d7f5d3SJohn MarinoAsk for 8192 bytes of zero-filled memory residing between physical 12486d7f5d3SJohn Marinoaddress 0 and 4194303 inclusive, aligned to a 32K boundary and not 12586d7f5d3SJohn Marinocrossing a 1M address boundary. 12686d7f5d3SJohn Marino.Sh DIAGNOSTICS 12786d7f5d3SJohn MarinoThe 12886d7f5d3SJohn Marino.Fn contigmalloc 12986d7f5d3SJohn Marinofunction will panic if 13086d7f5d3SJohn Marino.Fa size 13186d7f5d3SJohn Marinois zero, or if 13286d7f5d3SJohn Marino.Fa alignment 13386d7f5d3SJohn Marinoor 13486d7f5d3SJohn Marino.Fa boundary 13586d7f5d3SJohn Marinois not a power of two. 13686d7f5d3SJohn Marino.Sh SEE ALSO 13786d7f5d3SJohn Marino.Xr kmalloc 9 138