1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _MTMALLOC_IMPL_H 28*7c478bd9Sstevel@tonic-gate #define _MTMALLOC_IMPL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Various data structures that define the guts of the mt malloc 34*7c478bd9Sstevel@tonic-gate * library. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 38*7c478bd9Sstevel@tonic-gate #include <synch.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 41*7c478bd9Sstevel@tonic-gate extern "C" { 42*7c478bd9Sstevel@tonic-gate #endif 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate typedef struct cache { 45*7c478bd9Sstevel@tonic-gate mutex_t mt_cache_lock; /* lock for this data structure */ 46*7c478bd9Sstevel@tonic-gate caddr_t mt_freelist; /* free block bit mask */ 47*7c478bd9Sstevel@tonic-gate caddr_t mt_arena; /* addr of arena for actual dblks */ 48*7c478bd9Sstevel@tonic-gate size_t mt_nfree; /* how many freeblocks do we have */ 49*7c478bd9Sstevel@tonic-gate size_t mt_size; /* size of this cache */ 50*7c478bd9Sstevel@tonic-gate size_t mt_span; /* how long is this cache */ 51*7c478bd9Sstevel@tonic-gate struct cache *mt_next; /* next cache in list */ 52*7c478bd9Sstevel@tonic-gate int mt_hunks; /* at creation time what chunk size */ 53*7c478bd9Sstevel@tonic-gate } cache_t; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate typedef struct oversize { 56*7c478bd9Sstevel@tonic-gate struct oversize *next_bysize; 57*7c478bd9Sstevel@tonic-gate struct oversize *prev_bysize; 58*7c478bd9Sstevel@tonic-gate struct oversize *next_byaddr; 59*7c478bd9Sstevel@tonic-gate struct oversize *prev_byaddr; 60*7c478bd9Sstevel@tonic-gate struct oversize *hash_next; 61*7c478bd9Sstevel@tonic-gate caddr_t addr; 62*7c478bd9Sstevel@tonic-gate size_t size; 63*7c478bd9Sstevel@tonic-gate } oversize_t; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate typedef struct cache_head { 66*7c478bd9Sstevel@tonic-gate cache_t *mt_cache; 67*7c478bd9Sstevel@tonic-gate cache_t *mt_hint; 68*7c478bd9Sstevel@tonic-gate } cache_head_t; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* used to avoid false sharing, should be power-of-2 >= cache coherency size */ 71*7c478bd9Sstevel@tonic-gate #define CACHE_COHERENCY_UNIT 64 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #define PERCPU_SIZE CACHE_COHERENCY_UNIT 74*7c478bd9Sstevel@tonic-gate #define PERCPU_PAD (PERCPU_SIZE - sizeof (mutex_t) - \ 75*7c478bd9Sstevel@tonic-gate sizeof (cache_head_t *)) 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate typedef struct percpu { 78*7c478bd9Sstevel@tonic-gate mutex_t mt_parent_lock; /* used for hooking in new caches */ 79*7c478bd9Sstevel@tonic-gate cache_head_t *mt_caches; 80*7c478bd9Sstevel@tonic-gate char mt_pad[PERCPU_PAD]; 81*7c478bd9Sstevel@tonic-gate } percpu_t; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate typedef uint_t (*curcpu_func)(void); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #define DATA_SHIFT 1 86*7c478bd9Sstevel@tonic-gate #define TAIL_SHIFT 2 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* 89*7c478bd9Sstevel@tonic-gate * Oversize bit definitions: 3 bits to represent the oversize for 90*7c478bd9Sstevel@tonic-gate * head fragment, data itself, and tail fragment. 91*7c478bd9Sstevel@tonic-gate * If the head fragment is oversize, the first bit is on. 92*7c478bd9Sstevel@tonic-gate * If the data itself is oversize, the second bit is on. 93*7c478bd9Sstevel@tonic-gate * If the tail fragment is oversize, then the third bit is on. 94*7c478bd9Sstevel@tonic-gate */ 95*7c478bd9Sstevel@tonic-gate #define NONE_OVERSIZE 0x0 96*7c478bd9Sstevel@tonic-gate #define HEAD_OVERSIZE 0x1 97*7c478bd9Sstevel@tonic-gate #define DATA_OVERSIZE 0x2 98*7c478bd9Sstevel@tonic-gate #define HEAD_AND_DATA_OVERSIZE 0x3 99*7c478bd9Sstevel@tonic-gate #define TAIL_OVERSIZE 0x4 100*7c478bd9Sstevel@tonic-gate #define HEAD_AND_TAIL_OVERSIZE 0x5 101*7c478bd9Sstevel@tonic-gate #define DATA_AND_TAIL_OVERSIZE 0x6 102*7c478bd9Sstevel@tonic-gate #define ALL_OVERSIZE 0x7 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate #endif 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #endif /* _MTMALLOC_IMPL_H */ 109