2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
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.
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.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
62 * Author: Avadis Tevanian, Jr.
69 #ifndef _KERN_ZALLOC_H_
70 #define _KERN_ZALLOC_H_
72 #include <mach/machine/vm_types.h>
73 #include <kern/kern_types.h>
74 #include <sys/cdefs.h>
76 #ifdef MACH_KERNEL_PRIVATE
78 #include <zone_debug.h>
80 #include <kern/lock.h>
81 #include <kern/queue.h>
82 #include <kern/call_entry.h>
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.
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 */
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 */
113 queue_head_t active_zones
; /* active elements */
114 #endif /* ZONE_DEBUG */
117 extern void zone_gc(void);
118 extern void consider_zone_gc(void);
120 /* Steal memory for zone module */
121 extern void zone_steal_memory(void);
123 /* Bootstrap zone module (create zone zone) */
124 extern void zone_bootstrap(void);
126 /* Init zone module */
127 extern void zone_init(
130 /* Stack use statistics */
131 extern void stack_fake_zone_info(
135 vm_size_t
*elem_size
,
136 vm_size_t
*alloc_size
,
144 extern void * next_element(
148 extern void * first_element(
151 #endif /* MACH_KDB */
153 extern void zone_debug_enable(
156 extern void zone_debug_disable(
159 #endif /* ZONE_DEBUG */
161 #endif /* MACH_KERNEL_PRIVATE */
165 #ifdef XNU_KERNEL_PRIVATE
167 /* Allocate from zone */
168 extern void * zalloc(
171 /* Free zone element */
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 */
184 /* Non-blocking version of zalloc */
185 extern void * zalloc_noblock(
188 /* direct (non-wrappered) interface */
189 extern void * zalloc_canblock(
193 /* Get from zone free list */
197 /* Fill zone with memory */
203 /* Initially fill zone with specified number of elements */
208 /* Change zone parameters */
209 extern void zone_change(
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 */
220 /* Preallocate space for zone from zone map */
221 extern void zprealloc(
225 extern integer_t
zone_free_count(
228 #endif /* XNU_KERNEL_PRIVATE */
232 #endif /* _KERN_ZALLOC_H_ */
234 #endif /* KERNEL_PRIVATE */