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 56306Stomee * Common Development and Distribution License (the "License"). 66306Stomee * 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 */ 216306Stomee 220Sstevel@tonic-gate /* 236306Stomee * 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> 41*6712Stomee #include <sys/avl.h> 42*6712Stomee #include <sys/list.h> 430Sstevel@tonic-gate 440Sstevel@tonic-gate #ifdef __cplusplus 450Sstevel@tonic-gate extern "C" { 460Sstevel@tonic-gate #endif 470Sstevel@tonic-gate 480Sstevel@tonic-gate /* 490Sstevel@tonic-gate * kernel memory allocator: implementation-private data structures 50*6712Stomee * 51*6712Stomee * Lock order: 52*6712Stomee * 1. cache_lock 53*6712Stomee * 2. cc_lock in order by CPU ID 54*6712Stomee * 3. cache_depot_lock 55*6712Stomee * 56*6712Stomee * Do not call kmem_cache_alloc() or taskq_dispatch() while holding any of the 57*6712Stomee * above locks. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate 600Sstevel@tonic-gate #define KMF_AUDIT 0x00000001 /* transaction auditing */ 610Sstevel@tonic-gate #define KMF_DEADBEEF 0x00000002 /* deadbeef checking */ 620Sstevel@tonic-gate #define KMF_REDZONE 0x00000004 /* redzone checking */ 630Sstevel@tonic-gate #define KMF_CONTENTS 0x00000008 /* freed-buffer content logging */ 640Sstevel@tonic-gate #define KMF_STICKY 0x00000010 /* if set, override /etc/system */ 650Sstevel@tonic-gate #define KMF_NOMAGAZINE 0x00000020 /* disable per-cpu magazines */ 660Sstevel@tonic-gate #define KMF_FIREWALL 0x00000040 /* put all bufs before unmapped pages */ 670Sstevel@tonic-gate #define KMF_LITE 0x00000100 /* lightweight debugging */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate #define KMF_HASH 0x00000200 /* cache has hash table */ 700Sstevel@tonic-gate #define KMF_RANDOMIZE 0x00000400 /* randomize other kmem_flags */ 710Sstevel@tonic-gate 720Sstevel@tonic-gate #define KMF_BUFTAG (KMF_DEADBEEF | KMF_REDZONE) 730Sstevel@tonic-gate #define KMF_TOUCH (KMF_BUFTAG | KMF_LITE | KMF_CONTENTS) 740Sstevel@tonic-gate #define KMF_RANDOM (KMF_TOUCH | KMF_AUDIT | KMF_NOMAGAZINE) 750Sstevel@tonic-gate #define KMF_DEBUG (KMF_RANDOM | KMF_FIREWALL) 760Sstevel@tonic-gate 770Sstevel@tonic-gate #define KMEM_STACK_DEPTH 15 780Sstevel@tonic-gate 790Sstevel@tonic-gate #define KMEM_FREE_PATTERN 0xdeadbeefdeadbeefULL 800Sstevel@tonic-gate #define KMEM_UNINITIALIZED_PATTERN 0xbaddcafebaddcafeULL 810Sstevel@tonic-gate #define KMEM_REDZONE_PATTERN 0xfeedfacefeedfaceULL 820Sstevel@tonic-gate #define KMEM_REDZONE_BYTE 0xbb 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Redzone size encodings for kmem_alloc() / kmem_free(). We encode the 860Sstevel@tonic-gate * allocation size, rather than storing it directly, so that kmem_free() 870Sstevel@tonic-gate * can distinguish frees of the wrong size from redzone violations. 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * A size of zero is never valid. 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate #define KMEM_SIZE_ENCODE(x) (251 * (x) + 1) 920Sstevel@tonic-gate #define KMEM_SIZE_DECODE(x) ((x) / 251) 930Sstevel@tonic-gate #define KMEM_SIZE_VALID(x) ((x) % 251 == 1 && (x) != 1) 940Sstevel@tonic-gate 95*6712Stomee 96*6712Stomee #define KMEM_ALIGN 8 /* min guaranteed alignment */ 97*6712Stomee #define KMEM_ALIGN_SHIFT 3 /* log2(KMEM_ALIGN) */ 98*6712Stomee #define KMEM_VOID_FRACTION 8 /* never waste more than 1/8 of slab */ 99*6712Stomee 100*6712Stomee #define KMEM_SLAB_IS_PARTIAL(sp) \ 101*6712Stomee ((sp)->slab_refcnt > 0 && (sp)->slab_refcnt < (sp)->slab_chunks) 102*6712Stomee #define KMEM_SLAB_IS_ALL_USED(sp) \ 103*6712Stomee ((sp)->slab_refcnt == (sp)->slab_chunks) 104*6712Stomee 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * The bufctl (buffer control) structure keeps some minimal information 1070Sstevel@tonic-gate * about each buffer: its address, its slab, and its current linkage, 1080Sstevel@tonic-gate * which is either on the slab's freelist (if the buffer is free), or 1090Sstevel@tonic-gate * on the cache's buf-to-bufctl hash table (if the buffer is allocated). 1100Sstevel@tonic-gate * In the case of non-hashed, or "raw", caches (the common case), only 1110Sstevel@tonic-gate * the freelist linkage is necessary: the buffer address is at a fixed 1120Sstevel@tonic-gate * offset from the bufctl address, and the slab is at the end of the page. 1130Sstevel@tonic-gate * 1140Sstevel@tonic-gate * NOTE: bc_next must be the first field; raw buffers have linkage only. 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate typedef struct kmem_bufctl { 1170Sstevel@tonic-gate struct kmem_bufctl *bc_next; /* next bufctl struct */ 1180Sstevel@tonic-gate void *bc_addr; /* address of buffer */ 1190Sstevel@tonic-gate struct kmem_slab *bc_slab; /* controlling slab */ 1200Sstevel@tonic-gate } kmem_bufctl_t; 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * The KMF_AUDIT version of the bufctl structure. The beginning of this 1240Sstevel@tonic-gate * structure must be identical to the normal bufctl structure so that 1250Sstevel@tonic-gate * pointers are interchangeable. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate typedef struct kmem_bufctl_audit { 1280Sstevel@tonic-gate struct kmem_bufctl *bc_next; /* next bufctl struct */ 1290Sstevel@tonic-gate void *bc_addr; /* address of buffer */ 1300Sstevel@tonic-gate struct kmem_slab *bc_slab; /* controlling slab */ 1310Sstevel@tonic-gate kmem_cache_t *bc_cache; /* controlling cache */ 1320Sstevel@tonic-gate hrtime_t bc_timestamp; /* transaction time */ 1330Sstevel@tonic-gate kthread_t *bc_thread; /* thread doing transaction */ 1340Sstevel@tonic-gate struct kmem_bufctl *bc_lastlog; /* last log entry */ 1350Sstevel@tonic-gate void *bc_contents; /* contents at last free */ 1360Sstevel@tonic-gate int bc_depth; /* stack depth */ 1370Sstevel@tonic-gate pc_t bc_stack[KMEM_STACK_DEPTH]; /* pc stack */ 1380Sstevel@tonic-gate } kmem_bufctl_audit_t; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * A kmem_buftag structure is appended to each buffer whenever any of the 1420Sstevel@tonic-gate * KMF_BUFTAG flags (KMF_DEADBEEF, KMF_REDZONE, KMF_VERIFY) are set. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate typedef struct kmem_buftag { 1450Sstevel@tonic-gate uint64_t bt_redzone; /* 64-bit redzone pattern */ 1460Sstevel@tonic-gate kmem_bufctl_t *bt_bufctl; /* bufctl */ 1470Sstevel@tonic-gate intptr_t bt_bxstat; /* bufctl ^ (alloc/free) */ 1480Sstevel@tonic-gate } kmem_buftag_t; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * A variant of the kmem_buftag structure used for KMF_LITE caches. 1520Sstevel@tonic-gate * Previous callers are stored in reverse chronological order. (i.e. most 1530Sstevel@tonic-gate * recent first) 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate typedef struct kmem_buftag_lite { 1560Sstevel@tonic-gate kmem_buftag_t bt_buftag; /* a normal buftag */ 1570Sstevel@tonic-gate pc_t bt_history[1]; /* zero or more callers */ 1580Sstevel@tonic-gate } kmem_buftag_lite_t; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define KMEM_BUFTAG_LITE_SIZE(f) \ 1610Sstevel@tonic-gate (offsetof(kmem_buftag_lite_t, bt_history[f])) 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate #define KMEM_BUFTAG(cp, buf) \ 1640Sstevel@tonic-gate ((kmem_buftag_t *)((char *)(buf) + (cp)->cache_buftag)) 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate #define KMEM_BUFCTL(cp, buf) \ 1670Sstevel@tonic-gate ((kmem_bufctl_t *)((char *)(buf) + (cp)->cache_bufctl)) 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #define KMEM_BUF(cp, bcp) \ 1700Sstevel@tonic-gate ((void *)((char *)(bcp) - (cp)->cache_bufctl)) 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate #define KMEM_SLAB(cp, buf) \ 1730Sstevel@tonic-gate ((kmem_slab_t *)P2END((uintptr_t)(buf), (cp)->cache_slabsize) - 1) 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate #define KMEM_CPU_CACHE(cp) \ 1760Sstevel@tonic-gate (kmem_cpu_cache_t *)((char *)cp + CPU->cpu_cache_offset) 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define KMEM_MAGAZINE_VALID(cp, mp) \ 1790Sstevel@tonic-gate (((kmem_slab_t *)P2END((uintptr_t)(mp), PAGESIZE) - 1)->slab_cache == \ 1800Sstevel@tonic-gate (cp)->cache_magtype->mt_cache) 1810Sstevel@tonic-gate 182*6712Stomee #define KMEM_SLAB_OFFSET(sp, buf) \ 183*6712Stomee ((size_t)((uintptr_t)(buf) - (uintptr_t)((sp)->slab_base))) 184*6712Stomee 1850Sstevel@tonic-gate #define KMEM_SLAB_MEMBER(sp, buf) \ 186*6712Stomee (KMEM_SLAB_OFFSET(sp, buf) < (sp)->slab_cache->cache_slabsize) 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #define KMEM_BUFTAG_ALLOC 0xa110c8edUL 1890Sstevel@tonic-gate #define KMEM_BUFTAG_FREE 0xf4eef4eeUL 1900Sstevel@tonic-gate 191*6712Stomee /* slab_later_count thresholds */ 192*6712Stomee #define KMEM_DISBELIEF 3 193*6712Stomee 194*6712Stomee /* slab_flags */ 195*6712Stomee #define KMEM_SLAB_NOMOVE 0x1 196*6712Stomee #define KMEM_SLAB_MOVE_PENDING 0x2 197*6712Stomee 1980Sstevel@tonic-gate typedef struct kmem_slab { 1990Sstevel@tonic-gate struct kmem_cache *slab_cache; /* controlling cache */ 2000Sstevel@tonic-gate void *slab_base; /* base of allocated memory */ 201*6712Stomee avl_node_t slab_link; /* slab linkage */ 2020Sstevel@tonic-gate struct kmem_bufctl *slab_head; /* first free buffer */ 2030Sstevel@tonic-gate long slab_refcnt; /* outstanding allocations */ 2040Sstevel@tonic-gate long slab_chunks; /* chunks (bufs) in this slab */ 205*6712Stomee uint32_t slab_stuck_offset; /* unmoved buffer offset */ 206*6712Stomee uint16_t slab_later_count; /* cf KMEM_CBRC_LATER */ 207*6712Stomee uint16_t slab_flags; /* bits to mark the slab */ 2080Sstevel@tonic-gate } kmem_slab_t; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate #define KMEM_HASH_INITIAL 64 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #define KMEM_HASH(cp, buf) \ 2130Sstevel@tonic-gate ((cp)->cache_hash_table + \ 2140Sstevel@tonic-gate (((uintptr_t)(buf) >> (cp)->cache_hash_shift) & (cp)->cache_hash_mask)) 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate typedef struct kmem_magazine { 2170Sstevel@tonic-gate void *mag_next; 2180Sstevel@tonic-gate void *mag_round[1]; /* one or more rounds */ 2190Sstevel@tonic-gate } kmem_magazine_t; 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* 2220Sstevel@tonic-gate * The magazine types for fast per-cpu allocation 2230Sstevel@tonic-gate */ 2240Sstevel@tonic-gate typedef struct kmem_magtype { 2250Sstevel@tonic-gate int mt_magsize; /* magazine size (number of rounds) */ 2260Sstevel@tonic-gate int mt_align; /* magazine alignment */ 2270Sstevel@tonic-gate size_t mt_minbuf; /* all smaller buffers qualify */ 2280Sstevel@tonic-gate size_t mt_maxbuf; /* no larger buffers qualify */ 2290Sstevel@tonic-gate kmem_cache_t *mt_cache; /* magazine cache */ 2300Sstevel@tonic-gate } kmem_magtype_t; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate #define KMEM_CPU_CACHE_SIZE 64 /* must be power of 2 */ 2330Sstevel@tonic-gate #define KMEM_CPU_PAD (KMEM_CPU_CACHE_SIZE - sizeof (kmutex_t) - \ 2340Sstevel@tonic-gate 2 * sizeof (uint64_t) - 2 * sizeof (void *) - 4 * sizeof (int)) 2350Sstevel@tonic-gate #define KMEM_CACHE_SIZE(ncpus) \ 2360Sstevel@tonic-gate ((size_t)(&((kmem_cache_t *)0)->cache_cpu[ncpus])) 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate typedef struct kmem_cpu_cache { 2390Sstevel@tonic-gate kmutex_t cc_lock; /* protects this cpu's local cache */ 2400Sstevel@tonic-gate uint64_t cc_alloc; /* allocations from this cpu */ 2410Sstevel@tonic-gate uint64_t cc_free; /* frees to this cpu */ 2420Sstevel@tonic-gate kmem_magazine_t *cc_loaded; /* the currently loaded magazine */ 2430Sstevel@tonic-gate kmem_magazine_t *cc_ploaded; /* the previously loaded magazine */ 2440Sstevel@tonic-gate int cc_rounds; /* number of objects in loaded mag */ 2450Sstevel@tonic-gate int cc_prounds; /* number of objects in previous mag */ 2460Sstevel@tonic-gate int cc_magsize; /* number of rounds in a full mag */ 2470Sstevel@tonic-gate int cc_flags; /* CPU-local copy of cache_flags */ 2480Sstevel@tonic-gate char cc_pad[KMEM_CPU_PAD]; /* for nice alignment */ 2490Sstevel@tonic-gate } kmem_cpu_cache_t; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* 2520Sstevel@tonic-gate * The magazine lists used in the depot. 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate typedef struct kmem_maglist { 2550Sstevel@tonic-gate kmem_magazine_t *ml_list; /* magazine list */ 2560Sstevel@tonic-gate long ml_total; /* number of magazines */ 2570Sstevel@tonic-gate long ml_min; /* min since last update */ 2580Sstevel@tonic-gate long ml_reaplimit; /* max reapable magazines */ 2590Sstevel@tonic-gate uint64_t ml_alloc; /* allocations from this list */ 2600Sstevel@tonic-gate } kmem_maglist_t; 2610Sstevel@tonic-gate 262*6712Stomee typedef struct kmem_defrag { 263*6712Stomee /* 264*6712Stomee * Statistics 265*6712Stomee */ 266*6712Stomee uint64_t kmd_callbacks; /* move callbacks */ 267*6712Stomee uint64_t kmd_yes; /* KMEM_CBRC_YES responses */ 268*6712Stomee uint64_t kmd_no; /* NO responses */ 269*6712Stomee uint64_t kmd_later; /* LATER responses */ 270*6712Stomee uint64_t kmd_dont_need; /* DONT_NEED responses */ 271*6712Stomee uint64_t kmd_dont_know; /* DONT_KNOW responses */ 272*6712Stomee uint64_t kmd_hunt_found; /* DONT_KNOW: # found in mag */ 273*6712Stomee 274*6712Stomee /* 275*6712Stomee * Consolidator fields 276*6712Stomee */ 277*6712Stomee avl_tree_t kmd_moves_pending; /* buffer moves pending */ 278*6712Stomee list_t kmd_deadlist; /* deferred slab frees */ 279*6712Stomee size_t kmd_deadcount; /* # of slabs in kmd_deadlist */ 280*6712Stomee uint8_t kmd_reclaim_numer; /* slab usage threshold */ 281*6712Stomee uint8_t kmd_pad1; /* compiler padding */ 282*6712Stomee size_t kmd_slabs_sought; /* reclaimable slabs sought */ 283*6712Stomee size_t kmd_slabs_found; /* reclaimable slabs found */ 284*6712Stomee size_t kmd_scans; /* nth scan interval counter */ 285*6712Stomee /* 286*6712Stomee * Fields used to ASSERT that the client does not kmem_cache_free() 287*6712Stomee * objects passed to the move callback. 288*6712Stomee */ 289*6712Stomee void *kmd_from_buf; /* object to move */ 290*6712Stomee void *kmd_to_buf; /* move destination */ 291*6712Stomee kthread_t *kmd_thread; /* thread calling move */ 292*6712Stomee } kmem_defrag_t; 293*6712Stomee 2940Sstevel@tonic-gate #define KMEM_CACHE_NAMELEN 31 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate struct kmem_cache { 2970Sstevel@tonic-gate /* 2980Sstevel@tonic-gate * Statistics 2990Sstevel@tonic-gate */ 3000Sstevel@tonic-gate uint64_t cache_slab_create; /* slab creates */ 3010Sstevel@tonic-gate uint64_t cache_slab_destroy; /* slab destroys */ 3020Sstevel@tonic-gate uint64_t cache_slab_alloc; /* slab layer allocations */ 3030Sstevel@tonic-gate uint64_t cache_slab_free; /* slab layer frees */ 3040Sstevel@tonic-gate uint64_t cache_alloc_fail; /* total failed allocations */ 3050Sstevel@tonic-gate uint64_t cache_buftotal; /* total buffers */ 3060Sstevel@tonic-gate uint64_t cache_bufmax; /* max buffers ever */ 3076306Stomee uint64_t cache_bufslab; /* buffers free in slab layer */ 3080Sstevel@tonic-gate uint64_t cache_rescale; /* # of hash table rescales */ 3090Sstevel@tonic-gate uint64_t cache_lookup_depth; /* hash lookup depth */ 3100Sstevel@tonic-gate uint64_t cache_depot_contention; /* mutex contention count */ 3110Sstevel@tonic-gate uint64_t cache_depot_contention_prev; /* previous snapshot */ 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * Cache properties 3150Sstevel@tonic-gate */ 3160Sstevel@tonic-gate char cache_name[KMEM_CACHE_NAMELEN + 1]; 3170Sstevel@tonic-gate size_t cache_bufsize; /* object size */ 3180Sstevel@tonic-gate size_t cache_align; /* object alignment */ 3190Sstevel@tonic-gate int (*cache_constructor)(void *, void *, int); 3200Sstevel@tonic-gate void (*cache_destructor)(void *, void *); 3210Sstevel@tonic-gate void (*cache_reclaim)(void *); 322*6712Stomee kmem_cbrc_t (*cache_move)(void *, void *, size_t, void *); 3230Sstevel@tonic-gate void *cache_private; /* opaque arg to callbacks */ 3240Sstevel@tonic-gate vmem_t *cache_arena; /* vmem source for slabs */ 3250Sstevel@tonic-gate int cache_cflags; /* cache creation flags */ 3260Sstevel@tonic-gate int cache_flags; /* various cache state info */ 3270Sstevel@tonic-gate uint32_t cache_mtbf; /* induced alloc failure rate */ 328*6712Stomee uint32_t cache_pad1; /* compiler padding */ 3290Sstevel@tonic-gate kstat_t *cache_kstat; /* exported statistics */ 330*6712Stomee list_node_t cache_link; /* cache linkage */ 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* 3330Sstevel@tonic-gate * Slab layer 3340Sstevel@tonic-gate */ 3350Sstevel@tonic-gate kmutex_t cache_lock; /* protects slab layer */ 3360Sstevel@tonic-gate size_t cache_chunksize; /* buf + alignment [+ debug] */ 3370Sstevel@tonic-gate size_t cache_slabsize; /* size of a slab */ 338*6712Stomee size_t cache_maxchunks; /* max buffers per slab */ 3390Sstevel@tonic-gate size_t cache_bufctl; /* buf-to-bufctl distance */ 3400Sstevel@tonic-gate size_t cache_buftag; /* buf-to-buftag distance */ 3410Sstevel@tonic-gate size_t cache_verify; /* bytes to verify */ 3420Sstevel@tonic-gate size_t cache_contents; /* bytes of saved content */ 3430Sstevel@tonic-gate size_t cache_color; /* next slab color */ 3440Sstevel@tonic-gate size_t cache_mincolor; /* maximum slab color */ 3450Sstevel@tonic-gate size_t cache_maxcolor; /* maximum slab color */ 3460Sstevel@tonic-gate size_t cache_hash_shift; /* get to interesting bits */ 3470Sstevel@tonic-gate size_t cache_hash_mask; /* hash table mask */ 348*6712Stomee list_t cache_complete_slabs; /* completely allocated slabs */ 349*6712Stomee size_t cache_complete_slab_count; 350*6712Stomee avl_tree_t cache_partial_slabs; /* partial slab freelist */ 351*6712Stomee size_t cache_partial_binshift; /* for AVL sort bins */ 3520Sstevel@tonic-gate kmem_cache_t *cache_bufctl_cache; /* source of bufctls */ 3530Sstevel@tonic-gate kmem_bufctl_t **cache_hash_table; /* hash table base */ 354*6712Stomee kmem_defrag_t *cache_defrag; /* slab consolidator fields */ 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /* 3570Sstevel@tonic-gate * Depot layer 3580Sstevel@tonic-gate */ 3590Sstevel@tonic-gate kmutex_t cache_depot_lock; /* protects depot */ 3600Sstevel@tonic-gate kmem_magtype_t *cache_magtype; /* magazine type */ 3610Sstevel@tonic-gate kmem_maglist_t cache_full; /* full magazines */ 3620Sstevel@tonic-gate kmem_maglist_t cache_empty; /* empty magazines */ 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate /* 3650Sstevel@tonic-gate * Per-CPU layer 3660Sstevel@tonic-gate */ 3670Sstevel@tonic-gate kmem_cpu_cache_t cache_cpu[1]; /* max_ncpus actual elements */ 3680Sstevel@tonic-gate }; 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate typedef struct kmem_cpu_log_header { 3710Sstevel@tonic-gate kmutex_t clh_lock; 3720Sstevel@tonic-gate char *clh_current; 3730Sstevel@tonic-gate size_t clh_avail; 3740Sstevel@tonic-gate int clh_chunk; 3750Sstevel@tonic-gate int clh_hits; 3760Sstevel@tonic-gate char clh_pad[64 - sizeof (kmutex_t) - sizeof (char *) - 3770Sstevel@tonic-gate sizeof (size_t) - 2 * sizeof (int)]; 3780Sstevel@tonic-gate } kmem_cpu_log_header_t; 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate typedef struct kmem_log_header { 3810Sstevel@tonic-gate kmutex_t lh_lock; 3820Sstevel@tonic-gate char *lh_base; 3830Sstevel@tonic-gate int *lh_free; 3840Sstevel@tonic-gate size_t lh_chunksize; 3850Sstevel@tonic-gate int lh_nchunks; 3860Sstevel@tonic-gate int lh_head; 3870Sstevel@tonic-gate int lh_tail; 3880Sstevel@tonic-gate int lh_hits; 3890Sstevel@tonic-gate kmem_cpu_log_header_t lh_cpu[1]; /* ncpus actually allocated */ 3900Sstevel@tonic-gate } kmem_log_header_t; 3910Sstevel@tonic-gate 392*6712Stomee /* kmem_move kmm_flags */ 393*6712Stomee #define KMM_DESPERATE 0x1 394*6712Stomee #define KMM_NOTIFY 0x2 395*6712Stomee 396*6712Stomee typedef struct kmem_move { 397*6712Stomee kmem_slab_t *kmm_from_slab; 398*6712Stomee void *kmm_from_buf; 399*6712Stomee void *kmm_to_buf; 400*6712Stomee avl_node_t kmm_entry; 401*6712Stomee int kmm_flags; 402*6712Stomee } kmem_move_t; 403*6712Stomee 404*6712Stomee /* 405*6712Stomee * In order to consolidate partial slabs, it must be possible for the cache to 406*6712Stomee * have partial slabs. 407*6712Stomee */ 408*6712Stomee #define KMEM_IS_MOVABLE(cp) \ 409*6712Stomee (((cp)->cache_chunksize * 2) <= (cp)->cache_slabsize) 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate #ifdef __cplusplus 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate #endif 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate #endif /* _SYS_KMEM_IMPL_H */ 416