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