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