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