uma.h revision 148072
1139825Simp/*-
2141991Sbmilekic * Copyright (c) 2004, 2005,
3141991Sbmilekic *     Bosko Milekic <bmilekic@FreeBSD.org>.  All rights reserved.
4139318Sbmilekic * Copyright (c) 2002, 2003, 2004, 2005,
5141991Sbmilekic *     Jeffrey Roberson <jeff@FreeBSD.org>.  All rights reserved.
692654Sjeff *
792654Sjeff * Redistribution and use in source and binary forms, with or without
892654Sjeff * modification, are permitted provided that the following conditions
992654Sjeff * are met:
1092654Sjeff * 1. Redistributions of source code must retain the above copyright
1192654Sjeff *    notice unmodified, this list of conditions, and the following
1292654Sjeff *    disclaimer.
1392654Sjeff * 2. Redistributions in binary form must reproduce the above copyright
1492654Sjeff *    notice, this list of conditions and the following disclaimer in the
1592654Sjeff *    documentation and/or other materials provided with the distribution.
1692654Sjeff *
1792654Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1892654Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1992654Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2092654Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2192654Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2292654Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2392654Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2492654Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2592654Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2692654Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2792654Sjeff *
2892654Sjeff * $FreeBSD: head/sys/vm/uma.h 148072 2005-07-16 02:23:41Z silby $
2992654Sjeff *
3092654Sjeff */
3192654Sjeff
3292654Sjeff/*
3392654Sjeff * uma.h - External definitions for the Universal Memory Allocator
3492654Sjeff *
3592654Sjeff*/
3692654Sjeff
3792654Sjeff#ifndef VM_UMA_H
3892654Sjeff#define VM_UMA_H
3992654Sjeff
4092654Sjeff#include <sys/param.h>		/* For NULL */
4192654Sjeff#include <sys/malloc.h>		/* For M_* */
4292654Sjeff
4392654Sjeff/* User visable parameters */
4492654Sjeff#define UMA_SMALLEST_UNIT       (PAGE_SIZE / 256) /* Smallest item allocated */
4592654Sjeff
4692654Sjeff/* Types and type defs */
4792654Sjeff
48129906Sbmilekicstruct uma_zone;
4992654Sjeff/* Opaque type used as a handle to the zone */
5092654Sjefftypedef struct uma_zone * uma_zone_t;
5192654Sjeff
5292654Sjeff/*
5392654Sjeff * Item constructor
5492654Sjeff *
5592654Sjeff * Arguments:
5692654Sjeff *	item  A pointer to the memory which has been allocated.
5792654Sjeff *	arg   The arg field passed to uma_zalloc_arg
5892654Sjeff *	size  The size of the allocated item
59132987Sgreen *	flags See zalloc flags
6092654Sjeff *
6192654Sjeff * Returns:
62132987Sgreen *	0      on success
63132987Sgreen *      errno  on failure
6492654Sjeff *
6592654Sjeff * Discussion:
6692654Sjeff *	The constructor is called just before the memory is returned
67105689Ssheldonh *	to the user. It may block if necessary.
6892654Sjeff */
69132987Sgreentypedef int (*uma_ctor)(void *mem, int size, void *arg, int flags);
7092654Sjeff
7192654Sjeff/*
7292654Sjeff * Item destructor
7392654Sjeff *
7492654Sjeff * Arguments:
7592654Sjeff *	item  A pointer to the memory which has been allocated.
7692654Sjeff *	size  The size of the item being destructed.
7792654Sjeff *	arg   Argument passed through uma_zfree_arg
7892654Sjeff *
7992654Sjeff * Returns:
8092654Sjeff *	Nothing
8192654Sjeff *
8292654Sjeff * Discussion:
8392654Sjeff *	The destructor may perform operations that differ from those performed
8492654Sjeff *	by the initializer, but it must leave the object in the same state.
8592654Sjeff *	This IS type stable storage.  This is called after EVERY zfree call.
8692654Sjeff */
8792654Sjefftypedef void (*uma_dtor)(void *mem, int size, void *arg);
8892654Sjeff
8992654Sjeff/*
9092654Sjeff * Item initializer
9192654Sjeff *
9292654Sjeff * Arguments:
9392654Sjeff *	item  A pointer to the memory which has been allocated.
9492654Sjeff *	size  The size of the item being initialized.
95132987Sgreen *	flags See zalloc flags
9692654Sjeff *
9792654Sjeff * Returns:
98132987Sgreen *	0      on success
99132987Sgreen *      errno  on failure
10092654Sjeff *
10192654Sjeff * Discussion:
10292654Sjeff *	The initializer is called when the memory is cached in the uma zone.
10392654Sjeff *	this should be the same state that the destructor leaves the object in.
10492654Sjeff */
105132987Sgreentypedef int (*uma_init)(void *mem, int size, int flags);
10692654Sjeff
10792654Sjeff/*
10892654Sjeff * Item discard function
10992654Sjeff *
11092654Sjeff * Arguments:
11192654Sjeff * 	item  A pointer to memory which has been 'freed' but has not left the
11292654Sjeff *	      zone's cache.
11392654Sjeff *	size  The size of the item being discarded.
11492654Sjeff *
11592654Sjeff * Returns:
11692654Sjeff *	Nothing
11792654Sjeff *
11892654Sjeff * Discussion:
11992654Sjeff *	This routine is called when memory leaves a zone and is returned to the
12092654Sjeff *	system for other uses.  It is the counter part to the init function.
12192654Sjeff */
12292654Sjefftypedef void (*uma_fini)(void *mem, int size);
12392654Sjeff
12492654Sjeff/*
12592654Sjeff * What's the difference between initializing and constructing?
12692654Sjeff *
12792654Sjeff * The item is initialized when it is cached, and this is the state that the
12892654Sjeff * object should be in when returned to the allocator. The purpose of this is
12992654Sjeff * to remove some code which would otherwise be called on each allocation by
13092654Sjeff * utilizing a known, stable state.  This differs from the constructor which
13192654Sjeff * will be called on EVERY allocation.
13292654Sjeff *
13392654Sjeff * For example, in the initializer you may want to initialize embeded locks,
13492654Sjeff * NULL list pointers, set up initial states, magic numbers, etc.  This way if
135105689Ssheldonh * the object is held in the allocator and re-used it won't be necessary to
13692654Sjeff * re-initialize it.
13792654Sjeff *
13892654Sjeff * The constructor may be used to lock a data structure, link it on to lists,
13992654Sjeff * bump reference counts or total counts of outstanding structures, etc.
14092654Sjeff *
14192654Sjeff */
14292654Sjeff
14392654Sjeff
14492654Sjeff/* Function proto types */
14592654Sjeff
14692654Sjeff/*
14792654Sjeff * Create a new uma zone
14892654Sjeff *
14992654Sjeff * Arguments:
15092654Sjeff *	name  The text name of the zone for debugging and stats, this memory
15192654Sjeff *		should not be freed until the zone has been deallocated.
15292654Sjeff *	size  The size of the object that is being created.
15392654Sjeff *	ctor  The constructor that is called when the object is allocated
15492654Sjeff *	dtor  The destructor that is called when the object is freed.
15592654Sjeff *	init  An initializer that sets up the initial state of the memory.
15692654Sjeff *	fini  A discard function that undoes initialization done by init.
15792654Sjeff *		ctor/dtor/init/fini may all be null, see notes above.
15892654Sjeff *	align A bitmask that corisponds to the requested alignment
15992654Sjeff *		eg 4 would be 0x3
16092654Sjeff *	flags A set of parameters that control the behavior of the zone
16192654Sjeff *
16292654Sjeff * Returns:
16392654Sjeff *	A pointer to a structure which is intended to be opaque to users of
16492654Sjeff *	the interface.  The value may be null if the wait flag is not set.
16592654Sjeff */
16695925Sarruma_zone_t uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
16792654Sjeff			uma_init uminit, uma_fini fini, int align,
168148072Ssilby			u_int32_t flags);
16992654Sjeff
170120223Sjeff/*
171129906Sbmilekic * Create a secondary uma zone
172129906Sbmilekic *
173129906Sbmilekic * Arguments:
174129906Sbmilekic *	name  The text name of the zone for debugging and stats, this memory
175129906Sbmilekic *		should not be freed until the zone has been deallocated.
176129906Sbmilekic *	ctor  The constructor that is called when the object is allocated
177129906Sbmilekic *	dtor  The destructor that is called when the object is freed.
178129906Sbmilekic *	zinit  An initializer that sets up the initial state of the memory
179129906Sbmilekic *		as the object passes from the Keg's slab to the Zone's cache.
180129906Sbmilekic *	zfini  A discard function that undoes initialization done by init
181129906Sbmilekic *		as the object passes from the Zone's cache to the Keg's slab.
182129906Sbmilekic *
183129906Sbmilekic *		ctor/dtor/zinit/zfini may all be null, see notes above.
184129906Sbmilekic *		Note that the zinit and zfini specified here are NOT
185129906Sbmilekic *		exactly the same as the init/fini specified to uma_zcreate()
186129906Sbmilekic *		when creating a master zone.  These zinit/zfini are called
187129906Sbmilekic *		on the TRANSITION from keg to zone (and vice-versa). Once
188129906Sbmilekic *		these are set, the primary zone may alter its init/fini
189129906Sbmilekic *		(which are called when the object passes from VM to keg)
190129906Sbmilekic *		using uma_zone_set_init/fini()) as well as its own
191129906Sbmilekic *		zinit/zfini (unset by default for master zone) with
192129906Sbmilekic *		uma_zone_set_zinit/zfini() (note subtle 'z' prefix).
193129906Sbmilekic *
194129913Sbmilekic *	master  A reference to this zone's Master Zone (Primary Zone),
195129913Sbmilekic *		which contains the backing Keg for the Secondary Zone
196129913Sbmilekic *		being added.
197129906Sbmilekic *
198129906Sbmilekic * Returns:
199129906Sbmilekic *	A pointer to a structure which is intended to be opaque to users of
200129906Sbmilekic *	the interface.  The value may be null if the wait flag is not set.
201129906Sbmilekic */
202129906Sbmilekicuma_zone_t uma_zsecond_create(char *name, uma_ctor ctor, uma_dtor dtor,
203129906Sbmilekic		    uma_init zinit, uma_fini zfini, uma_zone_t master);
204129906Sbmilekic
205129906Sbmilekic/*
206120223Sjeff * Definitions for uma_zcreate flags
207120223Sjeff *
208120223Sjeff * These flags share space with UMA_ZFLAGs in uma_int.h.  Be careful not to
209148072Ssilby * overlap when adding new features.  0xf0000000 is in use by uma_int.h.
210120223Sjeff */
21192654Sjeff#define UMA_ZONE_PAGEABLE	0x0001	/* Return items not fully backed by
21292654Sjeff					   physical memory XXX Not yet */
21392654Sjeff#define UMA_ZONE_ZINIT		0x0002	/* Initialize with zeros */
21492654Sjeff#define UMA_ZONE_STATIC		0x0004	/* Staticly sized zone */
21592654Sjeff#define UMA_ZONE_OFFPAGE	0x0008	/* Force the slab structure allocation
21692654Sjeff					   off of the real memory */
21792654Sjeff#define UMA_ZONE_MALLOC		0x0010	/* For use by malloc(9) only! */
21892654Sjeff#define UMA_ZONE_NOFREE		0x0020	/* Do not free slabs of this type! */
21995758Sjeff#define UMA_ZONE_MTXCLASS	0x0040	/* Create a new lock class */
220103531Sjeff#define	UMA_ZONE_VM		0x0080	/*
221103531Sjeff					 * Used for internal vm datastructures
222103531Sjeff					 * only.
223103531Sjeff					 */
224103531Sjeff#define	UMA_ZONE_HASH		0x0100	/*
225103531Sjeff					 * Use a hash table instead of caching
226103531Sjeff					 * information in the vm_page.
227103531Sjeff					 */
228129906Sbmilekic#define	UMA_ZONE_SECONDARY	0x0200	/* Zone is a Secondary Zone */
229129906Sbmilekic#define	UMA_ZONE_REFCNT		0x0400	/* Allocate refcnts in slabs */
230129906Sbmilekic#define	UMA_ZONE_MAXBUCKET	0x0800	/* Use largest buckets */
23192654Sjeff
23292654Sjeff/* Definitions for align */
23392654Sjeff#define UMA_ALIGN_PTR	(sizeof(void *) - 1)	/* Alignment fit for ptr */
23492654Sjeff#define UMA_ALIGN_LONG	(sizeof(long) - 1)	/* "" long */
23592654Sjeff#define UMA_ALIGN_INT	(sizeof(int) - 1)	/* "" int */
23692654Sjeff#define UMA_ALIGN_SHORT	(sizeof(short) - 1)	/* "" short */
23792654Sjeff#define UMA_ALIGN_CHAR	(sizeof(char) - 1)	/* "" char */
23892654Sjeff#define UMA_ALIGN_CACHE	(16 - 1)		/* Cache line size align */
23992654Sjeff
24092654Sjeff/*
24194161Sjeff * Destroys an empty uma zone.  If the zone is not empty uma complains loudly.
24292654Sjeff *
24392654Sjeff * Arguments:
24492654Sjeff *	zone  The zone we want to destroy.
24592654Sjeff *
24692654Sjeff */
24794161Sjeffvoid uma_zdestroy(uma_zone_t zone);
24892654Sjeff
24992654Sjeff/*
25092654Sjeff * Allocates an item out of a zone
25192654Sjeff *
25292654Sjeff * Arguments:
25392654Sjeff *	zone  The zone we are allocating from
25492654Sjeff *	arg   This data is passed to the ctor function
25595766Sjeff *	flags See sys/malloc.h for available flags.
25692654Sjeff *
25792654Sjeff * Returns:
25892654Sjeff *	A non null pointer to an initialized element from the zone is
259111119Simp *	garanteed if the wait flag is M_WAITOK, otherwise a null pointer may be
26092654Sjeff *	returned if the zone is empty or the ctor failed.
26192654Sjeff */
26292654Sjeff
26395766Sjeffvoid *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags);
26492654Sjeff
26592654Sjeff/*
26692654Sjeff * Allocates an item out of a zone without supplying an argument
26792654Sjeff *
26892654Sjeff * This is just a wrapper for uma_zalloc_arg for convenience.
26992654Sjeff *
27092654Sjeff */
27195766Sjeffstatic __inline void *uma_zalloc(uma_zone_t zone, int flags);
27292654Sjeff
27392654Sjeffstatic __inline void *
27495766Sjeffuma_zalloc(uma_zone_t zone, int flags)
27592654Sjeff{
27695766Sjeff	return uma_zalloc_arg(zone, NULL, flags);
27792654Sjeff}
27892654Sjeff
27992654Sjeff/*
28092654Sjeff * Frees an item back into the specified zone.
28192654Sjeff *
28292654Sjeff * Arguments:
28392654Sjeff *	zone  The zone the item was originally allocated out of.
28492654Sjeff *	item  The memory to be freed.
28592654Sjeff *	arg   Argument passed to the destructor
28692654Sjeff *
28792654Sjeff * Returns:
28892654Sjeff *	Nothing.
28992654Sjeff */
29092654Sjeff
29192654Sjeffvoid uma_zfree_arg(uma_zone_t zone, void *item, void *arg);
29292654Sjeff
29392654Sjeff/*
29492654Sjeff * Frees an item back to a zone without supplying an argument
29592654Sjeff *
29692654Sjeff * This is just a wrapper for uma_zfree_arg for convenience.
29792654Sjeff *
29892654Sjeff */
29992654Sjeffstatic __inline void uma_zfree(uma_zone_t zone, void *item);
30092654Sjeff
30192654Sjeffstatic __inline void
30292654Sjeffuma_zfree(uma_zone_t zone, void *item)
30392654Sjeff{
304100326Smarkm	uma_zfree_arg(zone, item, NULL);
30592654Sjeff}
30692654Sjeff
30792654Sjeff/*
30892654Sjeff * XXX The rest of the prototypes in this header are h0h0 magic for the VM.
30992654Sjeff * If you think you need to use it for a normal zone you're probably incorrect.
31092654Sjeff */
31192654Sjeff
31292654Sjeff/*
31392654Sjeff * Backend page supplier routines
31492654Sjeff *
31592654Sjeff * Arguments:
31692654Sjeff *	zone  The zone that is requesting pages
31792654Sjeff *	size  The number of bytes being requested
31892654Sjeff *	pflag Flags for these memory pages, see below.
31992654Sjeff *	wait  Indicates our willingness to block.
32092654Sjeff *
32192654Sjeff * Returns:
32292654Sjeff *	A pointer to the alloced memory or NULL on failure.
32392654Sjeff */
32492654Sjeff
32592654Sjefftypedef void *(*uma_alloc)(uma_zone_t zone, int size, u_int8_t *pflag, int wait);
32692654Sjeff
32792654Sjeff/*
32892654Sjeff * Backend page free routines
32992654Sjeff *
33092654Sjeff * Arguments:
33192654Sjeff *	item  A pointer to the previously allocated pages
33292654Sjeff *	size  The original size of the allocation
33392654Sjeff *	pflag The flags for the slab.  See UMA_SLAB_* below
33492654Sjeff *
33592654Sjeff * Returns:
33692654Sjeff *	None
33792654Sjeff */
33892654Sjefftypedef void (*uma_free)(void *item, int size, u_int8_t pflag);
33992654Sjeff
34092654Sjeff
34192654Sjeff
34292654Sjeff/*
34392654Sjeff * Sets up the uma allocator. (Called by vm_mem_init)
34492654Sjeff *
34592654Sjeff * Arguments:
34692654Sjeff *	bootmem  A pointer to memory used to bootstrap the system.
34792654Sjeff *
34892654Sjeff * Returns:
34992654Sjeff *	Nothing
35092654Sjeff *
35192654Sjeff * Discussion:
35292654Sjeff *	This memory is used for zones which allocate things before the
35392654Sjeff *	backend page supplier can give us pages.  It should be
35492654Sjeff *	UMA_SLAB_SIZE * UMA_BOOT_PAGES bytes. (see uma_int.h)
35592654Sjeff *
35692654Sjeff */
35792654Sjeff
35892654Sjeffvoid uma_startup(void *bootmem);
35992654Sjeff
36092654Sjeff/*
36192654Sjeff * Finishes starting up the allocator.  This should
36292654Sjeff * be called when kva is ready for normal allocs.
36392654Sjeff *
36492654Sjeff * Arguments:
365103531Sjeff *	None
36692654Sjeff *
36792654Sjeff * Returns:
36892654Sjeff *	Nothing
36992654Sjeff *
37092654Sjeff * Discussion:
371103531Sjeff *	uma_startup2 is called by kmeminit() to enable us of uma for malloc.
37292654Sjeff */
37392654Sjeff
374103531Sjeffvoid uma_startup2(void);
37592654Sjeff
37692654Sjeff/*
37792654Sjeff * Reclaims unused memory for all zones
37892654Sjeff *
37992654Sjeff * Arguments:
38092654Sjeff *	None
38192654Sjeff * Returns:
38292654Sjeff *	None
38392654Sjeff *
38492654Sjeff * This should only be called by the page out daemon.
38592654Sjeff */
38692654Sjeff
38792654Sjeffvoid uma_reclaim(void);
38892654Sjeff
38992654Sjeff/*
39092654Sjeff * Switches the backing object of a zone
39192654Sjeff *
39292654Sjeff * Arguments:
39392654Sjeff *	zone  The zone to update
39492654Sjeff *	obj   The obj to use for future allocations
39592654Sjeff *	size  The size of the object to allocate
39692654Sjeff *
39792654Sjeff * Returns:
39892654Sjeff *	0  if kva space can not be allocated
39992654Sjeff *	1  if successful
40092654Sjeff *
40192654Sjeff * Discussion:
40292654Sjeff *	A NULL object can be used and uma will allocate one for you.  Setting
40392654Sjeff *	the size will limit the amount of memory allocated to this zone.
40492654Sjeff *
40592654Sjeff */
40692654Sjeffstruct vm_object;
40792654Sjeffint uma_zone_set_obj(uma_zone_t zone, struct vm_object *obj, int size);
40892654Sjeff
40992758Sjeff/*
41092758Sjeff * Sets a high limit on the number of items allowed in a zone
41192758Sjeff *
41292758Sjeff * Arguments:
41392758Sjeff *	zone  The zone to limit
41492758Sjeff *
41592758Sjeff * Returns:
41692758Sjeff *	Nothing
41792758Sjeff */
41892758Sjeffvoid uma_zone_set_max(uma_zone_t zone, int nitems);
41992654Sjeff
42092654Sjeff/*
421129906Sbmilekic * The following two routines (uma_zone_set_init/fini)
422129906Sbmilekic * are used to set the backend init/fini pair which acts on an
423129906Sbmilekic * object as it becomes allocated and is placed in a slab within
424129906Sbmilekic * the specified zone's backing keg.  These should probably not
425129906Sbmilekic * be changed once allocations have already begun and only
426129906Sbmilekic * immediately upon zone creation.
427129906Sbmilekic */
428129906Sbmilekicvoid uma_zone_set_init(uma_zone_t zone, uma_init uminit);
429129906Sbmilekicvoid uma_zone_set_fini(uma_zone_t zone, uma_fini fini);
430129906Sbmilekic
431129906Sbmilekic/*
432129906Sbmilekic * The following two routines (uma_zone_set_zinit/zfini) are
433129906Sbmilekic * used to set the zinit/zfini pair which acts on an object as
434129906Sbmilekic * it passes from the backing Keg's slab cache to the
435129906Sbmilekic * specified Zone's bucket cache.  These should probably not
436129906Sbmilekic * be changed once allocations have already begun and
437129906Sbmilekic * only immediately upon zone creation.
438129906Sbmilekic */
439129906Sbmilekicvoid uma_zone_set_zinit(uma_zone_t zone, uma_init zinit);
440129906Sbmilekicvoid uma_zone_set_zfini(uma_zone_t zone, uma_fini zfini);
441129906Sbmilekic
442129906Sbmilekic/*
44392654Sjeff * Replaces the standard page_alloc or obj_alloc functions for this zone
44492654Sjeff *
44592654Sjeff * Arguments:
44692654Sjeff *	zone   The zone whos back end allocator is being changed.
44792654Sjeff *	allocf A pointer to the allocation function
44892654Sjeff *
44992654Sjeff * Returns:
45092654Sjeff *	Nothing
45192654Sjeff *
45292654Sjeff * Discussion:
45392654Sjeff *	This could be used to implement pageable allocation, or perhaps
45492654Sjeff *	even DMA allocators if used in conjunction with the OFFPAGE
45592654Sjeff *	zone flag.
45692654Sjeff */
45792654Sjeff
45892654Sjeffvoid uma_zone_set_allocf(uma_zone_t zone, uma_alloc allocf);
45992654Sjeff
46092654Sjeff/*
46192654Sjeff * Used for freeing memory provided by the allocf above
46292654Sjeff *
46392654Sjeff * Arguments:
46492654Sjeff *	zone  The zone that intends to use this free routine.
46592654Sjeff *	freef The page freeing routine.
46692654Sjeff *
46792654Sjeff * Returns:
46892654Sjeff *	Nothing
46992654Sjeff */
47092654Sjeff
47192654Sjeffvoid uma_zone_set_freef(uma_zone_t zone, uma_free freef);
47292654Sjeff
47392654Sjeff/*
47492654Sjeff * These flags are setable in the allocf and visable in the freef.
47592654Sjeff */
47692654Sjeff#define UMA_SLAB_BOOT	0x01		/* Slab alloced from boot pages */
47792654Sjeff#define UMA_SLAB_KMEM	0x02		/* Slab alloced from kmem_map */
47892654Sjeff#define UMA_SLAB_PRIV	0x08		/* Slab alloced from priv allocator */
47994157Sjeff#define UMA_SLAB_OFFP	0x10		/* Slab is managed separately  */
48092654Sjeff#define UMA_SLAB_MALLOC	0x20		/* Slab is a large malloc slab */
48192654Sjeff/* 0x40 and 0x80 are available */
48292654Sjeff
48392654Sjeff/*
48492654Sjeff * Used to pre-fill a zone with some number of items
48592654Sjeff *
48692654Sjeff * Arguments:
48792654Sjeff *	zone    The zone to fill
48892654Sjeff *	itemcnt The number of items to reserve
48992654Sjeff *
49092654Sjeff * Returns:
49192654Sjeff *	Nothing
49292654Sjeff *
49392654Sjeff * NOTE: This is blocking and should only be done at startup
49492654Sjeff */
49592654Sjeffvoid uma_prealloc(uma_zone_t zone, int itemcnt);
49692654Sjeff
497129906Sbmilekic/*
498129906Sbmilekic * Used to lookup the reference counter allocated for an item
499129906Sbmilekic * from a UMA_ZONE_REFCNT zone.  For UMA_ZONE_REFCNT zones,
500129906Sbmilekic * reference counters are allocated for items and stored in
501129906Sbmilekic * the underlying slab header.
502129906Sbmilekic *
503129906Sbmilekic * Arguments:
504129906Sbmilekic * 	zone  The UMA_ZONE_REFCNT zone to which the item belongs.
505129906Sbmilekic *	item  The address of the item for which we want a refcnt.
506129906Sbmilekic *
507129906Sbmilekic * Returns:
508129906Sbmilekic * 	A pointer to a u_int32_t reference counter.
509129906Sbmilekic */
510129906Sbmilekicu_int32_t *uma_find_refcnt(uma_zone_t zone, void *item);
51192654Sjeff
512147996Srwatson/*
513147996Srwatson * Exported statistics structures to be used by user space monitoring tools.
514147996Srwatson * Statistics stream consusts of a uma_stream_header, followed by a series of
515147996Srwatson * alternative uma_type_header and uma_type_stat structures.  Statistics
516147996Srwatson * structures
517147996Srwatson */
518147996Srwatson#define	UMA_STREAM_VERSION	0x00000001
519147996Srwatsonstruct uma_stream_header {
520147996Srwatson	u_int32_t	ush_version;	/* Stream format version. */
521147996Srwatson	u_int32_t	ush_maxcpus;	/* Value of MAXCPU for stream. */
522147996Srwatson	u_int32_t	ush_count;	/* Number of records. */
523147996Srwatson	u_int32_t	_ush_pad;	/* Pad/reserved field. */
524147996Srwatson};
525147996Srwatson
526147996Srwatson#define	UMA_MAX_NAME	32
527147996Srwatsonstruct uma_type_header {
528147996Srwatson	/*
529147996Srwatson	 * Static per-zone data, some extracted from the supporting keg.
530147996Srwatson	 */
531147996Srwatson	char		uth_name[UMA_MAX_NAME];
532147996Srwatson	u_int32_t	uth_align;	/* Keg: alignment. */
533147996Srwatson	u_int32_t	uth_size;	/* Keg: requested size of item. */
534147996Srwatson	u_int32_t	uth_rsize;	/* Keg: real size of item. */
535147996Srwatson	u_int32_t	uth_maxpages;	/* Keg: maximum number of pages. */
536147996Srwatson	u_int32_t	uth_limit;	/* Keg: max items to allocate. */
537147996Srwatson
538147996Srwatson	/*
539147996Srwatson	 * Current dynamic zone/keg-derived statistics.
540147996Srwatson	 */
541147996Srwatson	u_int32_t	uth_pages;	/* Keg: pages allocated. */
542147996Srwatson	u_int32_t	uth_keg_free;	/* Keg: items free. */
543147996Srwatson	u_int32_t	uth_zone_free;	/* Zone: items free. */
544147996Srwatson	u_int32_t	uth_bucketsize;	/* Zone: desired bucket size. */
545147996Srwatson	u_int32_t	_uth_reserved0;	/* Reserved. */
546147996Srwatson	u_int64_t	uth_allocs;	/* Zone: number of allocations. */
547147996Srwatson	u_int64_t	uth_frees;	/* Zone: number of frees. */
548148070Srwatson	u_int64_t	uth_fails;	/* Zone: number of alloc failures. */
549148070Srwatson	u_int64_t	_uth_reserved1[3];	/* Reserved. */
550147996Srwatson
551147996Srwatson};
552147996Srwatson
553147996Srwatsonstruct uma_percpu_stat {
554147996Srwatson	u_int64_t	ups_allocs;	/* Cache: number of alloctions. */
555147996Srwatson	u_int64_t	ups_frees;	/* Cache: number of frees. */
556147996Srwatson	u_int64_t	ups_cache_free;	/* Cache: free items in cache. */
557147996Srwatson	u_int64_t	_ups_reserved[5];	/* Reserved. */
558147996Srwatson};
559147996Srwatson
56092654Sjeff#endif
561