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