xref: /freebsd/sys/vm/uma.h (revision dc8f7692fd1de628814f4eaf4a233dccf4c92199)
160727d8bSWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni  *
408ecce74SRobert Watson  * Copyright (c) 2002, 2003, 2004, 2005 Jeffrey Roberson <jeff@FreeBSD.org>
508ecce74SRobert Watson  * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org>
608ecce74SRobert Watson  * All rights reserved.
78355f576SJeff Roberson  *
88355f576SJeff Roberson  * Redistribution and use in source and binary forms, with or without
98355f576SJeff Roberson  * modification, are permitted provided that the following conditions
108355f576SJeff Roberson  * are met:
118355f576SJeff Roberson  * 1. Redistributions of source code must retain the above copyright
128355f576SJeff Roberson  *    notice unmodified, this list of conditions, and the following
138355f576SJeff Roberson  *    disclaimer.
148355f576SJeff Roberson  * 2. Redistributions in binary form must reproduce the above copyright
158355f576SJeff Roberson  *    notice, this list of conditions and the following disclaimer in the
168355f576SJeff Roberson  *    documentation and/or other materials provided with the distribution.
178355f576SJeff Roberson  *
188355f576SJeff Roberson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198355f576SJeff Roberson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208355f576SJeff Roberson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218355f576SJeff Roberson  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228355f576SJeff Roberson  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238355f576SJeff Roberson  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248355f576SJeff Roberson  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258355f576SJeff Roberson  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268355f576SJeff Roberson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278355f576SJeff Roberson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288355f576SJeff Roberson  *
298355f576SJeff Roberson  */
308355f576SJeff Roberson 
318355f576SJeff Roberson /*
328355f576SJeff Roberson  * uma.h - External definitions for the Universal Memory Allocator
338355f576SJeff Roberson  *
348355f576SJeff Roberson */
358355f576SJeff Roberson 
36f947570eSGleb Smirnoff #ifndef _VM_UMA_H_
37f947570eSGleb Smirnoff #define _VM_UMA_H_
388355f576SJeff Roberson 
398355f576SJeff Roberson #include <sys/param.h>		/* For NULL */
408355f576SJeff Roberson #include <sys/malloc.h>		/* For M_* */
41d4665eaaSJeff Roberson #include <sys/_smr.h>
428355f576SJeff Roberson 
432db63c5eSGiorgos Keramidas /* User visible parameters */
449b8db4d0SRyan Libby #define	UMA_SMALLEST_UNIT	8 /* Smallest item allocated */
458355f576SJeff Roberson 
468355f576SJeff Roberson /* Types and type defs */
478355f576SJeff Roberson 
488355f576SJeff Roberson struct uma_zone;
498355f576SJeff Roberson /* Opaque type used as a handle to the zone */
508355f576SJeff Roberson typedef struct uma_zone * uma_zone_t;
518355f576SJeff Roberson 
528355f576SJeff Roberson /*
538355f576SJeff Roberson  * Item constructor
548355f576SJeff Roberson  *
558355f576SJeff Roberson  * Arguments:
568355f576SJeff Roberson  *	item  A pointer to the memory which has been allocated.
578355f576SJeff Roberson  *	arg   The arg field passed to uma_zalloc_arg
588355f576SJeff Roberson  *	size  The size of the allocated item
59b23f72e9SBrian Feldman  *	flags See zalloc flags
608355f576SJeff Roberson  *
618355f576SJeff Roberson  * Returns:
62b23f72e9SBrian Feldman  *	0      on success
63b23f72e9SBrian Feldman  *      errno  on failure
648355f576SJeff Roberson  *
658355f576SJeff Roberson  * Discussion:
668355f576SJeff Roberson  *	The constructor is called just before the memory is returned
6729b4d526SSheldon Hearn  *	to the user. It may block if necessary.
688355f576SJeff Roberson  */
69b23f72e9SBrian Feldman typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags);
708355f576SJeff Roberson 
718355f576SJeff Roberson /*
728355f576SJeff Roberson  * Item destructor
738355f576SJeff Roberson  *
748355f576SJeff Roberson  * Arguments:
758355f576SJeff Roberson  *	item  A pointer to the memory which has been allocated.
768355f576SJeff Roberson  *	size  The size of the item being destructed.
778355f576SJeff Roberson  *	arg   Argument passed through uma_zfree_arg
788355f576SJeff Roberson  *
798355f576SJeff Roberson  * Returns:
808355f576SJeff Roberson  *	Nothing
818355f576SJeff Roberson  *
828355f576SJeff Roberson  * Discussion:
838355f576SJeff Roberson  *	The destructor may perform operations that differ from those performed
848355f576SJeff Roberson  *	by the initializer, but it must leave the object in the same state.
858355f576SJeff Roberson  *	This IS type stable storage.  This is called after EVERY zfree call.
868355f576SJeff Roberson  */
878355f576SJeff Roberson typedef void (*uma_dtor)(void *mem, int size, void *arg);
888355f576SJeff Roberson 
898355f576SJeff Roberson /*
908355f576SJeff Roberson  * Item initializer
918355f576SJeff Roberson  *
928355f576SJeff Roberson  * Arguments:
938355f576SJeff Roberson  *	item  A pointer to the memory which has been allocated.
948355f576SJeff Roberson  *	size  The size of the item being initialized.
95b23f72e9SBrian Feldman  *	flags See zalloc flags
968355f576SJeff Roberson  *
978355f576SJeff Roberson  * Returns:
98b23f72e9SBrian Feldman  *	0      on success
99b23f72e9SBrian Feldman  *      errno  on failure
1008355f576SJeff Roberson  *
1018355f576SJeff Roberson  * Discussion:
1028355f576SJeff Roberson  *	The initializer is called when the memory is cached in the uma zone.
1032db63c5eSGiorgos Keramidas  *	The initializer and the destructor should leave the object in the same
1042db63c5eSGiorgos Keramidas  *	state.
1058355f576SJeff Roberson  */
106b23f72e9SBrian Feldman typedef int (*uma_init)(void *mem, int size, int flags);
1078355f576SJeff Roberson 
1088355f576SJeff Roberson /*
1098355f576SJeff Roberson  * Item discard function
1108355f576SJeff Roberson  *
1118355f576SJeff Roberson  * Arguments:
1128355f576SJeff Roberson  *	item  A pointer to memory which has been 'freed' but has not left the
1138355f576SJeff Roberson  *	      zone's cache.
1148355f576SJeff Roberson  *	size  The size of the item being discarded.
1158355f576SJeff Roberson  *
1168355f576SJeff Roberson  * Returns:
1178355f576SJeff Roberson  *	Nothing
1188355f576SJeff Roberson  *
1198355f576SJeff Roberson  * Discussion:
1208355f576SJeff Roberson  *	This routine is called when memory leaves a zone and is returned to the
1212db63c5eSGiorgos Keramidas  *	system for other uses.  It is the counter-part to the init function.
1228355f576SJeff Roberson  */
1238355f576SJeff Roberson typedef void (*uma_fini)(void *mem, int size);
1248355f576SJeff Roberson 
1258355f576SJeff Roberson /*
1260095a784SJeff Roberson  * Import new memory into a cache zone.
1270095a784SJeff Roberson  */
128ab3185d1SJeff Roberson typedef int (*uma_import)(void *arg, void **store, int count, int domain,
129ab3185d1SJeff Roberson     int flags);
1300095a784SJeff Roberson 
1310095a784SJeff Roberson /*
1320095a784SJeff Roberson  * Free memory from a cache zone.
1330095a784SJeff Roberson  */
1340095a784SJeff Roberson typedef void (*uma_release)(void *arg, void **store, int count);
1350095a784SJeff Roberson 
1360095a784SJeff Roberson /*
1378355f576SJeff Roberson  * What's the difference between initializing and constructing?
1388355f576SJeff Roberson  *
1398355f576SJeff Roberson  * The item is initialized when it is cached, and this is the state that the
1408355f576SJeff Roberson  * object should be in when returned to the allocator. The purpose of this is
1418355f576SJeff Roberson  * to remove some code which would otherwise be called on each allocation by
1428355f576SJeff Roberson  * utilizing a known, stable state.  This differs from the constructor which
1438355f576SJeff Roberson  * will be called on EVERY allocation.
1448355f576SJeff Roberson  *
1452db63c5eSGiorgos Keramidas  * For example, in the initializer you may want to initialize embedded locks,
1468355f576SJeff Roberson  * NULL list pointers, set up initial states, magic numbers, etc.  This way if
14729b4d526SSheldon Hearn  * the object is held in the allocator and re-used it won't be necessary to
1488355f576SJeff Roberson  * re-initialize it.
1498355f576SJeff Roberson  *
1508355f576SJeff Roberson  * The constructor may be used to lock a data structure, link it on to lists,
1518355f576SJeff Roberson  * bump reference counts or total counts of outstanding structures, etc.
1528355f576SJeff Roberson  *
1538355f576SJeff Roberson  */
1548355f576SJeff Roberson 
1558355f576SJeff Roberson /* Function proto types */
1568355f576SJeff Roberson 
1578355f576SJeff Roberson /*
1588355f576SJeff Roberson  * Create a new uma zone
1598355f576SJeff Roberson  *
1608355f576SJeff Roberson  * Arguments:
1612db63c5eSGiorgos Keramidas  *	name  The text name of the zone for debugging and stats. This memory
1628355f576SJeff Roberson  *		should not be freed until the zone has been deallocated.
1638355f576SJeff Roberson  *	size  The size of the object that is being created.
1642db63c5eSGiorgos Keramidas  *	ctor  The constructor that is called when the object is allocated.
1658355f576SJeff Roberson  *	dtor  The destructor that is called when the object is freed.
1668355f576SJeff Roberson  *	init  An initializer that sets up the initial state of the memory.
1678355f576SJeff Roberson  *	fini  A discard function that undoes initialization done by init.
1688355f576SJeff Roberson  *		ctor/dtor/init/fini may all be null, see notes above.
1692db63c5eSGiorgos Keramidas  *	align A bitmask that corresponds to the requested alignment
1708355f576SJeff Roberson  *		eg 4 would be 0x3
1712db63c5eSGiorgos Keramidas  *	flags A set of parameters that control the behavior of the zone.
1728355f576SJeff Roberson  *
1738355f576SJeff Roberson  * Returns:
1748355f576SJeff Roberson  *	A pointer to a structure which is intended to be opaque to users of
1758355f576SJeff Roberson  *	the interface.  The value may be null if the wait flag is not set.
1768355f576SJeff Roberson  */
177bb196eb4SMatthew D Fleming uma_zone_t uma_zcreate(const char *name, size_t size, uma_ctor ctor,
178bb196eb4SMatthew D Fleming 		    uma_dtor dtor, uma_init uminit, uma_fini fini,
17985dcf349SGleb Smirnoff 		    int align, uint32_t flags);
1808355f576SJeff Roberson 
181b60f5b79SJeff Roberson /*
182099a0e58SBosko Milekic  * Create a secondary uma zone
183099a0e58SBosko Milekic  *
184099a0e58SBosko Milekic  * Arguments:
1852db63c5eSGiorgos Keramidas  *	name  The text name of the zone for debugging and stats. This memory
186099a0e58SBosko Milekic  *		should not be freed until the zone has been deallocated.
1872db63c5eSGiorgos Keramidas  *	ctor  The constructor that is called when the object is allocated.
188099a0e58SBosko Milekic  *	dtor  The destructor that is called when the object is freed.
189099a0e58SBosko Milekic  *	zinit  An initializer that sets up the initial state of the memory
190099a0e58SBosko Milekic  *		as the object passes from the Keg's slab to the Zone's cache.
191099a0e58SBosko Milekic  *	zfini  A discard function that undoes initialization done by init
192099a0e58SBosko Milekic  *		as the object passes from the Zone's cache to the Keg's slab.
193099a0e58SBosko Milekic  *
194099a0e58SBosko Milekic  *		ctor/dtor/zinit/zfini may all be null, see notes above.
195099a0e58SBosko Milekic  *		Note that the zinit and zfini specified here are NOT
196099a0e58SBosko Milekic  *		exactly the same as the init/fini specified to uma_zcreate()
197c8b0a88bSJeff Roberson  *		when creating a primary zone.  These zinit/zfini are called
198099a0e58SBosko Milekic  *		on the TRANSITION from keg to zone (and vice-versa). Once
199099a0e58SBosko Milekic  *		these are set, the primary zone may alter its init/fini
200099a0e58SBosko Milekic  *		(which are called when the object passes from VM to keg)
201099a0e58SBosko Milekic  *		using uma_zone_set_init/fini()) as well as its own
202c8b0a88bSJeff Roberson  *		zinit/zfini (unset by default for primary zone) with
203099a0e58SBosko Milekic  *		uma_zone_set_zinit/zfini() (note subtle 'z' prefix).
204099a0e58SBosko Milekic  *
205c8b0a88bSJeff Roberson  *	primary A reference to this zone's Primary Zone which contains the
206c8b0a88bSJeff Roberson  *		backing Keg for the Secondary Zone being added.
207099a0e58SBosko Milekic  *
208099a0e58SBosko Milekic  * Returns:
209099a0e58SBosko Milekic  *	A pointer to a structure which is intended to be opaque to users of
210099a0e58SBosko Milekic  *	the interface.  The value may be null if the wait flag is not set.
211099a0e58SBosko Milekic  */
2120464f16eSMark Johnston uma_zone_t uma_zsecond_create(const char *name, uma_ctor ctor, uma_dtor dtor,
213c8b0a88bSJeff Roberson     uma_init zinit, uma_fini zfini, uma_zone_t primary);
214099a0e58SBosko Milekic 
215099a0e58SBosko Milekic /*
2160095a784SJeff Roberson  * Create cache-only zones.
2170095a784SJeff Roberson  *
2180095a784SJeff Roberson  * This allows uma's per-cpu cache facilities to handle arbitrary
2190095a784SJeff Roberson  * pointers.  Consumers must specify the import and release functions to
2200095a784SJeff Roberson  * fill and destroy caches.  UMA does not allocate any memory for these
2210095a784SJeff Roberson  * zones.  The 'arg' parameter is passed to import/release and is caller
2220095a784SJeff Roberson  * specific.
2230095a784SJeff Roberson  */
2240464f16eSMark Johnston uma_zone_t uma_zcache_create(const char *name, int size, uma_ctor ctor,
2250464f16eSMark Johnston     uma_dtor dtor, uma_init zinit, uma_fini zfini, uma_import zimport,
2260095a784SJeff Roberson     uma_release zrelease, void *arg, int flags);
2270095a784SJeff Roberson 
2280095a784SJeff Roberson /*
229b60f5b79SJeff Roberson  * Definitions for uma_zcreate flags
230b60f5b79SJeff Roberson  *
231b60f5b79SJeff Roberson  * These flags share space with UMA_ZFLAGs in uma_int.h.  Be careful not to
23254c5ae80SRyan Libby  * overlap when adding new features.
233b60f5b79SJeff Roberson  */
234389a3fa6SMark Johnston #define	UMA_ZONE_UNMANAGED	0x0001	/*
235389a3fa6SMark Johnston 					 * Don't regulate the cache size, even
236389a3fa6SMark Johnston 					 * under memory pressure.
237389a3fa6SMark Johnston 					 */
2388355f576SJeff Roberson #define UMA_ZONE_ZINIT		0x0002	/* Initialize with zeros */
239ec0d8280SRyan Libby #define UMA_ZONE_CONTIG		0x0004	/*
240ec0d8280SRyan Libby 					 * Physical memory underlying an object
241ec0d8280SRyan Libby 					 * must be contiguous.
242ec0d8280SRyan Libby 					 */
24354c5ae80SRyan Libby #define UMA_ZONE_NOTOUCH	0x0008	/* UMA may not access the memory */
2448355f576SJeff Roberson #define UMA_ZONE_MALLOC		0x0010	/* For use by malloc(9) only! */
2458355f576SJeff Roberson #define UMA_ZONE_NOFREE		0x0020	/* Do not free slabs of this type! */
24628bc4419SJeff Roberson #define UMA_ZONE_MTXCLASS	0x0040	/* Create a new lock class */
24799571dc3SJeff Roberson #define	UMA_ZONE_VM		0x0080	/*
24899571dc3SJeff Roberson 					 * Used for internal vm datastructures
24999571dc3SJeff Roberson 					 * only.
25099571dc3SJeff Roberson 					 */
25154c5ae80SRyan Libby #define	UMA_ZONE_NOTPAGE	0x0100	/* allocf memory not vm pages */
252099a0e58SBosko Milekic #define	UMA_ZONE_SECONDARY	0x0200	/* Zone is a Secondary Zone */
2537e28037aSMark Johnston #define	UMA_ZONE_NOBUCKET	0x0400	/* Do not use buckets. */
2547e28037aSMark Johnston #define	UMA_ZONE_MAXBUCKET	0x0800	/* Use largest buckets. */
25554c5ae80SRyan Libby #define	UMA_ZONE_CACHESPREAD	0x2000	/*
256e20a199fSJeff Roberson 					 * Spread memory start locations across
257e20a199fSJeff Roberson 					 * all possible cache lines.  May
258e20a199fSJeff Roberson 					 * require many virtually contiguous
259e20a199fSJeff Roberson 					 * backend pages and can fail early.
260e20a199fSJeff Roberson 					 */
261263811f7SKip Macy #define	UMA_ZONE_NODUMP		0x4000	/*
262263811f7SKip Macy 					 * Zone's pages will not be included in
263263811f7SKip Macy 					 * mini-dumps.
264263811f7SKip Macy 					 */
265ad97af7eSGleb Smirnoff #define	UMA_ZONE_PCPU		0x8000	/*
266d4665eaaSJeff Roberson 					 * Allocates mp_maxid + 1 slabs of
267d4665eaaSJeff Roberson 					 * PAGE_SIZE
268ad97af7eSGleb Smirnoff 					 */
26954c5ae80SRyan Libby #define	UMA_ZONE_FIRSTTOUCH	0x10000	/* First touch NUMA policy */
27054c5ae80SRyan Libby #define	UMA_ZONE_ROUNDROBIN	0x20000	/* Round-robin NUMA policy. */
271d4665eaaSJeff Roberson #define	UMA_ZONE_SMR		0x40000 /*
272d4665eaaSJeff Roberson 					 * Safe memory reclamation defers
273d4665eaaSJeff Roberson 					 * frees until all read sections
274d4665eaaSJeff Roberson 					 * have exited.  This flag creates
275d4665eaaSJeff Roberson 					 * a unique SMR context for this
276d4665eaaSJeff Roberson 					 * zone.  To share contexts see
277d4665eaaSJeff Roberson 					 * uma_zone_set_smr() below.
278d4665eaaSJeff Roberson 					 *
279d4665eaaSJeff Roberson 					 * See sys/smr.h for more details.
280d4665eaaSJeff Roberson 					 */
28109c8cb71SMark Johnston #define	UMA_ZONE_NOKASAN	0x80000	/*
28209c8cb71SMark Johnston 					 * Disable KASAN verification.  This is
28309c8cb71SMark Johnston 					 * implied by NOFREE.  Cache zones are
28409c8cb71SMark Johnston 					 * not verified by default.
28509c8cb71SMark Johnston 					 */
28654c5ae80SRyan Libby /* In use by UMA_ZFLAGs:	0xffe00000 */
287e20a199fSJeff Roberson 
288e20a199fSJeff Roberson /*
289d4665eaaSJeff Roberson  * These flags are shared between the keg and zone.  Some are determined
290d4665eaaSJeff Roberson  * based on physical parameters of the request and may not be provided by
291d4665eaaSJeff Roberson  * the consumer.
292e20a199fSJeff Roberson  */
293e20a199fSJeff Roberson #define	UMA_ZONE_INHERIT						\
29454c5ae80SRyan Libby     (UMA_ZONE_NOTOUCH | UMA_ZONE_MALLOC | UMA_ZONE_NOFREE |		\
295bae55c4aSRyan Libby      UMA_ZONE_VM | UMA_ZONE_NOTPAGE | UMA_ZONE_PCPU |			\
29609c8cb71SMark Johnston      UMA_ZONE_FIRSTTOUCH | UMA_ZONE_ROUNDROBIN | UMA_ZONE_NOKASAN)
2978355f576SJeff Roberson 
2988355f576SJeff Roberson /* Definitions for align */
2998355f576SJeff Roberson #define UMA_ALIGN_PTR	(sizeof(void *) - 1)	/* Alignment fit for ptr */
3008355f576SJeff Roberson #define UMA_ALIGN_LONG	(sizeof(long) - 1)	/* "" long */
3018355f576SJeff Roberson #define UMA_ALIGN_INT	(sizeof(int) - 1)	/* "" int */
3028355f576SJeff Roberson #define UMA_ALIGN_SHORT	(sizeof(short) - 1)	/* "" short */
3038355f576SJeff Roberson #define UMA_ALIGN_CHAR	(sizeof(char) - 1)	/* "" char */
3041e319f6dSRobert Watson #define UMA_ALIGN_CACHE	(0 - 1)			/* Cache line size align */
30514c510c0SJohn Baldwin #define	UMA_ALIGNOF(type) (_Alignof(type) - 1)	/* Alignment fit for 'type' */
3068355f576SJeff Roberson 
307b48d4efeSMark Johnston #define	UMA_ANYDOMAIN	-1	/* Special value for domain search. */
308b48d4efeSMark Johnston 
3098355f576SJeff Roberson /*
3109c2cd7e5SJeff Roberson  * Destroys an empty uma zone.  If the zone is not empty uma complains loudly.
3118355f576SJeff Roberson  *
3128355f576SJeff Roberson  * Arguments:
3138355f576SJeff Roberson  *	zone  The zone we want to destroy.
3148355f576SJeff Roberson  *
3158355f576SJeff Roberson  */
3169c2cd7e5SJeff Roberson void uma_zdestroy(uma_zone_t zone);
3178355f576SJeff Roberson 
3188355f576SJeff Roberson /*
3198355f576SJeff Roberson  * Allocates an item out of a zone
3208355f576SJeff Roberson  *
3218355f576SJeff Roberson  * Arguments:
3228355f576SJeff Roberson  *	zone  The zone we are allocating from
3238355f576SJeff Roberson  *	arg   This data is passed to the ctor function
3242cc35ff9SJeff Roberson  *	flags See sys/malloc.h for available flags.
3258355f576SJeff Roberson  *
3268355f576SJeff Roberson  * Returns:
3272db63c5eSGiorgos Keramidas  *	A non-null pointer to an initialized element from the zone is
3282db63c5eSGiorgos Keramidas  *	guaranteed if the wait flag is M_WAITOK.  Otherwise a null pointer
3292db63c5eSGiorgos Keramidas  *	may be returned if the zone is empty or the ctor failed.
3308355f576SJeff Roberson  */
3318355f576SJeff Roberson 
3322cc35ff9SJeff Roberson void *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags);
333d4665eaaSJeff Roberson 
334d4665eaaSJeff Roberson /* Allocate per-cpu data.  Access the correct data with zpcpu_get(). */
3354e180881SMateusz Guzik void *uma_zalloc_pcpu_arg(uma_zone_t zone, void *arg, int flags);
3368355f576SJeff Roberson 
337d4665eaaSJeff Roberson /* Use with SMR zones. */
338d4665eaaSJeff Roberson void *uma_zalloc_smr(uma_zone_t zone, int flags);
339d4665eaaSJeff Roberson 
3408355f576SJeff Roberson /*
341ab3185d1SJeff Roberson  * Allocate an item from a specific NUMA domain.  This uses a slow path in
342ab3185d1SJeff Roberson  * the allocator but is guaranteed to allocate memory from the requested
343ab3185d1SJeff Roberson  * domain if M_WAITOK is set.
344ab3185d1SJeff Roberson  *
345ab3185d1SJeff Roberson  * Arguments:
346ab3185d1SJeff Roberson  *	zone  The zone we are allocating from
347ab3185d1SJeff Roberson  *	arg   This data is passed to the ctor function
348ab3185d1SJeff Roberson  *	domain The domain to allocate from.
349ab3185d1SJeff Roberson  *	flags See sys/malloc.h for available flags.
350ab3185d1SJeff Roberson  */
351ab3185d1SJeff Roberson void *uma_zalloc_domain(uma_zone_t zone, void *arg, int domain, int flags);
352ab3185d1SJeff Roberson 
353ab3185d1SJeff Roberson /*
3548355f576SJeff Roberson  * Allocates an item out of a zone without supplying an argument
3558355f576SJeff Roberson  *
3568355f576SJeff Roberson  * This is just a wrapper for uma_zalloc_arg for convenience.
3578355f576SJeff Roberson  *
3588355f576SJeff Roberson  */
3592cc35ff9SJeff Roberson static __inline void *uma_zalloc(uma_zone_t zone, int flags);
3604e180881SMateusz Guzik static __inline void *uma_zalloc_pcpu(uma_zone_t zone, int flags);
3618355f576SJeff Roberson 
3628355f576SJeff Roberson static __inline void *
3632cc35ff9SJeff Roberson uma_zalloc(uma_zone_t zone, int flags)
3648355f576SJeff Roberson {
3652cc35ff9SJeff Roberson 	return uma_zalloc_arg(zone, NULL, flags);
3668355f576SJeff Roberson }
3678355f576SJeff Roberson 
3684e180881SMateusz Guzik static __inline void *
3694e180881SMateusz Guzik uma_zalloc_pcpu(uma_zone_t zone, int flags)
3704e180881SMateusz Guzik {
3714e180881SMateusz Guzik 	return uma_zalloc_pcpu_arg(zone, NULL, flags);
3724e180881SMateusz Guzik }
3734e180881SMateusz Guzik 
3748355f576SJeff Roberson /*
3758355f576SJeff Roberson  * Frees an item back into the specified zone.
3768355f576SJeff Roberson  *
3778355f576SJeff Roberson  * Arguments:
3788355f576SJeff Roberson  *	zone  The zone the item was originally allocated out of.
3798355f576SJeff Roberson  *	item  The memory to be freed.
3808355f576SJeff Roberson  *	arg   Argument passed to the destructor
3818355f576SJeff Roberson  *
3828355f576SJeff Roberson  * Returns:
3838355f576SJeff Roberson  *	Nothing.
3848355f576SJeff Roberson  */
3858355f576SJeff Roberson 
3868355f576SJeff Roberson void uma_zfree_arg(uma_zone_t zone, void *item, void *arg);
387d4665eaaSJeff Roberson 
388d4665eaaSJeff Roberson /* Use with PCPU zones. */
3894e180881SMateusz Guzik void uma_zfree_pcpu_arg(uma_zone_t zone, void *item, void *arg);
3908355f576SJeff Roberson 
391d4665eaaSJeff Roberson /* Use with SMR zones. */
392d4665eaaSJeff Roberson void uma_zfree_smr(uma_zone_t zone, void *item);
393d4665eaaSJeff Roberson 
3948355f576SJeff Roberson /*
3958355f576SJeff Roberson  * Frees an item back to a zone without supplying an argument
3968355f576SJeff Roberson  *
3978355f576SJeff Roberson  * This is just a wrapper for uma_zfree_arg for convenience.
3988355f576SJeff Roberson  *
3998355f576SJeff Roberson  */
4008355f576SJeff Roberson static __inline void uma_zfree(uma_zone_t zone, void *item);
4014e180881SMateusz Guzik static __inline void uma_zfree_pcpu(uma_zone_t zone, void *item);
4028355f576SJeff Roberson 
4038355f576SJeff Roberson static __inline void
4048355f576SJeff Roberson uma_zfree(uma_zone_t zone, void *item)
4058355f576SJeff Roberson {
406f6e34b82SMark Murray 	uma_zfree_arg(zone, item, NULL);
4078355f576SJeff Roberson }
4088355f576SJeff Roberson 
4094e180881SMateusz Guzik static __inline void
4104e180881SMateusz Guzik uma_zfree_pcpu(uma_zone_t zone, void *item)
4114e180881SMateusz Guzik {
4124e180881SMateusz Guzik 	uma_zfree_pcpu_arg(zone, item, NULL);
4134e180881SMateusz Guzik }
4144e180881SMateusz Guzik 
4158355f576SJeff Roberson /*
4168d6fbbb8SJeff Roberson  * Wait until the specified zone can allocate an item.
4178d6fbbb8SJeff Roberson  */
4188d6fbbb8SJeff Roberson void uma_zwait(uma_zone_t zone);
4198d6fbbb8SJeff Roberson 
4208d6fbbb8SJeff Roberson /*
4218355f576SJeff Roberson  * Backend page supplier routines
4228355f576SJeff Roberson  *
4238355f576SJeff Roberson  * Arguments:
4242db63c5eSGiorgos Keramidas  *	zone  The zone that is requesting pages.
4252db63c5eSGiorgos Keramidas  *	size  The number of bytes being requested.
4268355f576SJeff Roberson  *	pflag Flags for these memory pages, see below.
427ab3185d1SJeff Roberson  *	domain The NUMA domain that we prefer for this allocation.
4288355f576SJeff Roberson  *	wait  Indicates our willingness to block.
4298355f576SJeff Roberson  *
4308355f576SJeff Roberson  * Returns:
4312db63c5eSGiorgos Keramidas  *	A pointer to the allocated memory or NULL on failure.
4328355f576SJeff Roberson  */
4338355f576SJeff Roberson 
434ab3185d1SJeff Roberson typedef void *(*uma_alloc)(uma_zone_t zone, vm_size_t size, int domain,
435ab3185d1SJeff Roberson     uint8_t *pflag, int wait);
4368355f576SJeff Roberson 
4378355f576SJeff Roberson /*
4388355f576SJeff Roberson  * Backend page free routines
4398355f576SJeff Roberson  *
4408355f576SJeff Roberson  * Arguments:
4412db63c5eSGiorgos Keramidas  *	item  A pointer to the previously allocated pages.
4422db63c5eSGiorgos Keramidas  *	size  The original size of the allocation.
4432db63c5eSGiorgos Keramidas  *	pflag The flags for the slab.  See UMA_SLAB_* below.
4448355f576SJeff Roberson  *
4458355f576SJeff Roberson  * Returns:
4468355f576SJeff Roberson  *	None
4478355f576SJeff Roberson  */
448f2c2231eSRyan Stone typedef void (*uma_free)(void *item, vm_size_t size, uint8_t pflag);
4498355f576SJeff Roberson 
4508355f576SJeff Roberson /*
451aabe13f1SMark Johnston  * Reclaims unused memory.  If no NUMA domain is specified, memory from all
452aabe13f1SMark Johnston  * domains is reclaimed.
4538355f576SJeff Roberson  *
4548355f576SJeff Roberson  * Arguments:
45508cfa56eSMark Johnston  *	req    Reclamation request type.
456aabe13f1SMark Johnston  *	domain The target NUMA domain.
4578355f576SJeff Roberson  * Returns:
4588355f576SJeff Roberson  *	None
4598355f576SJeff Roberson  */
46008cfa56eSMark Johnston #define	UMA_RECLAIM_DRAIN	1	/* release bucket cache */
46108cfa56eSMark Johnston #define	UMA_RECLAIM_DRAIN_CPU	2	/* release bucket and per-CPU caches */
46208cfa56eSMark Johnston #define	UMA_RECLAIM_TRIM	3	/* trim bucket cache to WSS */
46308cfa56eSMark Johnston void uma_reclaim(int req);
464aabe13f1SMark Johnston void uma_reclaim_domain(int req, int domain);
46508cfa56eSMark Johnston void uma_zone_reclaim(uma_zone_t, int req);
466aabe13f1SMark Johnston void uma_zone_reclaim_domain(uma_zone_t, int req, int domain);
4678355f576SJeff Roberson 
4688355f576SJeff Roberson /*
4691e319f6dSRobert Watson  * Sets the alignment mask to be used for all zones requesting cache
4701e319f6dSRobert Watson  * alignment.  Should be called by MD boot code prior to starting VM/UMA.
4711e319f6dSRobert Watson  *
4721e319f6dSRobert Watson  * Arguments:
473*dc8f7692SOlivier Certner  *	mask The alignment mask
4741e319f6dSRobert Watson  *
4751e319f6dSRobert Watson  * Returns:
4761e319f6dSRobert Watson  *	Nothing
4771e319f6dSRobert Watson  */
478*dc8f7692SOlivier Certner void uma_set_cache_align_mask(int mask);
479*dc8f7692SOlivier Certner 
480*dc8f7692SOlivier Certner #include <vm/uma_align_mask.h>
4811e319f6dSRobert Watson 
4821e319f6dSRobert Watson /*
4836fd34d6fSJeff Roberson  * Set a reserved number of items to hold for M_USE_RESERVE allocations.  All
4846fd34d6fSJeff Roberson  * other requests must allocate new backing pages.
4856fd34d6fSJeff Roberson  */
4866fd34d6fSJeff Roberson void uma_zone_reserve(uma_zone_t zone, int nitems);
4876fd34d6fSJeff Roberson 
4886fd34d6fSJeff Roberson /*
489a4915c21SAttilio Rao  * Reserves the maximum KVA space required by the zone and configures the zone
490a9d6f1feSMark Johnston  * to use a backend that allocates physical memory and maps it using the
491a9d6f1feSMark Johnston  * reserved KVA.
4928355f576SJeff Roberson  *
4938355f576SJeff Roberson  * Arguments:
4942db63c5eSGiorgos Keramidas  *	zone  The zone to update.
495a4915c21SAttilio Rao  *	nitems  The upper limit on the number of items that can be allocated.
4968355f576SJeff Roberson  *
4978355f576SJeff Roberson  * Returns:
498a4915c21SAttilio Rao  *	0  if KVA space can not be allocated
4998355f576SJeff Roberson  *	1  if successful
5008355f576SJeff Roberson  *
5018355f576SJeff Roberson  * Discussion:
502a4915c21SAttilio Rao  *	When the machine supports a direct map and the zone's items are smaller
503a4915c21SAttilio Rao  *	than a page, the zone will use the direct map instead of allocating KVA
504a4915c21SAttilio Rao  *	space.
5058355f576SJeff Roberson  */
506a4915c21SAttilio Rao int uma_zone_reserve_kva(uma_zone_t zone, int nitems);
5078355f576SJeff Roberson 
508736ee590SJeff Roberson /*
509e574d407SMark Johnston  * Sets an upper limit on the number of items allocated from a zone
510736ee590SJeff Roberson  *
511736ee590SJeff Roberson  * Arguments:
512736ee590SJeff Roberson  *	zone  The zone to limit
5131c6cae97SLawrence Stewart  *	nitems  The requested upper limit on the number of items allowed
514736ee590SJeff Roberson  *
515736ee590SJeff Roberson  * Returns:
516003cf08bSMark Johnston  *	int  The effective value of nitems
517736ee590SJeff Roberson  */
5181c6cae97SLawrence Stewart int uma_zone_set_max(uma_zone_t zone, int nitems);
5198355f576SJeff Roberson 
5208355f576SJeff Roberson /*
521e574d407SMark Johnston  * Sets an upper limit on the number of items allowed in zone's caches
522bb15d1c7SGleb Smirnoff  *
523bb15d1c7SGleb Smirnoff  * Arguments:
524bb15d1c7SGleb Smirnoff  *      zone  The zone to limit
525bb15d1c7SGleb Smirnoff  *      nitems  The requested upper limit on the number of items allowed
526bb15d1c7SGleb Smirnoff  */
527003cf08bSMark Johnston void uma_zone_set_maxcache(uma_zone_t zone, int nitems);
528bb15d1c7SGleb Smirnoff 
529bb15d1c7SGleb Smirnoff /*
530e49471b0SAndre Oppermann  * Obtains the effective limit on the number of items in a zone
531e49471b0SAndre Oppermann  *
532e49471b0SAndre Oppermann  * Arguments:
533e49471b0SAndre Oppermann  *	zone  The zone to obtain the effective limit from
534e49471b0SAndre Oppermann  *
535e49471b0SAndre Oppermann  * Return:
536e49471b0SAndre Oppermann  *	0  No limit
537e49471b0SAndre Oppermann  *	int  The effective limit of the zone
538e49471b0SAndre Oppermann  */
539e49471b0SAndre Oppermann int uma_zone_get_max(uma_zone_t zone);
540e49471b0SAndre Oppermann 
541e49471b0SAndre Oppermann /*
5422f891cd5SPawel Jakub Dawidek  * Sets a warning to be printed when limit is reached
5432f891cd5SPawel Jakub Dawidek  *
5442f891cd5SPawel Jakub Dawidek  * Arguments:
5452f891cd5SPawel Jakub Dawidek  *	zone  The zone we will warn about
5462f891cd5SPawel Jakub Dawidek  *	warning  Warning content
5472f891cd5SPawel Jakub Dawidek  *
5482f891cd5SPawel Jakub Dawidek  * Returns:
5492f891cd5SPawel Jakub Dawidek  *	Nothing
5502f891cd5SPawel Jakub Dawidek  */
5512f891cd5SPawel Jakub Dawidek void uma_zone_set_warning(uma_zone_t zone, const char *warning);
5522f891cd5SPawel Jakub Dawidek 
5532f891cd5SPawel Jakub Dawidek /*
55454503a13SJonathan T. Looney  * Sets a function to run when limit is reached
55554503a13SJonathan T. Looney  *
55654503a13SJonathan T. Looney  * Arguments:
55754503a13SJonathan T. Looney  *	zone  The zone to which this applies
55854503a13SJonathan T. Looney  *	fx  The function ro run
55954503a13SJonathan T. Looney  *
56054503a13SJonathan T. Looney  * Returns:
56154503a13SJonathan T. Looney  *	Nothing
56254503a13SJonathan T. Looney  */
563e60b2fcbSGleb Smirnoff typedef void (*uma_maxaction_t)(uma_zone_t, int);
56454503a13SJonathan T. Looney void uma_zone_set_maxaction(uma_zone_t zone, uma_maxaction_t);
56554503a13SJonathan T. Looney 
56654503a13SJonathan T. Looney /*
567c4ae7908SLawrence Stewart  * Obtains the approximate current number of items allocated from a zone
568c4ae7908SLawrence Stewart  *
569c4ae7908SLawrence Stewart  * Arguments:
570c4ae7908SLawrence Stewart  *	zone  The zone to obtain the current allocation count from
571c4ae7908SLawrence Stewart  *
572c4ae7908SLawrence Stewart  * Return:
573c4ae7908SLawrence Stewart  *	int  The approximate current number of items allocated from the zone
574c4ae7908SLawrence Stewart  */
575c4ae7908SLawrence Stewart int uma_zone_get_cur(uma_zone_t zone);
576c4ae7908SLawrence Stewart 
577c4ae7908SLawrence Stewart /*
578099a0e58SBosko Milekic  * The following two routines (uma_zone_set_init/fini)
579099a0e58SBosko Milekic  * are used to set the backend init/fini pair which acts on an
580099a0e58SBosko Milekic  * object as it becomes allocated and is placed in a slab within
581099a0e58SBosko Milekic  * the specified zone's backing keg.  These should probably not
5822db63c5eSGiorgos Keramidas  * be changed once allocations have already begun, but only be set
583099a0e58SBosko Milekic  * immediately upon zone creation.
584099a0e58SBosko Milekic  */
585099a0e58SBosko Milekic void uma_zone_set_init(uma_zone_t zone, uma_init uminit);
586099a0e58SBosko Milekic void uma_zone_set_fini(uma_zone_t zone, uma_fini fini);
587099a0e58SBosko Milekic 
588099a0e58SBosko Milekic /*
589099a0e58SBosko Milekic  * The following two routines (uma_zone_set_zinit/zfini) are
590099a0e58SBosko Milekic  * used to set the zinit/zfini pair which acts on an object as
591099a0e58SBosko Milekic  * it passes from the backing Keg's slab cache to the
592099a0e58SBosko Milekic  * specified Zone's bucket cache.  These should probably not
5932db63c5eSGiorgos Keramidas  * be changed once allocations have already begun, but only be set
5942db63c5eSGiorgos Keramidas  * immediately upon zone creation.
595099a0e58SBosko Milekic  */
596099a0e58SBosko Milekic void uma_zone_set_zinit(uma_zone_t zone, uma_init zinit);
597099a0e58SBosko Milekic void uma_zone_set_zfini(uma_zone_t zone, uma_fini zfini);
598099a0e58SBosko Milekic 
599099a0e58SBosko Milekic /*
600a4915c21SAttilio Rao  * Replaces the standard backend allocator for this zone.
6018355f576SJeff Roberson  *
6028355f576SJeff Roberson  * Arguments:
6032db63c5eSGiorgos Keramidas  *	zone   The zone whose backend allocator is being changed.
6048355f576SJeff Roberson  *	allocf A pointer to the allocation function
6058355f576SJeff Roberson  *
6068355f576SJeff Roberson  * Returns:
6078355f576SJeff Roberson  *	Nothing
6088355f576SJeff Roberson  *
6098355f576SJeff Roberson  * Discussion:
6108355f576SJeff Roberson  *	This could be used to implement pageable allocation, or perhaps
6118355f576SJeff Roberson  *	even DMA allocators if used in conjunction with the OFFPAGE
6128355f576SJeff Roberson  *	zone flag.
6138355f576SJeff Roberson  */
6148355f576SJeff Roberson 
6158355f576SJeff Roberson void uma_zone_set_allocf(uma_zone_t zone, uma_alloc allocf);
6168355f576SJeff Roberson 
6178355f576SJeff Roberson /*
6188355f576SJeff Roberson  * Used for freeing memory provided by the allocf above
6198355f576SJeff Roberson  *
6208355f576SJeff Roberson  * Arguments:
6218355f576SJeff Roberson  *	zone  The zone that intends to use this free routine.
6228355f576SJeff Roberson  *	freef The page freeing routine.
6238355f576SJeff Roberson  *
6248355f576SJeff Roberson  * Returns:
6258355f576SJeff Roberson  *	Nothing
6268355f576SJeff Roberson  */
6278355f576SJeff Roberson 
6288355f576SJeff Roberson void uma_zone_set_freef(uma_zone_t zone, uma_free freef);
6298355f576SJeff Roberson 
6308355f576SJeff Roberson /*
631d4665eaaSJeff Roberson  * Associate a zone with a smr context that is allocated after creation
632d4665eaaSJeff Roberson  * so that multiple zones may share the same context.
633d4665eaaSJeff Roberson  */
634d4665eaaSJeff Roberson void uma_zone_set_smr(uma_zone_t zone, smr_t smr);
635d4665eaaSJeff Roberson 
636d4665eaaSJeff Roberson /*
637d4665eaaSJeff Roberson  * Fetch the smr context that was set or made in uma_zcreate().
638d4665eaaSJeff Roberson  */
639d4665eaaSJeff Roberson smr_t uma_zone_get_smr(uma_zone_t zone);
640d4665eaaSJeff Roberson 
641d4665eaaSJeff Roberson /*
642fc9f1d2cSGordon Bergling  * These flags are settable in the allocf and visible in the freef.
6438355f576SJeff Roberson  */
6448355f576SJeff Roberson #define UMA_SLAB_BOOT	0x01		/* Slab alloced from boot pages */
64549bfa624SAlan Cox #define UMA_SLAB_KERNEL	0x04		/* Slab alloced from kmem */
6468355f576SJeff Roberson #define UMA_SLAB_PRIV	0x08		/* Slab alloced from priv allocator */
647ec0d8280SRyan Libby /* 0x02, 0x10, 0x40, and 0x80 are available */
6488355f576SJeff Roberson 
6498355f576SJeff Roberson /*
6508355f576SJeff Roberson  * Used to pre-fill a zone with some number of items
6518355f576SJeff Roberson  *
6528355f576SJeff Roberson  * Arguments:
6538355f576SJeff Roberson  *	zone    The zone to fill
6548355f576SJeff Roberson  *	itemcnt The number of items to reserve
6558355f576SJeff Roberson  *
6568355f576SJeff Roberson  * Returns:
6578355f576SJeff Roberson  *	Nothing
6588355f576SJeff Roberson  *
6598355f576SJeff Roberson  * NOTE: This is blocking and should only be done at startup
6608355f576SJeff Roberson  */
6618355f576SJeff Roberson void uma_prealloc(uma_zone_t zone, int itemcnt);
6628355f576SJeff Roberson 
663099a0e58SBosko Milekic /*
664663b416fSJohn Baldwin  * Used to determine if a fixed-size zone is exhausted.
665663b416fSJohn Baldwin  *
666663b416fSJohn Baldwin  * Arguments:
667663b416fSJohn Baldwin  *	zone    The zone to check
668663b416fSJohn Baldwin  *
669663b416fSJohn Baldwin  * Returns:
670663b416fSJohn Baldwin  *	Non-zero if zone is exhausted.
671663b416fSJohn Baldwin  */
672663b416fSJohn Baldwin int uma_zone_exhausted(uma_zone_t zone);
673663b416fSJohn Baldwin 
674663b416fSJohn Baldwin /*
675ed581bf6SJeff Roberson  * Returns the bytes of memory consumed by the zone.
676ed581bf6SJeff Roberson  */
677ed581bf6SJeff Roberson size_t uma_zone_memory(uma_zone_t zone);
678ed581bf6SJeff Roberson 
679ed581bf6SJeff Roberson /*
68049fef6a2SGleb Smirnoff  * Common UMA_ZONE_PCPU zones.
68149fef6a2SGleb Smirnoff  */
6822dee296aSMateusz Guzik extern uma_zone_t pcpu_zone_4;
6832dee296aSMateusz Guzik extern uma_zone_t pcpu_zone_8;
6843a440a42SMateusz Guzik extern uma_zone_t pcpu_zone_16;
6853a440a42SMateusz Guzik extern uma_zone_t pcpu_zone_32;
6863a440a42SMateusz Guzik extern uma_zone_t pcpu_zone_64;
68749fef6a2SGleb Smirnoff 
68849fef6a2SGleb Smirnoff /*
6897a52a97eSRobert Watson  * Exported statistics structures to be used by user space monitoring tools.
6902db63c5eSGiorgos Keramidas  * Statistics stream consists of a uma_stream_header, followed by a series of
6912db63c5eSGiorgos Keramidas  * alternative uma_type_header and uma_type_stat structures.
6927a52a97eSRobert Watson  */
6937a52a97eSRobert Watson #define	UMA_STREAM_VERSION	0x00000001
6947a52a97eSRobert Watson struct uma_stream_header {
69585dcf349SGleb Smirnoff 	uint32_t	ush_version;	/* Stream format version. */
69685dcf349SGleb Smirnoff 	uint32_t	ush_maxcpus;	/* Value of MAXCPU for stream. */
69785dcf349SGleb Smirnoff 	uint32_t	ush_count;	/* Number of records. */
69885dcf349SGleb Smirnoff 	uint32_t	_ush_pad;	/* Pad/reserved field. */
6997a52a97eSRobert Watson };
7007a52a97eSRobert Watson 
701cbbb4a00SRobert Watson #define	UTH_MAX_NAME	32
702cbbb4a00SRobert Watson #define	UTH_ZONE_SECONDARY	0x00000001
7037a52a97eSRobert Watson struct uma_type_header {
7047a52a97eSRobert Watson 	/*
7057a52a97eSRobert Watson 	 * Static per-zone data, some extracted from the supporting keg.
7067a52a97eSRobert Watson 	 */
707cbbb4a00SRobert Watson 	char		uth_name[UTH_MAX_NAME];
70885dcf349SGleb Smirnoff 	uint32_t	uth_align;	/* Keg: alignment. */
70985dcf349SGleb Smirnoff 	uint32_t	uth_size;	/* Keg: requested size of item. */
71085dcf349SGleb Smirnoff 	uint32_t	uth_rsize;	/* Keg: real size of item. */
71185dcf349SGleb Smirnoff 	uint32_t	uth_maxpages;	/* Keg: maximum number of pages. */
71285dcf349SGleb Smirnoff 	uint32_t	uth_limit;	/* Keg: max items to allocate. */
7137a52a97eSRobert Watson 
7147a52a97eSRobert Watson 	/*
7157a52a97eSRobert Watson 	 * Current dynamic zone/keg-derived statistics.
7167a52a97eSRobert Watson 	 */
71785dcf349SGleb Smirnoff 	uint32_t	uth_pages;	/* Keg: pages allocated. */
71885dcf349SGleb Smirnoff 	uint32_t	uth_keg_free;	/* Keg: items free. */
71985dcf349SGleb Smirnoff 	uint32_t	uth_zone_free;	/* Zone: items free. */
72085dcf349SGleb Smirnoff 	uint32_t	uth_bucketsize;	/* Zone: desired bucket size. */
72185dcf349SGleb Smirnoff 	uint32_t	uth_zone_flags;	/* Zone: flags. */
72285dcf349SGleb Smirnoff 	uint64_t	uth_allocs;	/* Zone: number of allocations. */
72385dcf349SGleb Smirnoff 	uint64_t	uth_frees;	/* Zone: number of frees. */
72485dcf349SGleb Smirnoff 	uint64_t	uth_fails;	/* Zone: number of alloc failures. */
72585dcf349SGleb Smirnoff 	uint64_t	uth_sleeps;	/* Zone: number of alloc sleeps. */
726c1685086SJeff Roberson 	uint64_t	uth_xdomain;	/* Zone: Number of cross domain frees. */
727c1685086SJeff Roberson 	uint64_t	_uth_reserved1[1];	/* Reserved. */
7287a52a97eSRobert Watson };
7297a52a97eSRobert Watson 
7307a52a97eSRobert Watson struct uma_percpu_stat {
73185dcf349SGleb Smirnoff 	uint64_t	ups_allocs;	/* Cache: number of allocations. */
73285dcf349SGleb Smirnoff 	uint64_t	ups_frees;	/* Cache: number of frees. */
73385dcf349SGleb Smirnoff 	uint64_t	ups_cache_free;	/* Cache: free items in cache. */
73485dcf349SGleb Smirnoff 	uint64_t	_ups_reserved[5];	/* Reserved. */
7357a52a97eSRobert Watson };
7367a52a97eSRobert Watson 
73744ec2b63SKonstantin Belousov void uma_reclaim_wakeup(void);
73844ec2b63SKonstantin Belousov void uma_reclaim_worker(void *);
73944ec2b63SKonstantin Belousov 
740ad5b0f5bSJeff Roberson unsigned long uma_limit(void);
741ad5b0f5bSJeff Roberson 
742ad5b0f5bSJeff Roberson /* Return the amount of memory managed by UMA. */
743ad5b0f5bSJeff Roberson unsigned long uma_size(void);
744ad5b0f5bSJeff Roberson 
745ad5b0f5bSJeff Roberson /* Return the amount of memory remaining.  May be negative. */
746ad5b0f5bSJeff Roberson long uma_avail(void);
747ad5b0f5bSJeff Roberson 
748f947570eSGleb Smirnoff #endif	/* _VM_UMA_H_ */
749