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