]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/task_working_set.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / vm / task_working_set.h
CommitLineData
0b4e3aa0 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
0b4e3aa0 3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
0b4e3aa0 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
0b4e3aa0
A
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
91447636
A
37#include <mach/mach_types.h>
38
39#ifdef KERNEL_PRIVATE
40
41#ifdef MACH_KERNEL_PRIVATE
42
0b4e3aa0
A
43#include <kern/queue.h>
44#include <vm/vm_object.h>
45
46/* task working set */
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/* start out size to allow monitoring of working set without excessive use */
56/* of wired memory resource. */
57#define TWS_SMALL_HASH_LINE_COUNT 4
58
0b4e3aa0
A
59/*
60 * do not think of changing this hash unless you understand the implications
61 * for the hash element page_cache field
62 */
63#define do_tws_hash(object,offset, rows, lines) \
9bccf70c
A
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) + \
0b4e3aa0 69 ((natural_t)(((vm_object_offset_t)(offset)) >> 17))) & \
9bccf70c 70 ((rows * lines) -1))
0b4e3aa0
A
71
72
73#define alt_tws_hash(addr, rows, lines) \
9bccf70c
A
74 ((((natural_t)(addr)) >> 17) & \
75 ((rows * lines) -1))
76
77
78/* Long term startup data structures for initial cache filling */
79
80#define TWS_STARTUP_MAX_HASH_RETRY 3
81
82/* 87 is the wrap skew, its based on RETRY times the RETRY offset of 29 */
83/*
84#define do_startup_hash(addr, hash_size) \
85 ((((((natural_t)(addr)) >> 17) & \
86 ((2 * (hash_size)) -1)) + \
87 (87 * (((addr) & TWS_ADDR_OFF_MASK)/(2 * (hash_size))))) & \
88 ((2 * (hash_size)) -1))
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; /* total size of struct in bytes */
113 unsigned int ele_count;
114 unsigned int array_size; /* lines * rows * expansion_count */
115 unsigned int hash_count;
116
117 tws_startup_ptr_t *table; /* hash table */
118 struct tws_startup_ptr *ele; /* hash elements */
119 struct tws_startup_ele *array;
120};
121
122typedef struct tws_startup *tws_startup_t;
123
124
125/* Dynamic cache data structures for working set */
0b4e3aa0
A
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
91447636 137#define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000ULL)
9bccf70c 138#define TWS_ADDR_OFF_MASK ((vm_offset_t)0xFFFE0000)
91447636 139#define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000ULL)
0b4e3aa0 140
9bccf70c
A
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
0b4e3aa0 147struct tws_hash_line {
91447636 148 unsigned int ele_count;
0b4e3aa0
A
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
9bccf70c 158#define TWS_ADDR_HASH 1
483a1d10 159#define TWS_HASH_EXPANSION_MAX 10
9bccf70c 160#define TWS_MAX_REHASH 3
0b4e3aa0
A
161
162
163struct tws_hash {
164 decl_mutex_data(,lock) /* tws_hash's lock */
165 int style;
166
91447636 167 unsigned int current_line;
0b4e3aa0 168 unsigned int pageout_count;
91447636 169 unsigned int line_count;
0b4e3aa0 170
91447636
A
171 unsigned int number_of_lines;
172 unsigned int number_of_elements;
173 unsigned int expansion_count;
0b4e3aa0
A
174 unsigned int time_of_creation;
175
91447636
A
176 unsigned int lookup_count;
177 unsigned int insert_count;
0b4e3aa0 178
9bccf70c
A
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];
0b4e3aa0
A
192 struct tws_hash_line *cache[TWS_HASH_EXPANSION_MAX];
193};
194
195typedef struct tws_hash *tws_hash_t;
196
197
0b4e3aa0
A
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
91447636
A
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);
0b4e3aa0
A
223
224extern void tws_hash_destroy(
91447636
A
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 /* MACH_KERNEL_PRIVATE */
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);
90556fb8 249
91447636
A
250extern kern_return_t tws_send_startup_info(
251 task_t task);
0b4e3aa0 252
91447636 253#endif /* KERNEL_PRIVATE */
0b4e3aa0
A
254
255#endif /* _VM_TASK_WORKING_SET_H_ */