1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#ifndef _VM_TASK_WORKING_SET_H_
35#define _VM_TASK_WORKING_SET_H_
36
37#include <mach/mach_types.h>
38
39#ifdef KERNEL_PRIVATE
40
41#ifdef MACH_KERNEL_PRIVATE
42
43#include <kern/queue.h>
44#include <vm/vm_object.h>
45
46
47
48#define tws_lock(tws) mutex_lock(&(tws)->lock)
49#define tws_lock_try(tws) mutex_try(&(tws)->lock)
50#define tws_unlock(tws) mutex_unlock(&(tws)->lock)
51
52
53#define TWS_ARRAY_SIZE 8
54#define TWS_HASH_LINE_COUNT 32
55
56
57#define TWS_SMALL_HASH_LINE_COUNT 4
58
59
60
61
62
63#define do_tws_hash(object,offset, rows, lines) \
64 ((((((natural_t)(object)) + \
65 (((natural_t)(object)) >> 6) + \
66 (((natural_t)(object)) >> 12) + \
67 (((natural_t)(object)) >> 18) + \
68 (((natural_t)(object)) >> 24)) << 5) + \
69 ((natural_t)(((vm_object_offset_t)(offset)) >> 17))) & \
70 ((rows * lines) -1))
71
72
73#define alt_tws_hash(addr, rows, lines) \
74 ((((natural_t)(addr)) >> 17) & \
75 ((rows * lines) -1))
76
77
78
79
80#define TWS_STARTUP_MAX_HASH_RETRY 3
81
82
83
84
85
86
87
88
89
90#define do_startup_hash(addr, hash_size) \
91 (((((natural_t)(addr)) >> 17) * 3) & \
92 (hash_size -1))
93
94
95
96struct tws_startup_ele {
97 unsigned int page_cache;
98 vm_offset_t page_addr;
99};
100
101typedef struct tws_startup_ele *tws_startup_ele_t;
102
103
104struct tws_startup_ptr {
105 tws_startup_ele_t element;
106 struct tws_startup_ptr *next;
107};
108
109typedef struct tws_startup_ptr *tws_startup_ptr_t;
110
111struct tws_startup {
112 unsigned int tws_hash_size;
113 unsigned int ele_count;
114 unsigned int array_size;
115 unsigned int hash_count;
116
117 tws_startup_ptr_t *table;
118 struct tws_startup_ptr *ele;
119 struct tws_startup_ele *array;
120};
121
122typedef struct tws_startup *tws_startup_t;
123
124
125
126
127struct tws_hash_ele {
128 vm_object_t object;
129 vm_object_offset_t offset;
130 unsigned int page_cache;
131 vm_offset_t page_addr;
132 int line;
133 vm_map_t map;
134};
135typedef struct tws_hash_ele *tws_hash_ele_t;
136
137#define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000ULL)
138#define TWS_ADDR_OFF_MASK ((vm_offset_t)0xFFFE0000)
139#define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000ULL)
140
141struct tws_hash_ptr {
142 tws_hash_ele_t element;
143 struct tws_hash_ptr *next;
144};
145typedef struct tws_hash_ptr *tws_hash_ptr_t;
146
147struct tws_hash_line {
148 unsigned int ele_count;
149 struct tws_hash_ele list[TWS_ARRAY_SIZE];
150};
151typedef struct tws_hash_line *tws_hash_line_t;
152
153#define TWS_HASH_STYLE_DEFAULT 0x0
154#define TWS_HASH_STYLE_BASIC 0x1
155#define TWS_HASH_STYLE_SIGNAL 0x2
156
157
158#define TWS_ADDR_HASH 1
159#define TWS_HASH_EXPANSION_MAX 10
160#define TWS_MAX_REHASH 3
161
162
163struct tws_hash {
164 decl_mutex_data(,lock)
165 int style;
166
167 unsigned int current_line;
168 unsigned int pageout_count;
169 unsigned int line_count;
170
171 unsigned int number_of_lines;
172 unsigned int number_of_elements;
173 unsigned int expansion_count;
174 unsigned int time_of_creation;
175
176 unsigned int lookup_count;
177 unsigned int insert_count;
178
179 tws_startup_t startup_cache;
180 char *startup_name;
181 int startup_name_length;
182 unsigned int uid;
183 int mod;
184 int fid;
185
186 unsigned int obj_free_count[TWS_HASH_EXPANSION_MAX];
187 unsigned int addr_free_count[TWS_HASH_EXPANSION_MAX];
188 tws_hash_ptr_t free_hash_ele[TWS_HASH_EXPANSION_MAX];
189 tws_hash_ptr_t *table[TWS_HASH_EXPANSION_MAX];
190 tws_hash_ptr_t table_ele[TWS_HASH_EXPANSION_MAX];
191 tws_hash_ptr_t alt_ele[TWS_HASH_EXPANSION_MAX];
192 struct tws_hash_line *cache[TWS_HASH_EXPANSION_MAX];
193};
194
195typedef struct tws_hash *tws_hash_t;
196
197
198extern kern_return_t tws_lookup(
199 tws_hash_t tws,
200 vm_object_offset_t offset,
201 vm_object_t object,
202 tws_hash_line_t *line);
203
204extern kern_return_t tws_insert(
205 tws_hash_t tws,
206 vm_object_offset_t offset,
207 vm_object_t object,
208 vm_offset_t page_addr,
209 vm_map_t map);
210
211extern void tws_build_cluster(
212 tws_hash_t tws,
213 vm_object_t object,
214 vm_object_offset_t *start,
215 vm_object_offset_t *end,
216 vm_size_t max_length);
217
218extern void tws_line_signal(
219 tws_hash_t tws,
220 vm_map_t map,
221 tws_hash_line_t hash_line,
222 vm_offset_t target_page);
223
224extern void tws_hash_destroy(
225 tws_hash_t tws);
226
227extern void tws_hash_ws_flush(
228 tws_hash_t tws);
229
230extern kern_return_t tws_expand_working_set(
231 tws_hash_t old_tws,
232 unsigned int line_count,
233 boolean_t dump_data);
234
235extern kern_return_t task_working_set_create(
236 task_t task,
237 unsigned int lines,
238 unsigned int rows,
239 unsigned int style);
240
241#endif
242
243extern kern_return_t tws_handle_startup_file(
244 task_t task,
245 unsigned int uid,
246 char *app_name,
247 void *app_vp,
248 boolean_t *new_info);
249
250extern kern_return_t tws_send_startup_info(
251 task_t task);
252
253#endif
254
255#endif
256