]>
Commit | Line | Data |
---|---|---|
0b4e3aa0 A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | */ | |
24 | ||
25 | /* | |
26 | * File: vm/task_working_set.h | |
27 | * Author: Chris Youngworth | |
28 | * Date: 2001 | |
29 | * | |
30 | * Working set detection and maintainence module | |
31 | * | |
32 | */ | |
33 | ||
34 | #ifndef _VM_TASK_WORKING_SET_H_ | |
35 | #define _VM_TASK_WORKING_SET_H_ | |
36 | ||
37 | #include <kern/queue.h> | |
38 | #include <vm/vm_object.h> | |
39 | ||
40 | /* task working set */ | |
41 | ||
42 | #define tws_lock(tws) mutex_lock(&(tws)->lock) | |
43 | #define tws_lock_try(tws) mutex_try(&(tws)->lock) | |
44 | #define tws_unlock(tws) mutex_unlock(&(tws)->lock) | |
45 | ||
46 | ||
47 | #define TWS_ARRAY_SIZE 8 | |
48 | #define TWS_HASH_LINE_COUNT 32 | |
49 | /* start out size to allow monitoring of working set without excessive use */ | |
50 | /* of wired memory resource. */ | |
51 | #define TWS_SMALL_HASH_LINE_COUNT 4 | |
52 | ||
53 | /* | |
54 | #define do_tws_hash(object,offset, rows, lines) \ | |
55 | ((((natural_t)(object)) + \ | |
56 | (((natural_t)(offset)) >> 11) + \ | |
57 | (((natural_t)(offset)) >> 12)) & \ | |
58 | ((2 * rows * lines) -1)) | |
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)) >> 2) + \ | |
66 | ((natural_t)(object) >> 12) + \ | |
67 | ((natural_t)(((vm_object_offset_t)(offset)) >> 12) \ | |
68 | & 0xFFFFFFFFFFFFFFE0)) & \ | |
69 | ((2 * rows * lines) -1)) | |
70 | /* | |
71 | #define do_tws_hash(object,offset, rows, lines) \ | |
72 | (((((natural_t)(object)) >> 2) + \ | |
73 | ((natural_t)(object) << 5) + \ | |
74 | ((natural_t)(((vm_object_offset_t)(offset)) >> 17))) & \ | |
75 | ((2 * rows * lines) -1)) | |
76 | */ | |
77 | ||
78 | ||
79 | #define alt_tws_hash(addr, rows, lines) \ | |
80 | ((((natural_t)(addr)) >> 12) & \ | |
81 | ((2 * rows * lines) -1)) | |
82 | ||
83 | struct tws_hash_ele { | |
84 | vm_object_t object; | |
85 | vm_object_offset_t offset; | |
86 | unsigned int page_cache; | |
87 | vm_offset_t page_addr; | |
88 | int line; | |
89 | vm_map_t map; | |
90 | }; | |
91 | typedef struct tws_hash_ele *tws_hash_ele_t; | |
92 | ||
93 | #define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000) | |
94 | #define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000) | |
95 | ||
96 | struct tws_hash_line { | |
97 | int ele_count; | |
98 | struct tws_hash_ele list[TWS_ARRAY_SIZE]; | |
99 | }; | |
100 | typedef struct tws_hash_line *tws_hash_line_t; | |
101 | ||
102 | #define TWS_HASH_STYLE_DEFAULT 0x0 | |
103 | #define TWS_HASH_STYLE_BASIC 0x1 | |
104 | #define TWS_HASH_STYLE_SIGNAL 0x2 | |
105 | ||
106 | ||
107 | #define TWS_HASH_EXPANSION_MAX 5 | |
108 | #define TWS_MAX_REHASH 2 | |
109 | ||
110 | ||
111 | struct tws_hash { | |
112 | decl_mutex_data(,lock) /* tws_hash's lock */ | |
113 | int style; | |
114 | ||
115 | int current_line; | |
116 | unsigned int pageout_count; | |
117 | int line_count; | |
118 | ||
119 | int number_of_lines; | |
120 | int number_of_elements; | |
121 | int expansion_count; | |
122 | unsigned int time_of_creation; | |
123 | ||
124 | int lookup_count; | |
125 | int insert_count; | |
126 | ||
127 | tws_hash_ele_t *table[TWS_HASH_EXPANSION_MAX]; | |
128 | tws_hash_ele_t *alt_table[TWS_HASH_EXPANSION_MAX]; | |
129 | struct tws_hash_line *cache[TWS_HASH_EXPANSION_MAX]; | |
130 | }; | |
131 | ||
132 | typedef struct tws_hash *tws_hash_t; | |
133 | ||
134 | ||
135 | extern tws_hash_t tws_hash_create(); | |
136 | ||
137 | extern void tws_hash_line_clear( | |
138 | tws_hash_t tws, | |
139 | tws_hash_line_t hash_line, | |
140 | boolean_t live); | |
141 | ||
142 | extern kern_return_t tws_lookup( | |
143 | tws_hash_t tws, | |
144 | vm_object_offset_t offset, | |
145 | vm_object_t object, | |
146 | tws_hash_line_t *line); | |
147 | ||
148 | extern kern_return_t tws_insert( | |
149 | tws_hash_t tws, | |
150 | vm_object_offset_t offset, | |
151 | vm_object_t object, | |
152 | vm_offset_t page_addr, | |
153 | vm_map_t map); | |
154 | ||
155 | extern void tws_build_cluster( | |
156 | tws_hash_t tws, | |
157 | vm_object_t object, | |
158 | vm_object_offset_t *start, | |
159 | vm_object_offset_t *end, | |
160 | vm_size_t max_length); | |
161 | ||
162 | extern tws_line_signal( | |
163 | tws_hash_t tws, | |
164 | vm_map_t map, | |
165 | tws_hash_line_t hash_line, | |
166 | vm_offset_t target_page); | |
167 | ||
168 | extern void tws_hash_destroy( | |
169 | tws_hash_t tws); | |
170 | ||
171 | extern void tws_hash_clear( | |
172 | tws_hash_t tws); | |
173 | ||
174 | kern_return_t task_working_set_create( | |
175 | task_t task, | |
176 | unsigned int lines, | |
177 | unsigned int rows, | |
178 | unsigned int style); | |
179 | ||
180 | kern_return_t tws_expand_working_set( | |
181 | vm_offset_t old_tws, | |
182 | int line_count); | |
183 | ||
184 | ||
185 | #endif /* _VM_TASK_WORKING_SET_H_ */ |