2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr.
67 #ifndef _KERN_ZALLOC_H_
68 #define _KERN_ZALLOC_H_
70 #include <mach/machine/vm_types.h>
71 #include <kern/kern_types.h>
72 #include <sys/cdefs.h>
74 #ifdef MACH_KERNEL_PRIVATE
76 #include <zone_debug.h>
78 #include <kern/lock.h>
79 #include <kern/queue.h>
80 #include <kern/call_entry.h>
83 * A zone is a collection of fixed size blocks for which there
84 * is fast allocation/deallocation access. Kernel routines can
85 * use zones to manage data structures dynamically, creating a zone
86 * for each type of data structure to be managed.
91 int count
; /* Number of elements used now */
92 vm_offset_t free_elements
;
93 decl_mutex_data(,lock
) /* generic lock */
94 vm_size_t cur_size
; /* current memory utilization */
95 vm_size_t max_size
; /* how large can this zone grow */
96 vm_size_t elem_size
; /* size of an element */
97 vm_size_t alloc_size
; /* size used for more memory */
99 /* boolean_t */ exhaustible
:1, /* (F) merely return if empty? */
100 /* boolean_t */ collectable
:1, /* (F) garbage collect empty pages */
101 /* boolean_t */ expandable
:1, /* (T) expand zone (with message)? */
102 /* boolean_t */ allows_foreign
:1,/* (F) allow non-zalloc space */
103 /* boolean_t */ doing_alloc
:1, /* is zone expanding now? */
104 /* boolean_t */ waiting
:1, /* is thread waiting for expansion? */
105 /* boolean_t */ async_pending
:1, /* asynchronous allocation pending? */
106 /* boolean_t */ doing_gc
:1; /* garbage collect in progress? */
107 struct zone
* next_zone
; /* Link for all-zones list */
108 call_entry_data_t call_async_alloc
; /* callout for asynchronous alloc */
109 const char *zone_name
; /* a name for the zone */
111 queue_head_t active_zones
; /* active elements */
112 #endif /* ZONE_DEBUG */
115 extern void zone_gc(void);
116 extern void consider_zone_gc(void);
118 /* Steal memory for zone module */
119 extern void zone_steal_memory(void);
121 /* Bootstrap zone module (create zone zone) */
122 extern void zone_bootstrap(void);
124 /* Init zone module */
125 extern void zone_init(
128 /* Stack use statistics */
129 extern void stack_fake_zone_info(
133 vm_size_t
*elem_size
,
134 vm_size_t
*alloc_size
,
142 extern void * next_element(
146 extern void * first_element(
149 #endif /* MACH_KDB */
151 extern void zone_debug_enable(
154 extern void zone_debug_disable(
157 #endif /* ZONE_DEBUG */
159 #endif /* MACH_KERNEL_PRIVATE */
163 #ifdef XNU_KERNEL_PRIVATE
165 /* Allocate from zone */
166 extern void * zalloc(
169 /* Free zone element */
176 vm_size_t size
, /* the size of an element */
177 vm_size_t maxmem
, /* maximum memory to use */
178 vm_size_t alloc
, /* allocation size */
179 const char *name
); /* a name for the zone */
182 /* Non-blocking version of zalloc */
183 extern void * zalloc_noblock(
186 /* direct (non-wrappered) interface */
187 extern void * zalloc_canblock(
191 /* Get from zone free list */
195 /* Fill zone with memory */
201 /* Initially fill zone with specified number of elements */
206 /* Change zone parameters */
207 extern void zone_change(
212 /* Item definitions */
213 #define Z_EXHAUST 1 /* Make zone exhaustible */
214 #define Z_COLLECT 2 /* Make zone collectable */
215 #define Z_EXPAND 3 /* Make zone expandable */
216 #define Z_FOREIGN 4 /* Allow collectable zone to contain foreign elements */
218 /* Preallocate space for zone from zone map */
219 extern void zprealloc(
223 extern integer_t
zone_free_count(
226 #endif /* XNU_KERNEL_PRIVATE */
230 #endif /* _KERN_ZALLOC_H_ */
232 #endif /* KERNEL_PRIVATE */