/* * Copyright (c) 2011 Free Software Foundation. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* * Copyright (c) 2010, 2011 Richard Braun. * All rights reserved. * * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * * * Object caching memory allocator. */ #ifndef _KERN_SLAB_H #define _KERN_SLAB_H #include #include #include #include /* * Object cache. */ struct kmem_cache; /* * Type for constructor functions. * * The pre-constructed state of an object is supposed to include only * elements such as e.g. linked lists, locks, reference counters. Therefore * constructors are expected to 1) never fail and 2) not need any * user-provided data. The first constraint implies that object construction * never performs dynamic resource allocation, which also means there is no * need for destructors. */ typedef void (*kmem_cache_ctor_t)(void *obj); /* * Types for slab allocation/free functions. * * All addresses and sizes must be page-aligned. */ typedef vm_offset_t (*kmem_slab_alloc_fn_t)(vm_size_t); typedef void (*kmem_slab_free_fn_t)(vm_offset_t, vm_size_t); #include /* * Mach-style declarations for struct kmem_cache. */ typedef struct kmem_cache *kmem_cache_t; #define KMEM_CACHE_NULL ((kmem_cache_t) 0) /* * VM submap for slab allocations. */ extern vm_map_t kmem_map; /* * Cache initialization flags. */ #define KMEM_CACHE_NOCPUPOOL 0x1 /* Don't use the per-cpu pools */ #define KMEM_CACHE_NOOFFSLAB 0x2 /* Don't allocate external slab data */ #define KMEM_CACHE_VERIFY 0x4 /* Use debugging facilities */ /* * Initialize a cache. * * If a slab allocation/free function pointer is NULL, the default backend * (vm_kmem on the kernel map) is used for the allocation/free action. */ void kmem_cache_init(struct kmem_cache *cache, const char *name, size_t obj_size, size_t align, kmem_cache_ctor_t ctor, kmem_slab_alloc_fn_t slab_alloc_fn, kmem_slab_free_fn_t slab_free_fn, int flags); /* * Allocate an object from a cache. */ vm_offset_t kmem_cache_alloc(struct kmem_cache *cache); /* * Release an object to its cache. */ void kmem_cache_free(struct kmem_cache *cache, vm_offset_t obj); /* * Initialize the memory allocator module. */ void slab_bootstrap(void); void slab_init(void); /* * Release free slabs to the VM system. */ void slab_collect(void); /* * Display a summary of all kernel caches. */ void slab_info(void); #endif /* _KERN_SLAB_H */