1.\" $NetBSD: memoryallocators.9,v 1.4 2009/08/03 20:02:55 rmind Exp $ 2.\" 3.\" Copyright (c) 2011 Venkatesh Srinivas 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.\" $FreeBSD: src/share/man/man9/zone.9,v 1.9.2.4 2002/05/02 20:01:29 asmodai Exp $ 28.\" 29.Dd March 23, 2011 30.Dt MEMORY 9 31.Os 32.Sh NAME 33.Nm memory 34.Nd introduction to kernel memory allocators 35.Sh DESCRIPTION 36The 37.Dx 38kernel provides several memory allocators, each with different characteristics 39and purposes. 40.Ss kmalloc 41kmalloc is the primary kernel memory allocator. kmalloc allocates pages from 42the kernel address space via 43.Xr vm_page_alloc 9 44and constructs buffers by slicing allocated pages. Allocations larger than 8 KB 45are served directly with pages from the kernel address space. kmalloc tracks 46allocation statistics in a malloc_zone structure, which must be declared 47before use. 48.Pp 49kmalloc is implemented as a slab allocator, with per-CPU slab structures. It 50may block while attempting to get free pages. 51.Pp 52For more information, see 53.Xr kmalloc 9 . 54.Ss Object caches 55The object cache is a frontend memory allocator to some backing allocator. It 56provides for per-CPU caches of constructed objects, saving time on setup of 57allocated structures. The object cache is well-suited to oft-allocated 58structures which have relatively complex setup routines. 59.Pp 60The object cache routines may block allocating cache structures or buffers. 61.Pp 62For more information, see 63.Xr objcache 9 . 64.Ss MPIPE 65MPIPE is a memory allocator frontend to kmalloc; an MPIPE can be created with 66a fixed number of buffers. The MPIPE guarantees that the desired 67number of buffers are available and can be allocated without blocking. Beyond 68the fixed count, MPIPE calls kmalloc and may block or may fail to allocate. 69.Pp 70For more information see 71.Xr mpipe 9 . 72.Ss The Zone Allocator 73The zone allocator is a specialized memory allocator; it performs a similar 74function to kmalloc, but it can run from statically allocated structures in 75addition to dynamically allocated vm_pages. The zone allocator should be 76restricted to use before the VM is initialized and to core VM structures. 77.Pp 78The zone allocator may block. 79.Pp 80For more information see 81.Xr zone 9 . 82.Sh HISTORY 83The kmalloc and Zone allocators were inherited from 84.Fx . 85The kmalloc allocator was converted to a per-CPU slab allocator in 86.Dx 1.0 . 87.Pp 88The MPIPE allocator appeared in 89.Dx 1.0 . 90The Object cache appeared in 91.Dx 1.3 . 92.Sh AUTHORS 93.An -nosplit 94This manual page is based on the 95.Nx 96analogue, by 97.An Elad Efrat Aq elad@NetBSD.org 98and 99.An YAMAMOTO Takashi Aq yamt@NetBSD.org . 100