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