xref: /onnv-gate/usr/src/uts/common/sys/kmem_impl.h (revision 6306:ecac2262dc70)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6306Stomee  * Common Development and Distribution License (the "License").
6*6306Stomee  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*6306Stomee 
220Sstevel@tonic-gate /*
23*6306Stomee  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_KMEM_IMPL_H
280Sstevel@tonic-gate #define	_SYS_KMEM_IMPL_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/kmem.h>
330Sstevel@tonic-gate #include <sys/vmem.h>
340Sstevel@tonic-gate #include <sys/thread.h>
350Sstevel@tonic-gate #include <sys/t_lock.h>
360Sstevel@tonic-gate #include <sys/time.h>
370Sstevel@tonic-gate #include <sys/kstat.h>
380Sstevel@tonic-gate #include <sys/cpuvar.h>
390Sstevel@tonic-gate #include <sys/systm.h>
400Sstevel@tonic-gate #include <vm/page.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * kernel memory allocator: implementation-private data structures
480Sstevel@tonic-gate  */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #define	KMF_AUDIT	0x00000001	/* transaction auditing */
510Sstevel@tonic-gate #define	KMF_DEADBEEF	0x00000002	/* deadbeef checking */
520Sstevel@tonic-gate #define	KMF_REDZONE	0x00000004	/* redzone checking */
530Sstevel@tonic-gate #define	KMF_CONTENTS	0x00000008	/* freed-buffer content logging */
540Sstevel@tonic-gate #define	KMF_STICKY	0x00000010	/* if set, override /etc/system */
550Sstevel@tonic-gate #define	KMF_NOMAGAZINE	0x00000020	/* disable per-cpu magazines */
560Sstevel@tonic-gate #define	KMF_FIREWALL	0x00000040	/* put all bufs before unmapped pages */
570Sstevel@tonic-gate #define	KMF_LITE	0x00000100	/* lightweight debugging */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #define	KMF_HASH	0x00000200	/* cache has hash table */
600Sstevel@tonic-gate #define	KMF_RANDOMIZE	0x00000400	/* randomize other kmem_flags */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	KMF_BUFTAG	(KMF_DEADBEEF | KMF_REDZONE)
630Sstevel@tonic-gate #define	KMF_TOUCH	(KMF_BUFTAG | KMF_LITE | KMF_CONTENTS)
640Sstevel@tonic-gate #define	KMF_RANDOM	(KMF_TOUCH | KMF_AUDIT | KMF_NOMAGAZINE)
650Sstevel@tonic-gate #define	KMF_DEBUG	(KMF_RANDOM | KMF_FIREWALL)
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #define	KMEM_STACK_DEPTH	15
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #define	KMEM_FREE_PATTERN		0xdeadbeefdeadbeefULL
700Sstevel@tonic-gate #define	KMEM_UNINITIALIZED_PATTERN	0xbaddcafebaddcafeULL
710Sstevel@tonic-gate #define	KMEM_REDZONE_PATTERN		0xfeedfacefeedfaceULL
720Sstevel@tonic-gate #define	KMEM_REDZONE_BYTE		0xbb
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * Redzone size encodings for kmem_alloc() / kmem_free().  We encode the
760Sstevel@tonic-gate  * allocation size, rather than storing it directly, so that kmem_free()
770Sstevel@tonic-gate  * can distinguish frees of the wrong size from redzone violations.
780Sstevel@tonic-gate  *
790Sstevel@tonic-gate  * A size of zero is never valid.
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate #define	KMEM_SIZE_ENCODE(x)	(251 * (x) + 1)
820Sstevel@tonic-gate #define	KMEM_SIZE_DECODE(x)	((x) / 251)
830Sstevel@tonic-gate #define	KMEM_SIZE_VALID(x)	((x) % 251 == 1 && (x) != 1)
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * The bufctl (buffer control) structure keeps some minimal information
870Sstevel@tonic-gate  * about each buffer: its address, its slab, and its current linkage,
880Sstevel@tonic-gate  * which is either on the slab's freelist (if the buffer is free), or
890Sstevel@tonic-gate  * on the cache's buf-to-bufctl hash table (if the buffer is allocated).
900Sstevel@tonic-gate  * In the case of non-hashed, or "raw", caches (the common case), only
910Sstevel@tonic-gate  * the freelist linkage is necessary: the buffer address is at a fixed
920Sstevel@tonic-gate  * offset from the bufctl address, and the slab is at the end of the page.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * NOTE: bc_next must be the first field; raw buffers have linkage only.
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate typedef struct kmem_bufctl {
970Sstevel@tonic-gate 	struct kmem_bufctl	*bc_next;	/* next bufctl struct */
980Sstevel@tonic-gate 	void			*bc_addr;	/* address of buffer */
990Sstevel@tonic-gate 	struct kmem_slab	*bc_slab;	/* controlling slab */
1000Sstevel@tonic-gate } kmem_bufctl_t;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * The KMF_AUDIT version of the bufctl structure.  The beginning of this
1040Sstevel@tonic-gate  * structure must be identical to the normal bufctl structure so that
1050Sstevel@tonic-gate  * pointers are interchangeable.
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate typedef struct kmem_bufctl_audit {
1080Sstevel@tonic-gate 	struct kmem_bufctl	*bc_next;	/* next bufctl struct */
1090Sstevel@tonic-gate 	void			*bc_addr;	/* address of buffer */
1100Sstevel@tonic-gate 	struct kmem_slab	*bc_slab;	/* controlling slab */
1110Sstevel@tonic-gate 	kmem_cache_t		*bc_cache;	/* controlling cache */
1120Sstevel@tonic-gate 	hrtime_t		bc_timestamp;	/* transaction time */
1130Sstevel@tonic-gate 	kthread_t		*bc_thread;	/* thread doing transaction */
1140Sstevel@tonic-gate 	struct kmem_bufctl	*bc_lastlog;	/* last log entry */
1150Sstevel@tonic-gate 	void			*bc_contents;	/* contents at last free */
1160Sstevel@tonic-gate 	int			bc_depth;	/* stack depth */
1170Sstevel@tonic-gate 	pc_t			bc_stack[KMEM_STACK_DEPTH];	/* pc stack */
1180Sstevel@tonic-gate } kmem_bufctl_audit_t;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate /*
1210Sstevel@tonic-gate  * A kmem_buftag structure is appended to each buffer whenever any of the
1220Sstevel@tonic-gate  * KMF_BUFTAG flags (KMF_DEADBEEF, KMF_REDZONE, KMF_VERIFY) are set.
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate typedef struct kmem_buftag {
1250Sstevel@tonic-gate 	uint64_t		bt_redzone;	/* 64-bit redzone pattern */
1260Sstevel@tonic-gate 	kmem_bufctl_t		*bt_bufctl;	/* bufctl */
1270Sstevel@tonic-gate 	intptr_t		bt_bxstat;	/* bufctl ^ (alloc/free) */
1280Sstevel@tonic-gate } kmem_buftag_t;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate  * A variant of the kmem_buftag structure used for KMF_LITE caches.
1320Sstevel@tonic-gate  * Previous callers are stored in reverse chronological order. (i.e. most
1330Sstevel@tonic-gate  * recent first)
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate typedef struct kmem_buftag_lite {
1360Sstevel@tonic-gate 	kmem_buftag_t		bt_buftag;	/* a normal buftag */
1370Sstevel@tonic-gate 	pc_t			bt_history[1];	/* zero or more callers */
1380Sstevel@tonic-gate } kmem_buftag_lite_t;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #define	KMEM_BUFTAG_LITE_SIZE(f)	\
1410Sstevel@tonic-gate 	(offsetof(kmem_buftag_lite_t, bt_history[f]))
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define	KMEM_BUFTAG(cp, buf)		\
1440Sstevel@tonic-gate 	((kmem_buftag_t *)((char *)(buf) + (cp)->cache_buftag))
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #define	KMEM_BUFCTL(cp, buf)		\
1470Sstevel@tonic-gate 	((kmem_bufctl_t *)((char *)(buf) + (cp)->cache_bufctl))
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate #define	KMEM_BUF(cp, bcp)		\
1500Sstevel@tonic-gate 	((void *)((char *)(bcp) - (cp)->cache_bufctl))
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	KMEM_SLAB(cp, buf)		\
1530Sstevel@tonic-gate 	((kmem_slab_t *)P2END((uintptr_t)(buf), (cp)->cache_slabsize) - 1)
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define	KMEM_CPU_CACHE(cp)		\
1560Sstevel@tonic-gate 	(kmem_cpu_cache_t *)((char *)cp + CPU->cpu_cache_offset)
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #define	KMEM_MAGAZINE_VALID(cp, mp)	\
1590Sstevel@tonic-gate 	(((kmem_slab_t *)P2END((uintptr_t)(mp), PAGESIZE) - 1)->slab_cache == \
1600Sstevel@tonic-gate 	    (cp)->cache_magtype->mt_cache)
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate #define	KMEM_SLAB_MEMBER(sp, buf)	\
1630Sstevel@tonic-gate 	((size_t)(buf) - (size_t)(sp)->slab_base < \
1640Sstevel@tonic-gate 	    (sp)->slab_cache->cache_slabsize)
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate #define	KMEM_BUFTAG_ALLOC	0xa110c8edUL
1670Sstevel@tonic-gate #define	KMEM_BUFTAG_FREE	0xf4eef4eeUL
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate typedef struct kmem_slab {
1700Sstevel@tonic-gate 	struct kmem_cache	*slab_cache;	/* controlling cache */
1710Sstevel@tonic-gate 	void			*slab_base;	/* base of allocated memory */
1720Sstevel@tonic-gate 	struct kmem_slab	*slab_next;	/* next slab on freelist */
1730Sstevel@tonic-gate 	struct kmem_slab	*slab_prev;	/* prev slab on freelist */
1740Sstevel@tonic-gate 	struct kmem_bufctl	*slab_head;	/* first free buffer */
1750Sstevel@tonic-gate 	long			slab_refcnt;	/* outstanding allocations */
1760Sstevel@tonic-gate 	long			slab_chunks;	/* chunks (bufs) in this slab */
1770Sstevel@tonic-gate } kmem_slab_t;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #define	KMEM_HASH_INITIAL	64
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #define	KMEM_HASH(cp, buf)	\
1820Sstevel@tonic-gate 	((cp)->cache_hash_table +	\
1830Sstevel@tonic-gate 	(((uintptr_t)(buf) >> (cp)->cache_hash_shift) & (cp)->cache_hash_mask))
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate typedef struct kmem_magazine {
1860Sstevel@tonic-gate 	void	*mag_next;
1870Sstevel@tonic-gate 	void	*mag_round[1];		/* one or more rounds */
1880Sstevel@tonic-gate } kmem_magazine_t;
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate /*
1910Sstevel@tonic-gate  * The magazine types for fast per-cpu allocation
1920Sstevel@tonic-gate  */
1930Sstevel@tonic-gate typedef struct kmem_magtype {
1940Sstevel@tonic-gate 	int		mt_magsize;	/* magazine size (number of rounds) */
1950Sstevel@tonic-gate 	int		mt_align;	/* magazine alignment */
1960Sstevel@tonic-gate 	size_t		mt_minbuf;	/* all smaller buffers qualify */
1970Sstevel@tonic-gate 	size_t		mt_maxbuf;	/* no larger buffers qualify */
1980Sstevel@tonic-gate 	kmem_cache_t	*mt_cache;	/* magazine cache */
1990Sstevel@tonic-gate } kmem_magtype_t;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #define	KMEM_CPU_CACHE_SIZE	64	/* must be power of 2 */
2020Sstevel@tonic-gate #define	KMEM_CPU_PAD		(KMEM_CPU_CACHE_SIZE - sizeof (kmutex_t) - \
2030Sstevel@tonic-gate 	2 * sizeof (uint64_t) - 2 * sizeof (void *) - 4 * sizeof (int))
2040Sstevel@tonic-gate #define	KMEM_CACHE_SIZE(ncpus)	\
2050Sstevel@tonic-gate 	((size_t)(&((kmem_cache_t *)0)->cache_cpu[ncpus]))
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate typedef struct kmem_cpu_cache {
2080Sstevel@tonic-gate 	kmutex_t	cc_lock;	/* protects this cpu's local cache */
2090Sstevel@tonic-gate 	uint64_t	cc_alloc;	/* allocations from this cpu */
2100Sstevel@tonic-gate 	uint64_t	cc_free;	/* frees to this cpu */
2110Sstevel@tonic-gate 	kmem_magazine_t	*cc_loaded;	/* the currently loaded magazine */
2120Sstevel@tonic-gate 	kmem_magazine_t	*cc_ploaded;	/* the previously loaded magazine */
2130Sstevel@tonic-gate 	int		cc_rounds;	/* number of objects in loaded mag */
2140Sstevel@tonic-gate 	int		cc_prounds;	/* number of objects in previous mag */
2150Sstevel@tonic-gate 	int		cc_magsize;	/* number of rounds in a full mag */
2160Sstevel@tonic-gate 	int		cc_flags;	/* CPU-local copy of cache_flags */
2170Sstevel@tonic-gate 	char		cc_pad[KMEM_CPU_PAD]; /* for nice alignment */
2180Sstevel@tonic-gate } kmem_cpu_cache_t;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate /*
2210Sstevel@tonic-gate  * The magazine lists used in the depot.
2220Sstevel@tonic-gate  */
2230Sstevel@tonic-gate typedef struct kmem_maglist {
2240Sstevel@tonic-gate 	kmem_magazine_t	*ml_list;	/* magazine list */
2250Sstevel@tonic-gate 	long		ml_total;	/* number of magazines */
2260Sstevel@tonic-gate 	long		ml_min;		/* min since last update */
2270Sstevel@tonic-gate 	long		ml_reaplimit;	/* max reapable magazines */
2280Sstevel@tonic-gate 	uint64_t	ml_alloc;	/* allocations from this list */
2290Sstevel@tonic-gate } kmem_maglist_t;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate #define	KMEM_CACHE_NAMELEN	31
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate struct kmem_cache {
2340Sstevel@tonic-gate 	/*
2350Sstevel@tonic-gate 	 * Statistics
2360Sstevel@tonic-gate 	 */
2370Sstevel@tonic-gate 	uint64_t	cache_slab_create;	/* slab creates */
2380Sstevel@tonic-gate 	uint64_t	cache_slab_destroy;	/* slab destroys */
2390Sstevel@tonic-gate 	uint64_t	cache_slab_alloc;	/* slab layer allocations */
2400Sstevel@tonic-gate 	uint64_t	cache_slab_free;	/* slab layer frees */
2410Sstevel@tonic-gate 	uint64_t	cache_alloc_fail;	/* total failed allocations */
2420Sstevel@tonic-gate 	uint64_t	cache_buftotal;		/* total buffers */
2430Sstevel@tonic-gate 	uint64_t	cache_bufmax;		/* max buffers ever */
244*6306Stomee 	uint64_t	cache_bufslab;		/* buffers free in slab layer */
2450Sstevel@tonic-gate 	uint64_t	cache_rescale;		/* # of hash table rescales */
2460Sstevel@tonic-gate 	uint64_t	cache_lookup_depth;	/* hash lookup depth */
2470Sstevel@tonic-gate 	uint64_t	cache_depot_contention;	/* mutex contention count */
2480Sstevel@tonic-gate 	uint64_t	cache_depot_contention_prev; /* previous snapshot */
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 	/*
2510Sstevel@tonic-gate 	 * Cache properties
2520Sstevel@tonic-gate 	 */
2530Sstevel@tonic-gate 	char		cache_name[KMEM_CACHE_NAMELEN + 1];
2540Sstevel@tonic-gate 	size_t		cache_bufsize;		/* object size */
2550Sstevel@tonic-gate 	size_t		cache_align;		/* object alignment */
2560Sstevel@tonic-gate 	int		(*cache_constructor)(void *, void *, int);
2570Sstevel@tonic-gate 	void		(*cache_destructor)(void *, void *);
2580Sstevel@tonic-gate 	void		(*cache_reclaim)(void *);
2590Sstevel@tonic-gate 	void		*cache_private;		/* opaque arg to callbacks */
2600Sstevel@tonic-gate 	vmem_t		*cache_arena;		/* vmem source for slabs */
2610Sstevel@tonic-gate 	int		cache_cflags;		/* cache creation flags */
2620Sstevel@tonic-gate 	int		cache_flags;		/* various cache state info */
2630Sstevel@tonic-gate 	uint32_t	cache_mtbf;		/* induced alloc failure rate */
2640Sstevel@tonic-gate 	uint32_t	cache_pad1;		/* to align cache_lock */
2650Sstevel@tonic-gate 	kstat_t		*cache_kstat;		/* exported statistics */
2660Sstevel@tonic-gate 	kmem_cache_t	*cache_next;		/* forward cache linkage */
2670Sstevel@tonic-gate 	kmem_cache_t	*cache_prev;		/* backward cache linkage */
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	/*
2700Sstevel@tonic-gate 	 * Slab layer
2710Sstevel@tonic-gate 	 */
2720Sstevel@tonic-gate 	kmutex_t	cache_lock;		/* protects slab layer */
2730Sstevel@tonic-gate 	size_t		cache_chunksize;	/* buf + alignment [+ debug] */
2740Sstevel@tonic-gate 	size_t		cache_slabsize;		/* size of a slab */
2750Sstevel@tonic-gate 	size_t		cache_bufctl;		/* buf-to-bufctl distance */
2760Sstevel@tonic-gate 	size_t		cache_buftag;		/* buf-to-buftag distance */
2770Sstevel@tonic-gate 	size_t		cache_verify;		/* bytes to verify */
2780Sstevel@tonic-gate 	size_t		cache_contents;		/* bytes of saved content */
2790Sstevel@tonic-gate 	size_t		cache_color;		/* next slab color */
2800Sstevel@tonic-gate 	size_t		cache_mincolor;		/* maximum slab color */
2810Sstevel@tonic-gate 	size_t		cache_maxcolor;		/* maximum slab color */
2820Sstevel@tonic-gate 	size_t		cache_hash_shift;	/* get to interesting bits */
2830Sstevel@tonic-gate 	size_t		cache_hash_mask;	/* hash table mask */
2840Sstevel@tonic-gate 	kmem_slab_t	*cache_freelist;	/* slab free list */
2850Sstevel@tonic-gate 	kmem_slab_t	cache_nullslab;		/* end of freelist marker */
2860Sstevel@tonic-gate 	kmem_cache_t	*cache_bufctl_cache;	/* source of bufctls */
2870Sstevel@tonic-gate 	kmem_bufctl_t	**cache_hash_table;	/* hash table base */
2880Sstevel@tonic-gate 	void		*cache_pad2;		/* to align depot_lock */
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	/*
2910Sstevel@tonic-gate 	 * Depot layer
2920Sstevel@tonic-gate 	 */
2930Sstevel@tonic-gate 	kmutex_t	cache_depot_lock;	/* protects depot */
2940Sstevel@tonic-gate 	kmem_magtype_t	*cache_magtype;		/* magazine type */
2950Sstevel@tonic-gate 	void		*cache_pad3;		/* to align cache_cpu */
2960Sstevel@tonic-gate 	kmem_maglist_t	cache_full;		/* full magazines */
2970Sstevel@tonic-gate 	kmem_maglist_t	cache_empty;		/* empty magazines */
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 	/*
3000Sstevel@tonic-gate 	 * Per-CPU layer
3010Sstevel@tonic-gate 	 */
3020Sstevel@tonic-gate 	kmem_cpu_cache_t cache_cpu[1];		/* max_ncpus actual elements */
3030Sstevel@tonic-gate };
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate typedef struct kmem_cpu_log_header {
3060Sstevel@tonic-gate 	kmutex_t	clh_lock;
3070Sstevel@tonic-gate 	char		*clh_current;
3080Sstevel@tonic-gate 	size_t		clh_avail;
3090Sstevel@tonic-gate 	int		clh_chunk;
3100Sstevel@tonic-gate 	int		clh_hits;
3110Sstevel@tonic-gate 	char		clh_pad[64 - sizeof (kmutex_t) - sizeof (char *) -
3120Sstevel@tonic-gate 				sizeof (size_t) - 2 * sizeof (int)];
3130Sstevel@tonic-gate } kmem_cpu_log_header_t;
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate typedef struct kmem_log_header {
3160Sstevel@tonic-gate 	kmutex_t	lh_lock;
3170Sstevel@tonic-gate 	char		*lh_base;
3180Sstevel@tonic-gate 	int		*lh_free;
3190Sstevel@tonic-gate 	size_t		lh_chunksize;
3200Sstevel@tonic-gate 	int		lh_nchunks;
3210Sstevel@tonic-gate 	int		lh_head;
3220Sstevel@tonic-gate 	int		lh_tail;
3230Sstevel@tonic-gate 	int		lh_hits;
3240Sstevel@tonic-gate 	kmem_cpu_log_header_t lh_cpu[1];	/* ncpus actually allocated */
3250Sstevel@tonic-gate } kmem_log_header_t;
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate #define	KMEM_ALIGN		8	/* min guaranteed alignment */
3280Sstevel@tonic-gate #define	KMEM_ALIGN_SHIFT	3	/* log2(KMEM_ALIGN) */
3290Sstevel@tonic-gate #define	KMEM_VOID_FRACTION	8	/* never waste more than 1/8 of slab */
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate #ifdef	__cplusplus
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate #endif
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate #endif	/* _SYS_KMEM_IMPL_H */
336