uma.h revision 177921
167754Smsmith/*- 267754Smsmith * Copyright (c) 2002, 2003, 2004, 2005 Jeffrey Roberson <jeff@FreeBSD.org> 367754Smsmith * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org> 491116Smsmith * All rights reserved. 567754Smsmith * 667754Smsmith * Redistribution and use in source and binary forms, with or without 767754Smsmith * modification, are permitted provided that the following conditions 867754Smsmith * are met: 967754Smsmith * 1. Redistributions of source code must retain the above copyright 1067754Smsmith * notice unmodified, this list of conditions, and the following 1167754Smsmith * disclaimer. 1291116Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1370243Smsmith * notice, this list of conditions and the following disclaimer in the 1467754Smsmith * documentation and/or other materials provided with the distribution. 1567754Smsmith * 1667754Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1767754Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1867754Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1967754Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2067754Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2167754Smsmith * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2267754Smsmith * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2367754Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2467754Smsmith * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2567754Smsmith * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2667754Smsmith * 2767754Smsmith * $FreeBSD: head/sys/vm/uma.h 177921 2008-04-04 18:41:12Z alc $ 2867754Smsmith * 2967754Smsmith */ 3067754Smsmith 3167754Smsmith/* 3267754Smsmith * uma.h - External definitions for the Universal Memory Allocator 3367754Smsmith * 3467754Smsmith*/ 3567754Smsmith 3667754Smsmith#ifndef VM_UMA_H 3767754Smsmith#define VM_UMA_H 3867754Smsmith 3967754Smsmith#include <sys/param.h> /* For NULL */ 4067754Smsmith#include <sys/malloc.h> /* For M_* */ 4167754Smsmith 4267754Smsmith/* User visable parameters */ 4367754Smsmith#define UMA_SMALLEST_UNIT (PAGE_SIZE / 256) /* Smallest item allocated */ 4467754Smsmith 4567754Smsmith/* Types and type defs */ 4667754Smsmith 4767754Smsmithstruct uma_zone; 4867754Smsmith/* Opaque type used as a handle to the zone */ 4967754Smsmithtypedef struct uma_zone * uma_zone_t; 5067754Smsmith 5167754Smsmithvoid zone_drain(uma_zone_t); 5267754Smsmith 5367754Smsmith/* 5467754Smsmith * Item constructor 5567754Smsmith * 5667754Smsmith * Arguments: 5767754Smsmith * item A pointer to the memory which has been allocated. 5867754Smsmith * arg The arg field passed to uma_zalloc_arg 5967754Smsmith * size The size of the allocated item 6067754Smsmith * flags See zalloc flags 6167754Smsmith * 6267754Smsmith * Returns: 6367754Smsmith * 0 on success 6467754Smsmith * errno on failure 6567754Smsmith * 6667754Smsmith * Discussion: 6767754Smsmith * The constructor is called just before the memory is returned 6867754Smsmith * to the user. It may block if necessary. 6967754Smsmith */ 7067754Smsmithtypedef int (*uma_ctor)(void *mem, int size, void *arg, int flags); 7167754Smsmith 7267754Smsmith/* 7367754Smsmith * Item destructor 7467754Smsmith * 7567754Smsmith * Arguments: 7667754Smsmith * item A pointer to the memory which has been allocated. 7767754Smsmith * size The size of the item being destructed. 7867754Smsmith * arg Argument passed through uma_zfree_arg 7967754Smsmith * 8067754Smsmith * Returns: 8167754Smsmith * Nothing 8267754Smsmith * 8367754Smsmith * Discussion: 8467754Smsmith * The destructor may perform operations that differ from those performed 8567754Smsmith * by the initializer, but it must leave the object in the same state. 8667754Smsmith * This IS type stable storage. This is called after EVERY zfree call. 8767754Smsmith */ 8867754Smsmithtypedef void (*uma_dtor)(void *mem, int size, void *arg); 8967754Smsmith 9067754Smsmith/* 9167754Smsmith * Item initializer 9267754Smsmith * 9367754Smsmith * Arguments: 9467754Smsmith * item A pointer to the memory which has been allocated. 9567754Smsmith * size The size of the item being initialized. 9667754Smsmith * flags See zalloc flags 9767754Smsmith * 9867754Smsmith * Returns: 9967754Smsmith * 0 on success 10067754Smsmith * errno on failure 10167754Smsmith * 10267754Smsmith * Discussion: 10367754Smsmith * The initializer is called when the memory is cached in the uma zone. 10467754Smsmith * this should be the same state that the destructor leaves the object in. 10567754Smsmith */ 10667754Smsmithtypedef int (*uma_init)(void *mem, int size, int flags); 10767754Smsmith 10867754Smsmith/* 10967754Smsmith * Item discard function 11067754Smsmith * 11167754Smsmith * Arguments: 11267754Smsmith * item A pointer to memory which has been 'freed' but has not left the 11367754Smsmith * zone's cache. 11467754Smsmith * size The size of the item being discarded. 11567754Smsmith * 11667754Smsmith * Returns: 11767754Smsmith * Nothing 11867754Smsmith * 11967754Smsmith * Discussion: 12067754Smsmith * This routine is called when memory leaves a zone and is returned to the 12167754Smsmith * system for other uses. It is the counter part to the init function. 12267754Smsmith */ 12367754Smsmithtypedef void (*uma_fini)(void *mem, int size); 12467754Smsmith 12577424Smsmith/* 12691116Smsmith * What's the difference between initializing and constructing? 12767754Smsmith * 12867754Smsmith * The item is initialized when it is cached, and this is the state that the 12967754Smsmith * object should be in when returned to the allocator. The purpose of this is 13067754Smsmith * to remove some code which would otherwise be called on each allocation by 13167754Smsmith * utilizing a known, stable state. This differs from the constructor which 13267754Smsmith * will be called on EVERY allocation. 13383174Smsmith * 13467754Smsmith * For example, in the initializer you may want to initialize embeded locks, 13567754Smsmith * NULL list pointers, set up initial states, magic numbers, etc. This way if 13667754Smsmith * the object is held in the allocator and re-used it won't be necessary to 13783174Smsmith * re-initialize it. 13867754Smsmith * 13967754Smsmith * The constructor may be used to lock a data structure, link it on to lists, 14067754Smsmith * bump reference counts or total counts of outstanding structures, etc. 14167754Smsmith * 14267754Smsmith */ 14384491Smsmith 14467754Smsmith 14567754Smsmith/* Function proto types */ 14667754Smsmith 14783174Smsmith/* 14891116Smsmith * Create a new uma zone 14967754Smsmith * 15067754Smsmith * Arguments: 15180062Smsmith * name The text name of the zone for debugging and stats, this memory 15267754Smsmith * should not be freed until the zone has been deallocated. 15367754Smsmith * size The size of the object that is being created. 15467754Smsmith * ctor The constructor that is called when the object is allocated 15567754Smsmith * dtor The destructor that is called when the object is freed. 15667754Smsmith * init An initializer that sets up the initial state of the memory. 15782367Smsmith * fini A discard function that undoes initialization done by init. 15867754Smsmith * ctor/dtor/init/fini may all be null, see notes above. 15984491Smsmith * align A bitmask that corisponds to the requested alignment 16067754Smsmith * eg 4 would be 0x3 16191116Smsmith * flags A set of parameters that control the behavior of the zone 16267754Smsmith * 16367754Smsmith * Returns: 16467754Smsmith * A pointer to a structure which is intended to be opaque to users of 16567754Smsmith * the interface. The value may be null if the wait flag is not set. 16667754Smsmith */ 16767754Smsmithuma_zone_t uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor, 16867754Smsmith uma_init uminit, uma_fini fini, int align, 16967754Smsmith u_int32_t flags); 17067754Smsmith 17183174Smsmith/* 17267754Smsmith * Create a secondary uma zone 17367754Smsmith * 17467754Smsmith * Arguments: 17583174Smsmith * name The text name of the zone for debugging and stats, this memory 17667754Smsmith * should not be freed until the zone has been deallocated. 17767754Smsmith * ctor The constructor that is called when the object is allocated 17867754Smsmith * dtor The destructor that is called when the object is freed. 17967754Smsmith * zinit An initializer that sets up the initial state of the memory 18067754Smsmith * as the object passes from the Keg's slab to the Zone's cache. 18167754Smsmith * zfini A discard function that undoes initialization done by init 18267754Smsmith * as the object passes from the Zone's cache to the Keg's slab. 18367754Smsmith * 18467754Smsmith * ctor/dtor/zinit/zfini may all be null, see notes above. 18567754Smsmith * Note that the zinit and zfini specified here are NOT 18667754Smsmith * exactly the same as the init/fini specified to uma_zcreate() 18767754Smsmith * when creating a master zone. These zinit/zfini are called 18891116Smsmith * on the TRANSITION from keg to zone (and vice-versa). Once 18967754Smsmith * these are set, the primary zone may alter its init/fini 19083174Smsmith * (which are called when the object passes from VM to keg) 19191116Smsmith * using uma_zone_set_init/fini()) as well as its own 19267754Smsmith * zinit/zfini (unset by default for master zone) with 19367754Smsmith * uma_zone_set_zinit/zfini() (note subtle 'z' prefix). 19467754Smsmith * 19567754Smsmith * master A reference to this zone's Master Zone (Primary Zone), 19667754Smsmith * which contains the backing Keg for the Secondary Zone 19767754Smsmith * being added. 19867754Smsmith * 19967754Smsmith * Returns: 20067754Smsmith * A pointer to a structure which is intended to be opaque to users of 20167754Smsmith * the interface. The value may be null if the wait flag is not set. 20267754Smsmith */ 20367754Smsmithuma_zone_t uma_zsecond_create(char *name, uma_ctor ctor, uma_dtor dtor, 20467754Smsmith uma_init zinit, uma_fini zfini, uma_zone_t master); 20567754Smsmith 20667754Smsmith/* 20767754Smsmith * Definitions for uma_zcreate flags 20867754Smsmith * 20967754Smsmith * These flags share space with UMA_ZFLAGs in uma_int.h. Be careful not to 21067754Smsmith * overlap when adding new features. 0xf0000000 is in use by uma_int.h. 21167754Smsmith */ 21267754Smsmith#define UMA_ZONE_PAGEABLE 0x0001 /* Return items not fully backed by 21367754Smsmith physical memory XXX Not yet */ 21467754Smsmith#define UMA_ZONE_ZINIT 0x0002 /* Initialize with zeros */ 21567754Smsmith#define UMA_ZONE_STATIC 0x0004 /* Staticly sized zone */ 21682367Smsmith#define UMA_ZONE_OFFPAGE 0x0008 /* Force the slab structure allocation 21767754Smsmith off of the real memory */ 21867754Smsmith#define UMA_ZONE_MALLOC 0x0010 /* For use by malloc(9) only! */ 21987031Smsmith#define UMA_ZONE_NOFREE 0x0020 /* Do not free slabs of this type! */ 22067754Smsmith#define UMA_ZONE_MTXCLASS 0x0040 /* Create a new lock class */ 22187031Smsmith#define UMA_ZONE_VM 0x0080 /* 22280062Smsmith * Used for internal vm datastructures 22367754Smsmith * only. 22467754Smsmith */ 22567754Smsmith#define UMA_ZONE_HASH 0x0100 /* 22667754Smsmith * Use a hash table instead of caching 22767754Smsmith * information in the vm_page. 22867754Smsmith */ 22967754Smsmith#define UMA_ZONE_SECONDARY 0x0200 /* Zone is a Secondary Zone */ 23067754Smsmith#define UMA_ZONE_REFCNT 0x0400 /* Allocate refcnts in slabs */ 23167754Smsmith#define UMA_ZONE_MAXBUCKET 0x0800 /* Use largest buckets */ 23267754Smsmith 23383174Smsmith/* Definitions for align */ 23467754Smsmith#define UMA_ALIGN_PTR (sizeof(void *) - 1) /* Alignment fit for ptr */ 23567754Smsmith#define UMA_ALIGN_LONG (sizeof(long) - 1) /* "" long */ 23667754Smsmith#define UMA_ALIGN_INT (sizeof(int) - 1) /* "" int */ 23767754Smsmith#define UMA_ALIGN_SHORT (sizeof(short) - 1) /* "" short */ 23887031Smsmith#define UMA_ALIGN_CHAR (sizeof(char) - 1) /* "" char */ 23987031Smsmith#define UMA_ALIGN_CACHE (0 - 1) /* Cache line size align */ 24067754Smsmith 24187031Smsmith/* 24291116Smsmith * Destroys an empty uma zone. If the zone is not empty uma complains loudly. 24387031Smsmith * 24467754Smsmith * Arguments: 24567754Smsmith * zone The zone we want to destroy. 24667754Smsmith * 24767754Smsmith */ 24867754Smsmithvoid uma_zdestroy(uma_zone_t zone); 24967754Smsmith 25083174Smsmith/* 25191116Smsmith * Allocates an item out of a zone 25267754Smsmith * 25367754Smsmith * Arguments: 25467754Smsmith * zone The zone we are allocating from 25567754Smsmith * arg This data is passed to the ctor function 25667754Smsmith * flags See sys/malloc.h for available flags. 25791116Smsmith * 25867754Smsmith * Returns: 25967754Smsmith * A non null pointer to an initialized element from the zone is 26067754Smsmith * garanteed if the wait flag is M_WAITOK, otherwise a null pointer may be 26167754Smsmith * returned if the zone is empty or the ctor failed. 26267754Smsmith */ 26367754Smsmith 26467754Smsmithvoid *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags); 26567754Smsmith 26667754Smsmith/* 26767754Smsmith * Allocates an item out of a zone without supplying an argument 26867754Smsmith * 26967754Smsmith * This is just a wrapper for uma_zalloc_arg for convenience. 27087031Smsmith * 27167754Smsmith */ 27267754Smsmithstatic __inline void *uma_zalloc(uma_zone_t zone, int flags); 27367754Smsmith 27467754Smsmithstatic __inline void * 27567754Smsmithuma_zalloc(uma_zone_t zone, int flags) 27667754Smsmith{ 27767754Smsmith return uma_zalloc_arg(zone, NULL, flags); 27867754Smsmith} 27967754Smsmith 28067754Smsmith/* 28167754Smsmith * Frees an item back into the specified zone. 28267754Smsmith * 28367754Smsmith * Arguments: 28467754Smsmith * zone The zone the item was originally allocated out of. 28567754Smsmith * item The memory to be freed. 28667754Smsmith * arg Argument passed to the destructor 28767754Smsmith * 28867754Smsmith * Returns: 28967754Smsmith * Nothing. 29067754Smsmith */ 29167754Smsmith 29267754Smsmithvoid uma_zfree_arg(uma_zone_t zone, void *item, void *arg); 29367754Smsmith 29467754Smsmith/* 29567754Smsmith * Frees an item back to a zone without supplying an argument 29667754Smsmith * 29767754Smsmith * This is just a wrapper for uma_zfree_arg for convenience. 29867754Smsmith * 29967754Smsmith */ 30067754Smsmithstatic __inline void uma_zfree(uma_zone_t zone, void *item); 30167754Smsmith 30267754Smsmithstatic __inline void 30367754Smsmithuma_zfree(uma_zone_t zone, void *item) 30477424Smsmith{ 30567754Smsmith uma_zfree_arg(zone, item, NULL); 30667754Smsmith} 30767754Smsmith 30867754Smsmith/* 30967754Smsmith * XXX The rest of the prototypes in this header are h0h0 magic for the VM. 31067754Smsmith * If you think you need to use it for a normal zone you're probably incorrect. 31167754Smsmith */ 31282367Smsmith 31391116Smsmith/* 31467754Smsmith * Backend page supplier routines 31567754Smsmith * 31667754Smsmith * Arguments: 31767754Smsmith * zone The zone that is requesting pages 31867754Smsmith * size The number of bytes being requested 31967754Smsmith * pflag Flags for these memory pages, see below. 32077424Smsmith * wait Indicates our willingness to block. 32167754Smsmith * 32267754Smsmith * Returns: 32367754Smsmith * A pointer to the alloced memory or NULL on failure. 32467754Smsmith */ 32567754Smsmith 32667754Smsmithtypedef void *(*uma_alloc)(uma_zone_t zone, int size, u_int8_t *pflag, int wait); 32767754Smsmith 32867754Smsmith/* 32967754Smsmith * Backend page free routines 33067754Smsmith * 33167754Smsmith * Arguments: 33267754Smsmith * item A pointer to the previously allocated pages 33367754Smsmith * size The original size of the allocation 33467754Smsmith * pflag The flags for the slab. See UMA_SLAB_* below 33567754Smsmith * 33667754Smsmith * Returns: 33767754Smsmith * None 33867754Smsmith */ 33982367Smsmithtypedef void (*uma_free)(void *item, int size, u_int8_t pflag); 34091116Smsmith 34167754Smsmith 34267754Smsmith 34367754Smsmith/* 34467754Smsmith * Sets up the uma allocator. (Called by vm_mem_init) 34567754Smsmith * 34691116Smsmith * Arguments: 34767754Smsmith * bootmem A pointer to memory used to bootstrap the system. 34867754Smsmith * 34967754Smsmith * Returns: 35067754Smsmith * Nothing 35167754Smsmith * 35267754Smsmith * Discussion: 35367754Smsmith * This memory is used for zones which allocate things before the 35467754Smsmith * backend page supplier can give us pages. It should be 35567754Smsmith * UMA_SLAB_SIZE * boot_pages bytes. (see uma_int.h) 35667754Smsmith * 35767754Smsmith */ 35867754Smsmith 35967754Smsmithvoid uma_startup(void *bootmem, int boot_pages); 36067754Smsmith 36167754Smsmith/* 36267754Smsmith * Finishes starting up the allocator. This should 36391116Smsmith * be called when kva is ready for normal allocs. 36491116Smsmith * 36567754Smsmith * Arguments: 36667754Smsmith * None 36767754Smsmith * 36867754Smsmith * Returns: 36967754Smsmith * Nothing 37067754Smsmith * 37167754Smsmith * Discussion: 37267754Smsmith * uma_startup2 is called by kmeminit() to enable us of uma for malloc. 37367754Smsmith */ 37467754Smsmith 37567754Smsmithvoid uma_startup2(void); 37667754Smsmith 37791116Smsmith/* 37867754Smsmith * Reclaims unused memory for all zones 37967754Smsmith * 38067754Smsmith * Arguments: 38167754Smsmith * None 38267754Smsmith * Returns: 38367754Smsmith * None 38467754Smsmith * 38567754Smsmith * This should only be called by the page out daemon. 38667754Smsmith */ 38767754Smsmith 38867754Smsmithvoid uma_reclaim(void); 38967754Smsmith 39067754Smsmith/* 39167754Smsmith * Sets the alignment mask to be used for all zones requesting cache 39267754Smsmith * alignment. Should be called by MD boot code prior to starting VM/UMA. 39367754Smsmith * 39467754Smsmith * Arguments: 39567754Smsmith * align The alignment mask 39667754Smsmith * 39767754Smsmith * Returns: 39867754Smsmith * Nothing 39967754Smsmith */ 40067754Smsmithvoid uma_set_align(int align); 40167754Smsmith 40267754Smsmith/* 40367754Smsmith * Switches the backing object of a zone 40467754Smsmith * 40567754Smsmith * Arguments: 40667754Smsmith * zone The zone to update 40785756Smsmith * obj The obj to use for future allocations 40867754Smsmith * size The size of the object to allocate 40967754Smsmith * 41067754Smsmith * Returns: 41167754Smsmith * 0 if kva space can not be allocated 41267754Smsmith * 1 if successful 41382367Smsmith * 41467754Smsmith * Discussion: 41582367Smsmith * A NULL object can be used and uma will allocate one for you. Setting 41667754Smsmith * the size will limit the amount of memory allocated to this zone. 41767754Smsmith * 41867754Smsmith */ 41985756Smsmithstruct vm_object; 42067754Smsmithint uma_zone_set_obj(uma_zone_t zone, struct vm_object *obj, int size); 42185756Smsmith 42280062Smsmith/* 42367754Smsmith * Sets a high limit on the number of items allowed in a zone 42467754Smsmith * 42567754Smsmith * Arguments: 42667754Smsmith * zone The zone to limit 42767754Smsmith * 42867754Smsmith * Returns: 42967754Smsmith * Nothing 43067754Smsmith */ 43167754Smsmithvoid uma_zone_set_max(uma_zone_t zone, int nitems); 43267754Smsmith 43367754Smsmith/* 43467754Smsmith * The following two routines (uma_zone_set_init/fini) 43567754Smsmith * are used to set the backend init/fini pair which acts on an 43667754Smsmith * object as it becomes allocated and is placed in a slab within 43767754Smsmith * the specified zone's backing keg. These should probably not 43867754Smsmith * be changed once allocations have already begun and only 43967754Smsmith * immediately upon zone creation. 44067754Smsmith */ 44167754Smsmithvoid uma_zone_set_init(uma_zone_t zone, uma_init uminit); 44267754Smsmithvoid uma_zone_set_fini(uma_zone_t zone, uma_fini fini); 44383174Smsmith 44467754Smsmith/* 44567754Smsmith * The following two routines (uma_zone_set_zinit/zfini) are 44667754Smsmith * used to set the zinit/zfini pair which acts on an object as 44767754Smsmith * it passes from the backing Keg's slab cache to the 44891116Smsmith * specified Zone's bucket cache. These should probably not 44967754Smsmith * be changed once allocations have already begun and 45067754Smsmith * only immediately upon zone creation. 45167754Smsmith */ 45267754Smsmithvoid uma_zone_set_zinit(uma_zone_t zone, uma_init zinit); 45367754Smsmithvoid uma_zone_set_zfini(uma_zone_t zone, uma_fini zfini); 45467754Smsmith 45567754Smsmith/* 45684491Smsmith * Replaces the standard page_alloc or obj_alloc functions for this zone 45784491Smsmith * 45867754Smsmith * Arguments: 45967754Smsmith * zone The zone whos back end allocator is being changed. 46091116Smsmith * allocf A pointer to the allocation function 46167754Smsmith * 46267754Smsmith * Returns: 46367754Smsmith * Nothing 46467754Smsmith * 46567754Smsmith * Discussion: 46667754Smsmith * This could be used to implement pageable allocation, or perhaps 46767754Smsmith * even DMA allocators if used in conjunction with the OFFPAGE 46867754Smsmith * zone flag. 46967754Smsmith */ 47067754Smsmith 47167754Smsmithvoid uma_zone_set_allocf(uma_zone_t zone, uma_alloc allocf); 47267754Smsmith 47367754Smsmith/* 47485756Smsmith * Used for freeing memory provided by the allocf above 47585756Smsmith * 47685756Smsmith * Arguments: 47767754Smsmith * zone The zone that intends to use this free routine. 47867754Smsmith * freef The page freeing routine. 47967754Smsmith * 48085756Smsmith * Returns: 48167754Smsmith * Nothing 48285756Smsmith */ 48367754Smsmith 48485756Smsmithvoid uma_zone_set_freef(uma_zone_t zone, uma_free freef); 48567754Smsmith 48685756Smsmith/* 48767754Smsmith * These flags are setable in the allocf and visable in the freef. 48867754Smsmith */ 48985756Smsmith#define UMA_SLAB_BOOT 0x01 /* Slab alloced from boot pages */ 49085756Smsmith#define UMA_SLAB_KMEM 0x02 /* Slab alloced from kmem_map */ 49167754Smsmith#define UMA_SLAB_KERNEL 0x04 /* Slab alloced from kernel_map */ 49267754Smsmith#define UMA_SLAB_PRIV 0x08 /* Slab alloced from priv allocator */ 49367754Smsmith#define UMA_SLAB_OFFP 0x10 /* Slab is managed separately */ 49467754Smsmith#define UMA_SLAB_MALLOC 0x20 /* Slab is a large malloc slab */ 49567754Smsmith/* 0x40 and 0x80 are available */ 49667754Smsmith 49767754Smsmith/* 49867754Smsmith * Used to pre-fill a zone with some number of items 49967754Smsmith * 50085756Smsmith * Arguments: 50185756Smsmith * zone The zone to fill 50267754Smsmith * itemcnt The number of items to reserve 50367754Smsmith * 50467754Smsmith * Returns: 50567754Smsmith * Nothing 50667754Smsmith * 50767754Smsmith * NOTE: This is blocking and should only be done at startup 50867754Smsmith */ 50967754Smsmithvoid uma_prealloc(uma_zone_t zone, int itemcnt); 51067754Smsmith 51185756Smsmith/* 51267754Smsmith * Used to lookup the reference counter allocated for an item 51367754Smsmith * from a UMA_ZONE_REFCNT zone. For UMA_ZONE_REFCNT zones, 51467754Smsmith * reference counters are allocated for items and stored in 51585756Smsmith * the underlying slab header. 51667754Smsmith * 51791116Smsmith * Arguments: 51867754Smsmith * zone The UMA_ZONE_REFCNT zone to which the item belongs. 51967754Smsmith * item The address of the item for which we want a refcnt. 52067754Smsmith * 52167754Smsmith * Returns: 52267754Smsmith * A pointer to a u_int32_t reference counter. 52367754Smsmith */ 52467754Smsmithu_int32_t *uma_find_refcnt(uma_zone_t zone, void *item); 52567754Smsmith 52667754Smsmith/* 52767754Smsmith * Used to determine if a fixed-size zone is exhausted. 52867754Smsmith * 52985756Smsmith * Arguments: 53083174Smsmith * zone The zone to check 53167754Smsmith * 53267754Smsmith * Returns: 53367754Smsmith * Non-zero if zone is exhausted. 53467754Smsmith */ 53585756Smsmithint uma_zone_exhausted(uma_zone_t zone); 53667754Smsmithint uma_zone_exhausted_nolock(uma_zone_t zone); 53767754Smsmith 53867754Smsmith/* 53967754Smsmith * Exported statistics structures to be used by user space monitoring tools. 54069450Smsmith * Statistics stream consusts of a uma_stream_header, followed by a series of 54167754Smsmith * alternative uma_type_header and uma_type_stat structures. Statistics 54267754Smsmith * structures 54367754Smsmith */ 54491116Smsmith#define UMA_STREAM_VERSION 0x00000001 54591116Smsmithstruct uma_stream_header { 54667754Smsmith u_int32_t ush_version; /* Stream format version. */ 54767754Smsmith u_int32_t ush_maxcpus; /* Value of MAXCPU for stream. */ 54891116Smsmith u_int32_t ush_count; /* Number of records. */ 54983174Smsmith u_int32_t _ush_pad; /* Pad/reserved field. */ 55083174Smsmith}; 55167754Smsmith 55285756Smsmith#define UTH_MAX_NAME 32 55385756Smsmith#define UTH_ZONE_SECONDARY 0x00000001 55467754Smsmithstruct uma_type_header { 55591116Smsmith /* 55691116Smsmith * Static per-zone data, some extracted from the supporting keg. 55767754Smsmith */ 55891116Smsmith char uth_name[UTH_MAX_NAME]; 55967754Smsmith u_int32_t uth_align; /* Keg: alignment. */ 56091116Smsmith u_int32_t uth_size; /* Keg: requested size of item. */ 56167754Smsmith u_int32_t uth_rsize; /* Keg: real size of item. */ 56291116Smsmith u_int32_t uth_maxpages; /* Keg: maximum number of pages. */ 56391116Smsmith u_int32_t uth_limit; /* Keg: max items to allocate. */ 56491116Smsmith 56591116Smsmith /* 56685756Smsmith * Current dynamic zone/keg-derived statistics. 56767754Smsmith */ 56891116Smsmith u_int32_t uth_pages; /* Keg: pages allocated. */ 56967754Smsmith u_int32_t uth_keg_free; /* Keg: items free. */ 57085756Smsmith u_int32_t uth_zone_free; /* Zone: items free. */ 57167754Smsmith u_int32_t uth_bucketsize; /* Zone: desired bucket size. */ 57291116Smsmith u_int32_t uth_zone_flags; /* Zone: flags. */ 57391116Smsmith u_int64_t uth_allocs; /* Zone: number of allocations. */ 57467754Smsmith u_int64_t uth_frees; /* Zone: number of frees. */ 57567754Smsmith u_int64_t uth_fails; /* Zone: number of alloc failures. */ 57691116Smsmith u_int64_t _uth_reserved1[3]; /* Reserved. */ 57767754Smsmith}; 57867754Smsmith 57967754Smsmithstruct uma_percpu_stat { 58067754Smsmith u_int64_t ups_allocs; /* Cache: number of alloctions. */ 58167754Smsmith u_int64_t ups_frees; /* Cache: number of frees. */ 58267754Smsmith u_int64_t ups_cache_free; /* Cache: free items in cache. */ 58367754Smsmith u_int64_t _ups_reserved[5]; /* Reserved. */ 58467754Smsmith}; 58583174Smsmith 58667754Smsmith#endif 58783174Smsmith