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