]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/zalloc.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / kern / zalloc.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58 /*
59 */
60 /*
61 * File: zalloc.h
62 * Author: Avadis Tevanian, Jr.
63 * Date: 1985
64 *
65 */
66
67 #ifdef KERNEL_PRIVATE
68
69 #ifndef _KERN_ZALLOC_H_
70 #define _KERN_ZALLOC_H_
71
72 #include <mach/machine/vm_types.h>
73 #include <kern/kern_types.h>
74 #include <sys/cdefs.h>
75
76 #ifdef MACH_KERNEL_PRIVATE
77
78 #include <zone_debug.h>
79 #include <mach_kdb.h>
80 #include <kern/lock.h>
81 #include <kern/queue.h>
82 #include <kern/call_entry.h>
83
84 /*
85 * A zone is a collection of fixed size blocks for which there
86 * is fast allocation/deallocation access. Kernel routines can
87 * use zones to manage data structures dynamically, creating a zone
88 * for each type of data structure to be managed.
89 *
90 */
91
92 struct zone {
93 int count; /* Number of elements used now */
94 vm_offset_t free_elements;
95 decl_mutex_data(,lock) /* generic lock */
96 vm_size_t cur_size; /* current memory utilization */
97 vm_size_t max_size; /* how large can this zone grow */
98 vm_size_t elem_size; /* size of an element */
99 vm_size_t alloc_size; /* size used for more memory */
100 unsigned int
101 /* boolean_t */ exhaustible :1, /* (F) merely return if empty? */
102 /* boolean_t */ collectable :1, /* (F) garbage collect empty pages */
103 /* boolean_t */ expandable :1, /* (T) expand zone (with message)? */
104 /* boolean_t */ allows_foreign :1,/* (F) allow non-zalloc space */
105 /* boolean_t */ doing_alloc :1, /* is zone expanding now? */
106 /* boolean_t */ waiting :1, /* is thread waiting for expansion? */
107 /* boolean_t */ async_pending :1, /* asynchronous allocation pending? */
108 /* boolean_t */ doing_gc :1; /* garbage collect in progress? */
109 struct zone * next_zone; /* Link for all-zones list */
110 call_entry_data_t call_async_alloc; /* callout for asynchronous alloc */
111 const char *zone_name; /* a name for the zone */
112 #if ZONE_DEBUG
113 queue_head_t active_zones; /* active elements */
114 #endif /* ZONE_DEBUG */
115 };
116
117 extern void zone_gc(void);
118 extern void consider_zone_gc(void);
119
120 /* Steal memory for zone module */
121 extern void zone_steal_memory(void);
122
123 /* Bootstrap zone module (create zone zone) */
124 extern void zone_bootstrap(void);
125
126 /* Init zone module */
127 extern void zone_init(
128 vm_size_t map_size);
129
130 /* Stack use statistics */
131 extern void stack_fake_zone_info(
132 int *count,
133 vm_size_t *cur_size,
134 vm_size_t *max_size,
135 vm_size_t *elem_size,
136 vm_size_t *alloc_size,
137 int *collectable,
138 int *exhaustable);
139
140 #if ZONE_DEBUG
141
142 #if MACH_KDB
143
144 extern void * next_element(
145 zone_t z,
146 void *elt);
147
148 extern void * first_element(
149 zone_t z);
150
151 #endif /* MACH_KDB */
152
153 extern void zone_debug_enable(
154 zone_t z);
155
156 extern void zone_debug_disable(
157 zone_t z);
158
159 #endif /* ZONE_DEBUG */
160
161 #endif /* MACH_KERNEL_PRIVATE */
162
163 __BEGIN_DECLS
164
165 #ifdef XNU_KERNEL_PRIVATE
166
167 /* Allocate from zone */
168 extern void * zalloc(
169 zone_t zone);
170
171 /* Free zone element */
172 extern void zfree(
173 zone_t zone,
174 void *elem);
175
176 /* Create zone */
177 extern zone_t zinit(
178 vm_size_t size, /* the size of an element */
179 vm_size_t maxmem, /* maximum memory to use */
180 vm_size_t alloc, /* allocation size */
181 const char *name); /* a name for the zone */
182
183
184 /* Non-blocking version of zalloc */
185 extern void * zalloc_noblock(
186 zone_t zone);
187
188 /* direct (non-wrappered) interface */
189 extern void * zalloc_canblock(
190 zone_t zone,
191 boolean_t canblock);
192
193 /* Get from zone free list */
194 extern void * zget(
195 zone_t zone);
196
197 /* Fill zone with memory */
198 extern void zcram(
199 zone_t zone,
200 void *newmem,
201 vm_size_t size);
202
203 /* Initially fill zone with specified number of elements */
204 extern int zfill(
205 zone_t zone,
206 int nelem);
207
208 /* Change zone parameters */
209 extern void zone_change(
210 zone_t zone,
211 unsigned int item,
212 boolean_t value);
213
214 /* Item definitions */
215 #define Z_EXHAUST 1 /* Make zone exhaustible */
216 #define Z_COLLECT 2 /* Make zone collectable */
217 #define Z_EXPAND 3 /* Make zone expandable */
218 #define Z_FOREIGN 4 /* Allow collectable zone to contain foreign elements */
219
220 /* Preallocate space for zone from zone map */
221 extern void zprealloc(
222 zone_t zone,
223 vm_size_t size);
224
225 extern integer_t zone_free_count(
226 zone_t zone);
227
228 #endif /* XNU_KERNEL_PRIVATE */
229
230 __END_DECLS
231
232 #endif /* _KERN_ZALLOC_H_ */
233
234 #endif /* KERNEL_PRIVATE */