]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/zalloc.h
xnu-344.34.tar.gz
[apple/xnu.git] / osfmk / kern / zalloc.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
de355530
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
de355530
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
de355530
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50/*
51 */
52/*
53 * File: zalloc.h
54 * Author: Avadis Tevanian, Jr.
55 * Date: 1985
56 *
57 */
58
59#ifndef _KERN_ZALLOC_H_
60#define _KERN_ZALLOC_H_
61
62#include <mach/machine/vm_types.h>
63#include <kern/kern_types.h>
64
9bccf70c
A
65#include <sys/appleapiopts.h>
66
67#ifdef __APPLE_API_PRIVATE
68
69#ifdef MACH_KERNEL_PRIVATE
70
1c79356b
A
71#include <zone_debug.h>
72#include <mach_kdb.h>
73#include <kern/lock.h>
74#include <kern/queue.h>
0b4e3aa0 75#include <kern/call_entry.h>
1c79356b
A
76
77/*
78 * A zone is a collection of fixed size blocks for which there
79 * is fast allocation/deallocation access. Kernel routines can
80 * use zones to manage data structures dynamically, creating a zone
81 * for each type of data structure to be managed.
82 *
83 */
84
85struct zone {
86 int count; /* Number of elements used now */
87 vm_offset_t free_elements;
88 vm_size_t cur_size; /* current memory utilization */
89 vm_size_t max_size; /* how large can this zone grow */
90 vm_size_t elem_size; /* size of an element */
91 vm_size_t alloc_size; /* size used for more memory */
92 char *zone_name; /* a name for the zone */
93 unsigned int
94 /* boolean_t */ exhaustible :1, /* (F) merely return if empty? */
95 /* boolean_t */ collectable :1, /* (F) garbage collect empty pages */
96 /* boolean_t */ expandable :1, /* (T) expand zone (with message)? */
97 /* boolean_t */ allows_foreign :1,/* (F) allow non-zalloc space */
98 /* boolean_t */ doing_alloc :1, /* is zone expanding now? */
0b4e3aa0
A
99 /* boolean_t */ waiting :1, /* is thread waiting for expansion? */
100 /* boolean_t */ async_pending :1; /* asynchronous allocation pending? */
1c79356b 101 struct zone * next_zone; /* Link for all-zones list */
0b4e3aa0 102 call_entry_data_t call_async_alloc; /* callout for asynchronous alloc */
1c79356b
A
103#if ZONE_DEBUG
104 queue_head_t active_zones; /* active elements */
105#endif /* ZONE_DEBUG */
106 decl_simple_lock_data(,lock) /* generic lock */
107};
108
1c79356b
A
109extern void zone_gc(void);
110extern void consider_zone_gc(void);
111
112/* Steal memory for zone module */
113extern void zone_steal_memory(void);
114
115/* Bootstrap zone module (create zone zone) */
116extern void zone_bootstrap(void);
117
118/* Init zone module */
119extern void zone_init(vm_size_t);
120
9bccf70c 121#endif /* MACH_KERNEL_PRIVATE */
1c79356b 122
9bccf70c 123#endif /* __APPLE_API_PRIVATE */
1c79356b
A
124
125/* Allocate from zone */
126extern vm_offset_t zalloc(
127 zone_t zone);
128
129/* Non-blocking version of zalloc */
130extern vm_offset_t zalloc_noblock(
131 zone_t zone);
132
133/* Get from zone free list */
134extern vm_offset_t zget(
135 zone_t zone);
136
137/* Create zone */
138extern zone_t zinit(
139 vm_size_t size, /* the size of an element */
140 vm_size_t max, /* maximum memory to use */
141 vm_size_t alloc, /* allocation size */
142 char *name); /* a name for the zone */
143
144/* Free zone element */
145extern void zfree(
146 zone_t zone,
147 vm_offset_t elem);
148
149/* Fill zone with memory */
150extern void zcram(
151 zone_t zone,
152 vm_offset_t newmem,
153 vm_size_t size);
154
155/* Initially fill zone with specified number of elements */
156extern int zfill(
157 zone_t zone,
158 int nelem);
159/* Change zone parameters */
160extern void zone_change(
161 zone_t zone,
162 unsigned int item,
163 boolean_t value);
164
165/* Preallocate space for zone from zone map */
166extern void zprealloc(
167 zone_t zone,
168 vm_size_t size);
169
170/*
171 * zone_free_count returns a hint as to the current number of free elements
172 * in the zone. By the time it returns, it may no longer be true (a new
173 * element might have been added, or an element removed).
174 * This routine may be used in conjunction with zcram and a lock to regulate
175 * adding memory to a non-expandable zone.
176 */
177extern integer_t zone_free_count(zone_t zone);
178
179/*
180 * Item definitions for zone_change:
181 */
182#define Z_EXHAUST 1 /* Make zone exhaustible */
183#define Z_COLLECT 2 /* Make zone collectable */
184#define Z_EXPAND 3 /* Make zone expandable */
185#define Z_FOREIGN 4 /* Allow collectable zone to contain foreign */
186 /* (not allocated via zalloc) elements. */
9bccf70c
A
187
188#ifdef __APPLE_API_PRIVATE
189
190#ifdef MACH_KERNEL_PRIVATE
191
1c79356b 192#if ZONE_DEBUG
9bccf70c 193
1c79356b 194#if MACH_KDB
9bccf70c 195
1c79356b
A
196extern vm_offset_t next_element(
197 zone_t z,
198 vm_offset_t elt);
199
200extern vm_offset_t first_element(
201 zone_t z);
9bccf70c 202
1c79356b 203#endif /* MACH_KDB */
9bccf70c 204
1c79356b
A
205extern void zone_debug_enable(
206 zone_t z);
207
208extern void zone_debug_disable(
209 zone_t z);
9bccf70c 210
1c79356b 211#endif /* ZONE_DEBUG */
9bccf70c
A
212
213#endif MACH_KERNEL_PRIVATE
214
215#endif /* __APPLE_API_PRIVATE */
1c79356b
A
216
217#endif /* _KERN_ZALLOC_H_ */