xref: /illumos-gate/usr/src/lib/libmtmalloc/common/mtmalloc_impl.h (revision 657a8c206b913d1ee578fd725f0b25eca5b77253)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Various data structures that define the guts of the mt malloc
34  * library.
35  */
36 
37 #include <sys/types.h>
38 #include <synch.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef struct cache {
45 	mutex_t mt_cache_lock;	/* lock for this data structure */
46 	caddr_t mt_freelist;	/* free block bit mask */
47 	caddr_t mt_arena;	/* addr of arena for actual dblks */
48 	size_t  mt_nfree;	/* how many freeblocks do we have */
49 	size_t mt_size;		/* size of this cache */
50 	size_t mt_span;		/* how long is this cache */
51 	struct cache *mt_next;	/* next cache in list */
52 	int mt_hunks;		/* at creation time what chunk size */
53 } cache_t;
54 
55 typedef struct oversize {
56 	struct oversize *next_bysize;
57 	struct oversize *prev_bysize;
58 	struct oversize *next_byaddr;
59 	struct oversize *prev_byaddr;
60 	struct oversize *hash_next;
61 	caddr_t addr;
62 	size_t  size;
63 } oversize_t;
64 
65 typedef struct cache_head {
66 	cache_t *mt_cache;
67 	cache_t *mt_hint;
68 } cache_head_t;
69 
70 /* used to avoid false sharing, should be power-of-2 >= cache coherency size */
71 #define	CACHE_COHERENCY_UNIT	64
72 
73 #define	PERCPU_SIZE	CACHE_COHERENCY_UNIT
74 #define	PERCPU_PAD	(PERCPU_SIZE - sizeof (mutex_t) - \
75 			sizeof (cache_head_t *))
76 
77 typedef struct percpu {
78 	mutex_t mt_parent_lock;	/* used for hooking in new caches */
79 	cache_head_t *mt_caches;
80 	char mt_pad[PERCPU_PAD];
81 } percpu_t;
82 
83 typedef uint_t (*curcpu_func)(void);
84 
85 #define	DATA_SHIFT	1
86 #define	TAIL_SHIFT	2
87 
88 /*
89  * Oversize bit definitions: 3 bits to represent the oversize for
90  * head fragment, data itself, and tail fragment.
91  * If the head fragment is oversize, the first bit is on.
92  * If the data itself is oversize, the second bit is on.
93  * If the tail fragment is oversize, then the third bit is on.
94  */
95 #define	NONE_OVERSIZE		0x0
96 #define	HEAD_OVERSIZE		0x1
97 #define	DATA_OVERSIZE		0x2
98 #define	HEAD_AND_DATA_OVERSIZE	0x3
99 #define	TAIL_OVERSIZE		0x4
100 #define	HEAD_AND_TAIL_OVERSIZE	0x5
101 #define	DATA_AND_TAIL_OVERSIZE	0x6
102 #define	ALL_OVERSIZE		0x7
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _MTMALLOC_IMPL_H */
109