]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/kern/zalloc.h
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / kern / zalloc.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
32 *
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.
38 *
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.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53/*
54 */
55/*
56 * File: zalloc.h
57 * Author: Avadis Tevanian, Jr.
58 * Date: 1985
59 *
60 */
61
62#ifndef _KERN_ZALLOC_H_
63#define _KERN_ZALLOC_H_
64
65#include <mach/machine/vm_types.h>
66#include <kern/kern_types.h>
67
68#include <sys/appleapiopts.h>
69
70#ifdef __APPLE_API_PRIVATE
71
72#ifdef MACH_KERNEL_PRIVATE
73
74#include <zone_debug.h>
75#include <mach_kdb.h>
76#include <kern/lock.h>
77#include <kern/queue.h>
78#include <kern/call_entry.h>
79
80/*
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.
85 *
86 */
87
88struct zone {
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 */
96 unsigned int
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 */
106#if ZONE_DEBUG
107 queue_head_t active_zones; /* active elements */
108#endif /* ZONE_DEBUG */
109 decl_simple_lock_data(,lock) /* generic lock */
110};
111
112extern void zone_gc(void);
113extern void consider_zone_gc(void);
114
115/* Steal memory for zone module */
116extern void zone_steal_memory(void);
117
118/* Bootstrap zone module (create zone zone) */
119extern void zone_bootstrap(void);
120
121/* Init zone module */
122extern void zone_init(vm_size_t);
123
124#endif /* MACH_KERNEL_PRIVATE */
125
126#endif /* __APPLE_API_PRIVATE */
127
128/* Allocate from zone */
129extern vm_offset_t zalloc(
130 zone_t zone);
131
132/* Non-blocking version of zalloc */
133extern vm_offset_t zalloc_noblock(
134 zone_t zone);
135
136/* Get from zone free list */
137extern vm_offset_t zget(
138 zone_t zone);
139
140/* Create zone */
141extern zone_t zinit(
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 */
146
147/* Free zone element */
148extern void zfree(
149 zone_t zone,
150 vm_offset_t elem);
151
152/* Fill zone with memory */
153extern void zcram(
154 zone_t zone,
155 vm_offset_t newmem,
156 vm_size_t size);
157
158/* Initially fill zone with specified number of elements */
159extern int zfill(
160 zone_t zone,
161 int nelem);
162/* Change zone parameters */
163extern void zone_change(
164 zone_t zone,
165 unsigned int item,
166 boolean_t value);
167
168/* Preallocate space for zone from zone map */
169extern void zprealloc(
170 zone_t zone,
171 vm_size_t size);
172
173/*
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.
179 */
180extern integer_t zone_free_count(zone_t zone);
181
182/*
183 * Item definitions for zone_change:
184 */
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. */
190
191#ifdef __APPLE_API_PRIVATE
192
193#ifdef MACH_KERNEL_PRIVATE
194
195#if ZONE_DEBUG
196
197#if MACH_KDB
198
199extern vm_offset_t next_element(
200 zone_t z,
201 vm_offset_t elt);
202
203extern vm_offset_t first_element(
204 zone_t z);
205
206#endif /* MACH_KDB */
207
208extern void zone_debug_enable(
209 zone_t z);
210
211extern void zone_debug_disable(
212 zone_t z);
213
214#endif /* ZONE_DEBUG */
215
216#endif MACH_KERNEL_PRIVATE
217
218#endif /* __APPLE_API_PRIVATE */
219
220#endif /* _KERN_ZALLOC_H_ */