]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/task_working_set.h
ea1a9502627860918a1837b1181116a92bf215bc
[apple/xnu.git] / osfmk / vm / task_working_set.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 */
32
33 /*
34 * File: vm/task_working_set.h
35 * Author: Chris Youngworth
36 * Date: 2001
37 *
38 * Working set detection and maintainence module
39 *
40 */
41
42 #ifndef _VM_TASK_WORKING_SET_H_
43 #define _VM_TASK_WORKING_SET_H_
44
45 #include <mach/mach_types.h>
46
47 #ifdef KERNEL_PRIVATE
48
49 #ifdef MACH_KERNEL_PRIVATE
50
51 #include <kern/queue.h>
52 #include <vm/vm_object.h>
53
54 /* task working set */
55
56 #define tws_lock(tws) mutex_lock(&(tws)->lock)
57 #define tws_lock_try(tws) mutex_try(&(tws)->lock)
58 #define tws_unlock(tws) mutex_unlock(&(tws)->lock)
59
60
61 #define TWS_ARRAY_SIZE 8
62 #define TWS_HASH_LINE_COUNT 32
63 /* start out size to allow monitoring of working set without excessive use */
64 /* of wired memory resource. */
65 #define TWS_SMALL_HASH_LINE_COUNT 4
66
67 /*
68 * do not think of changing this hash unless you understand the implications
69 * for the hash element page_cache field
70 */
71 #define do_tws_hash(object,offset, rows, lines) \
72 ((((((natural_t)(object)) + \
73 (((natural_t)(object)) >> 6) + \
74 (((natural_t)(object)) >> 12) + \
75 (((natural_t)(object)) >> 18) + \
76 (((natural_t)(object)) >> 24)) << 5) + \
77 ((natural_t)(((vm_object_offset_t)(offset)) >> 17))) & \
78 ((rows * lines) -1))
79
80
81 #define alt_tws_hash(addr, rows, lines) \
82 ((((natural_t)(addr)) >> 17) & \
83 ((rows * lines) -1))
84
85
86 /* Long term startup data structures for initial cache filling */
87
88 #define TWS_STARTUP_MAX_HASH_RETRY 3
89
90 /* 87 is the wrap skew, its based on RETRY times the RETRY offset of 29 */
91 /*
92 #define do_startup_hash(addr, hash_size) \
93 ((((((natural_t)(addr)) >> 17) & \
94 ((2 * (hash_size)) -1)) + \
95 (87 * (((addr) & TWS_ADDR_OFF_MASK)/(2 * (hash_size))))) & \
96 ((2 * (hash_size)) -1))
97 */
98 #define do_startup_hash(addr, hash_size) \
99 (((((natural_t)(addr)) >> 17) * 3) & \
100 (hash_size -1))
101
102
103
104 struct tws_startup_ele {
105 unsigned int page_cache;
106 vm_offset_t page_addr;
107 };
108
109 typedef struct tws_startup_ele *tws_startup_ele_t;
110
111
112 struct tws_startup_ptr {
113 tws_startup_ele_t element;
114 struct tws_startup_ptr *next;
115 };
116
117 typedef struct tws_startup_ptr *tws_startup_ptr_t;
118
119 struct tws_startup {
120 unsigned int tws_hash_size; /* total size of struct in bytes */
121 unsigned int ele_count;
122 unsigned int array_size; /* lines * rows * expansion_count */
123 unsigned int hash_count;
124
125 tws_startup_ptr_t *table; /* hash table */
126 struct tws_startup_ptr *ele; /* hash elements */
127 struct tws_startup_ele *array;
128 };
129
130 typedef struct tws_startup *tws_startup_t;
131
132
133 /* Dynamic cache data structures for working set */
134
135 struct tws_hash_ele {
136 vm_object_t object;
137 vm_object_offset_t offset;
138 unsigned int page_cache;
139 vm_offset_t page_addr;
140 int line;
141 vm_map_t map;
142 };
143 typedef struct tws_hash_ele *tws_hash_ele_t;
144
145 #define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000ULL)
146 #define TWS_ADDR_OFF_MASK ((vm_offset_t)0xFFFE0000)
147 #define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000ULL)
148
149 struct tws_hash_ptr {
150 tws_hash_ele_t element;
151 struct tws_hash_ptr *next;
152 };
153 typedef struct tws_hash_ptr *tws_hash_ptr_t;
154
155 struct tws_hash_line {
156 unsigned int ele_count;
157 struct tws_hash_ele list[TWS_ARRAY_SIZE];
158 };
159 typedef struct tws_hash_line *tws_hash_line_t;
160
161 #define TWS_HASH_STYLE_DEFAULT 0x0
162 #define TWS_HASH_STYLE_BASIC 0x1
163 #define TWS_HASH_STYLE_SIGNAL 0x2
164
165
166 #define TWS_ADDR_HASH 1
167 #define TWS_HASH_EXPANSION_MAX 10
168 #define TWS_MAX_REHASH 3
169
170
171 struct tws_hash {
172 decl_mutex_data(,lock) /* tws_hash's lock */
173 int style;
174
175 unsigned int current_line;
176 unsigned int pageout_count;
177 unsigned int line_count;
178
179 unsigned int number_of_lines;
180 unsigned int number_of_elements;
181 unsigned int expansion_count;
182 unsigned int time_of_creation;
183
184 unsigned int lookup_count;
185 unsigned int insert_count;
186
187 tws_startup_t startup_cache;
188 char *startup_name;
189 int startup_name_length;
190 unsigned int uid;
191 int mod;
192 int fid;
193
194 unsigned int obj_free_count[TWS_HASH_EXPANSION_MAX];
195 unsigned int addr_free_count[TWS_HASH_EXPANSION_MAX];
196 tws_hash_ptr_t free_hash_ele[TWS_HASH_EXPANSION_MAX];
197 tws_hash_ptr_t *table[TWS_HASH_EXPANSION_MAX];
198 tws_hash_ptr_t table_ele[TWS_HASH_EXPANSION_MAX];
199 tws_hash_ptr_t alt_ele[TWS_HASH_EXPANSION_MAX];
200 struct tws_hash_line *cache[TWS_HASH_EXPANSION_MAX];
201 };
202
203 typedef struct tws_hash *tws_hash_t;
204
205
206 extern kern_return_t tws_lookup(
207 tws_hash_t tws,
208 vm_object_offset_t offset,
209 vm_object_t object,
210 tws_hash_line_t *line);
211
212 extern kern_return_t tws_insert(
213 tws_hash_t tws,
214 vm_object_offset_t offset,
215 vm_object_t object,
216 vm_offset_t page_addr,
217 vm_map_t map);
218
219 extern void tws_build_cluster(
220 tws_hash_t tws,
221 vm_object_t object,
222 vm_object_offset_t *start,
223 vm_object_offset_t *end,
224 vm_size_t max_length);
225
226 extern void tws_line_signal(
227 tws_hash_t tws,
228 vm_map_t map,
229 tws_hash_line_t hash_line,
230 vm_offset_t target_page);
231
232 extern void tws_hash_destroy(
233 tws_hash_t tws);
234
235 extern void tws_hash_ws_flush(
236 tws_hash_t tws);
237
238 extern kern_return_t tws_expand_working_set(
239 tws_hash_t old_tws,
240 unsigned int line_count,
241 boolean_t dump_data);
242
243 extern kern_return_t task_working_set_create(
244 task_t task,
245 unsigned int lines,
246 unsigned int rows,
247 unsigned int style);
248
249 #endif /* MACH_KERNEL_PRIVATE */
250
251 extern kern_return_t tws_handle_startup_file(
252 task_t task,
253 unsigned int uid,
254 char *app_name,
255 void *app_vp,
256 boolean_t *new_info);
257
258 extern kern_return_t tws_send_startup_info(
259 task_t task);
260
261 #endif /* KERNEL_PRIVATE */
262
263 #endif /* _VM_TASK_WORKING_SET_H_ */