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