2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * File: vm/task_working_set.h
27 * Author: Chris Youngworth
30 * Working set detection and maintainence module
34 #ifndef _VM_TASK_WORKING_SET_H_
35 #define _VM_TASK_WORKING_SET_H_
37 #include <kern/queue.h>
38 #include <vm/vm_object.h>
40 /* task working set */
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)
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
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))
61 * do not think of changing this hash unless you understand the implications
62 * for the hash element page_cache field
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))
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))
79 #define alt_tws_hash(addr, rows, lines) \
80 ((((natural_t)(addr)) >> 12) & \
81 ((2 * rows * lines) -1))
85 vm_object_offset_t offset
;
86 unsigned int page_cache
;
87 vm_offset_t page_addr
;
91 typedef struct tws_hash_ele
*tws_hash_ele_t
;
93 #define TWS_HASH_OFF_MASK ((vm_object_offset_t)0xFFFFFFFFFFFE0000)
94 #define TWS_INDEX_MASK ((vm_object_offset_t)0x000000000001F000)
96 struct tws_hash_line
{
98 struct tws_hash_ele list
[TWS_ARRAY_SIZE
];
100 typedef struct tws_hash_line
*tws_hash_line_t
;
102 #define TWS_HASH_STYLE_DEFAULT 0x0
103 #define TWS_HASH_STYLE_BASIC 0x1
104 #define TWS_HASH_STYLE_SIGNAL 0x2
107 #define TWS_HASH_EXPANSION_MAX 5
108 #define TWS_MAX_REHASH 2
112 decl_mutex_data(,lock
) /* tws_hash's lock */
116 unsigned int pageout_count
;
120 int number_of_elements
;
122 unsigned int time_of_creation
;
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
];
132 typedef struct tws_hash
*tws_hash_t
;
135 extern tws_hash_t
tws_hash_create();
137 extern void tws_hash_line_clear(
139 tws_hash_line_t hash_line
,
142 extern kern_return_t
tws_lookup(
144 vm_object_offset_t offset
,
146 tws_hash_line_t
*line
);
148 extern kern_return_t
tws_insert(
150 vm_object_offset_t offset
,
152 vm_offset_t page_addr
,
155 extern void tws_build_cluster(
158 vm_object_offset_t
*start
,
159 vm_object_offset_t
*end
,
160 vm_size_t max_length
);
162 extern tws_line_signal(
165 tws_hash_line_t hash_line
,
166 vm_offset_t target_page
);
168 extern void tws_hash_destroy(
171 extern void tws_hash_clear(
174 kern_return_t
task_working_set_create(
180 kern_return_t
tws_expand_working_set(
185 #endif /* _VM_TASK_WORKING_SET_H_ */