2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 * Author: Avadis Tevanian, Jr.
62 #ifndef _KERN_ZALLOC_H_
63 #define _KERN_ZALLOC_H_
65 #include <mach/machine/vm_types.h>
66 #include <kern/kern_types.h>
68 #include <sys/appleapiopts.h>
70 #ifdef __APPLE_API_PRIVATE
72 #ifdef MACH_KERNEL_PRIVATE
74 #include <zone_debug.h>
76 #include <kern/lock.h>
77 #include <kern/queue.h>
78 #include <kern/call_entry.h>
81 * A zone is a collection of fixed size blocks for which there
82 * is fast allocation/deallocation access. Kernel routines can
83 * use zones to manage data structures dynamically, creating a zone
84 * for each type of data structure to be managed.
89 int count
; /* Number of elements used now */
90 vm_offset_t free_elements
;
91 vm_size_t cur_size
; /* current memory utilization */
92 vm_size_t max_size
; /* how large can this zone grow */
93 vm_size_t elem_size
; /* size of an element */
94 vm_size_t alloc_size
; /* size used for more memory */
95 char *zone_name
; /* a name for the zone */
97 /* boolean_t */ exhaustible
:1, /* (F) merely return if empty? */
98 /* boolean_t */ collectable
:1, /* (F) garbage collect empty pages */
99 /* boolean_t */ expandable
:1, /* (T) expand zone (with message)? */
100 /* boolean_t */ allows_foreign
:1,/* (F) allow non-zalloc space */
101 /* boolean_t */ doing_alloc
:1, /* is zone expanding now? */
102 /* boolean_t */ waiting
:1, /* is thread waiting for expansion? */
103 /* boolean_t */ async_pending
:1; /* asynchronous allocation pending? */
104 struct zone
* next_zone
; /* Link for all-zones list */
105 call_entry_data_t call_async_alloc
; /* callout for asynchronous alloc */
107 queue_head_t active_zones
; /* active elements */
108 #endif /* ZONE_DEBUG */
109 decl_simple_lock_data(,lock
) /* generic lock */
112 extern void zone_gc(void);
113 extern void consider_zone_gc(void);
115 /* Steal memory for zone module */
116 extern void zone_steal_memory(void);
118 /* Bootstrap zone module (create zone zone) */
119 extern void zone_bootstrap(void);
121 /* Init zone module */
122 extern void zone_init(vm_size_t
);
124 #endif /* MACH_KERNEL_PRIVATE */
126 #endif /* __APPLE_API_PRIVATE */
128 /* Allocate from zone */
129 extern vm_offset_t
zalloc(
132 /* Non-blocking version of zalloc */
133 extern vm_offset_t
zalloc_noblock(
136 /* Get from zone free list */
137 extern vm_offset_t
zget(
142 vm_size_t size
, /* the size of an element */
143 vm_size_t max
, /* maximum memory to use */
144 vm_size_t alloc
, /* allocation size */
145 char *name
); /* a name for the zone */
147 /* Free zone element */
152 /* Fill zone with memory */
158 /* Initially fill zone with specified number of elements */
162 /* Change zone parameters */
163 extern void zone_change(
168 /* Preallocate space for zone from zone map */
169 extern void zprealloc(
174 * zone_free_count returns a hint as to the current number of free elements
175 * in the zone. By the time it returns, it may no longer be true (a new
176 * element might have been added, or an element removed).
177 * This routine may be used in conjunction with zcram and a lock to regulate
178 * adding memory to a non-expandable zone.
180 extern integer_t
zone_free_count(zone_t zone
);
183 * Item definitions for zone_change:
185 #define Z_EXHAUST 1 /* Make zone exhaustible */
186 #define Z_COLLECT 2 /* Make zone collectable */
187 #define Z_EXPAND 3 /* Make zone expandable */
188 #define Z_FOREIGN 4 /* Allow collectable zone to contain foreign */
189 /* (not allocated via zalloc) elements. */
191 #ifdef __APPLE_API_PRIVATE
193 #ifdef MACH_KERNEL_PRIVATE
199 extern vm_offset_t
next_element(
203 extern vm_offset_t
first_element(
206 #endif /* MACH_KDB */
208 extern void zone_debug_enable(
211 extern void zone_debug_disable(
214 #endif /* ZONE_DEBUG */
216 #endif /* MACH_KERNEL_PRIVATE */
218 #endif /* __APPLE_API_PRIVATE */
220 #endif /* _KERN_ZALLOC_H_ */