]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 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. | |
1c79356b | 11 | * |
e5568f75 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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 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. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: vm/vm_page.h | |
54 | * Author: Avadis Tevanian, Jr., Michael Wayne Young | |
55 | * Date: 1985 | |
56 | * | |
57 | * Resident memory system definitions. | |
58 | */ | |
59 | ||
60 | #ifndef _VM_VM_PAGE_H_ | |
61 | #define _VM_VM_PAGE_H_ | |
62 | ||
63 | #include <mach/boolean.h> | |
64 | #include <mach/vm_prot.h> | |
65 | #include <mach/vm_param.h> | |
66 | #include <vm/vm_object.h> | |
67 | #include <kern/queue.h> | |
68 | #include <kern/lock.h> | |
69 | ||
70 | #include <kern/macro_help.h> | |
71 | ||
0b4e3aa0 A |
72 | /* |
73 | * Each page entered on the inactive queue obtains a ticket from a | |
74 | * particular ticket roll. Pages granted tickets from a particular | |
75 | * roll generally flow through the queue as a group. In this way when a | |
76 | * page with a ticket from a particular roll is pulled from the top of the | |
77 | * queue it is extremely likely that the pages near the top will have tickets | |
78 | * from the same or adjacent rolls. In this way the proximity to the top | |
79 | * of the queue can be loosely ascertained by determining the identity of | |
80 | * the roll the pages ticket came from. | |
81 | */ | |
82 | ||
83 | ||
84 | extern int vm_page_ticket_roll; | |
85 | extern int vm_page_ticket; | |
86 | ||
9bccf70c | 87 | |
0b4e3aa0 A |
88 | #define VM_PAGE_TICKETS_IN_ROLL 512 |
89 | #define VM_PAGE_TICKET_ROLL_IDS 16 | |
90 | ||
1c79356b A |
91 | /* |
92 | * Management of resident (logical) pages. | |
93 | * | |
94 | * A small structure is kept for each resident | |
95 | * page, indexed by page number. Each structure | |
96 | * is an element of several lists: | |
97 | * | |
98 | * A hash table bucket used to quickly | |
99 | * perform object/offset lookups | |
100 | * | |
101 | * A list of all pages for a given object, | |
102 | * so they can be quickly deactivated at | |
103 | * time of deallocation. | |
104 | * | |
105 | * An ordered list of pages due for pageout. | |
106 | * | |
107 | * In addition, the structure contains the object | |
108 | * and offset to which this page belongs (for pageout), | |
109 | * and sundry status bits. | |
110 | * | |
111 | * Fields in this structure are locked either by the lock on the | |
112 | * object that the page belongs to (O) or by the lock on the page | |
113 | * queues (P). [Some fields require that both locks be held to | |
114 | * change that field; holding either lock is sufficient to read.] | |
115 | */ | |
116 | ||
117 | struct vm_page { | |
118 | queue_chain_t pageq; /* queue info for FIFO | |
119 | * queue or free list (P) */ | |
120 | queue_chain_t listq; /* all pages in same object (O) */ | |
121 | struct vm_page *next; /* VP bucket link (O) */ | |
122 | ||
123 | vm_object_t object; /* which object am I in (O&P) */ | |
124 | vm_object_offset_t offset; /* offset into that object (O,P) */ | |
125 | ||
126 | unsigned int wire_count:16, /* how many wired down maps use me? (O&P) */ | |
0b4e3aa0 A |
127 | page_ticket:4, /* age of the page on the */ |
128 | /* inactive queue. */ | |
1c79356b A |
129 | /* boolean_t */ inactive:1, /* page is in inactive list (P) */ |
130 | active:1, /* page is in active list (P) */ | |
131 | laundry:1, /* page is being cleaned now (P)*/ | |
132 | free:1, /* page is on free list (P) */ | |
133 | reference:1, /* page has been used (P) */ | |
1c79356b | 134 | pageout:1, /* page wired & busy for pageout (P) */ |
0b4e3aa0 A |
135 | gobbled:1, /* page used internally (P) */ |
136 | private:1, /* Page should not be returned to | |
137 | * the free list (O) */ | |
9bccf70c | 138 | zero_fill:1, |
0b4e3aa0 | 139 | :0; |
1c79356b A |
140 | |
141 | unsigned int | |
0b4e3aa0 | 142 | page_error:8, /* error from I/O operations */ |
1c79356b A |
143 | /* boolean_t */ busy:1, /* page is in transit (O) */ |
144 | wanted:1, /* someone is waiting for page (O) */ | |
145 | tabled:1, /* page is in VP table (O) */ | |
146 | fictitious:1, /* Physical page doesn't exist (O) */ | |
0b4e3aa0 | 147 | no_isync:1, /* page has not been instruction synced */ |
1c79356b A |
148 | absent:1, /* Data has been requested, but is |
149 | * not yet available (O) */ | |
150 | error:1, /* Data manager was unable to provide | |
151 | * data due to error (O) */ | |
152 | dirty:1, /* Page must be cleaned (O) */ | |
153 | cleaning:1, /* Page clean has begun (O) */ | |
154 | precious:1, /* Page is precious; data must be | |
155 | * returned even if clean (O) */ | |
156 | clustered:1, /* page is not the faulted page (O) */ | |
157 | overwriting:1, /* Request to unlock has been made | |
158 | * without having data. (O) | |
159 | * [See vm_fault_page_overwrite] */ | |
160 | restart:1, /* Page was pushed higher in shadow | |
161 | chain by copy_call-related pagers; | |
162 | start again at top of chain */ | |
163 | lock_supplied:1,/* protection supplied by pager (O) */ | |
164 | /* vm_prot_t */ page_lock:3, /* Uses prohibited by pager (O) */ | |
165 | /* vm_prot_t */ unlock_request:3,/* Outstanding unlock request (O) */ | |
166 | unusual:1, /* Page is absent, error, restart or | |
167 | page locked */ | |
168 | discard_request:1,/* a memory_object_discard_request() | |
169 | * has been sent */ | |
170 | list_req_pending:1, /* pagein/pageout alt mechanism */ | |
171 | /* allows creation of list */ | |
172 | /* requests on pages that are */ | |
173 | /* actively being paged. */ | |
0b4e3aa0 A |
174 | dump_cleaning:1; /* set by the pageout daemon when */ |
175 | /* a page being cleaned is */ | |
176 | /* encountered and targeted as */ | |
177 | /* a pageout candidate */ | |
178 | /* we've used up all 32 bits */ | |
1c79356b | 179 | |
55e303ae | 180 | vm_offset_t phys_page; /* Physical address of page, passed |
1c79356b | 181 | * to pmap_enter (read-only) */ |
1c79356b A |
182 | }; |
183 | ||
184 | typedef struct vm_page *vm_page_t; | |
185 | ||
1c79356b | 186 | #define VM_PAGE_NULL ((vm_page_t) 0) |
e5568f75 A |
187 | #define NEXT_PAGE(m) ((vm_page_t) (m)->pageq.next) |
188 | #define NEXT_PAGE_PTR(m) ((vm_page_t *) &(m)->pageq.next) | |
1c79356b A |
189 | |
190 | /* | |
191 | * XXX The unusual bit should not be necessary. Most of the bit | |
192 | * XXX fields above really want to be masks. | |
193 | */ | |
194 | ||
195 | /* | |
196 | * For debugging, this macro can be defined to perform | |
197 | * some useful check on a page structure. | |
198 | */ | |
199 | ||
200 | #define VM_PAGE_CHECK(mem) | |
201 | ||
202 | /* | |
203 | * Each pageable resident page falls into one of three lists: | |
204 | * | |
205 | * free | |
206 | * Available for allocation now. | |
207 | * inactive | |
208 | * Not referenced in any map, but still has an | |
209 | * object/offset-page mapping, and may be dirty. | |
210 | * This is the list of pages that should be | |
211 | * paged out next. | |
212 | * active | |
213 | * A list of pages which have been placed in | |
214 | * at least one physical map. This list is | |
215 | * ordered, in LRU-like fashion. | |
216 | */ | |
217 | ||
218 | extern | |
219 | vm_page_t vm_page_queue_free; /* memory free queue */ | |
220 | extern | |
221 | vm_page_t vm_page_queue_fictitious; /* fictitious free queue */ | |
222 | extern | |
223 | queue_head_t vm_page_queue_active; /* active memory queue */ | |
224 | extern | |
225 | queue_head_t vm_page_queue_inactive; /* inactive memory queue */ | |
9bccf70c | 226 | queue_head_t vm_page_queue_zf; /* inactive memory queue for zero fill */ |
1c79356b A |
227 | |
228 | extern | |
229 | vm_offset_t first_phys_addr; /* physical address for first_page */ | |
230 | extern | |
231 | vm_offset_t last_phys_addr; /* physical address for last_page */ | |
232 | ||
233 | extern | |
234 | int vm_page_free_count; /* How many pages are free? */ | |
235 | extern | |
236 | int vm_page_fictitious_count;/* How many fictitious pages are free? */ | |
237 | extern | |
238 | int vm_page_active_count; /* How many pages are active? */ | |
239 | extern | |
240 | int vm_page_inactive_count; /* How many pages are inactive? */ | |
241 | extern | |
242 | int vm_page_wire_count; /* How many pages are wired? */ | |
243 | extern | |
244 | int vm_page_free_target; /* How many do we want free? */ | |
245 | extern | |
246 | int vm_page_free_min; /* When to wakeup pageout */ | |
247 | extern | |
248 | int vm_page_inactive_target;/* How many do we want inactive? */ | |
249 | extern | |
250 | int vm_page_free_reserved; /* How many pages reserved to do pageout */ | |
251 | extern | |
252 | int vm_page_laundry_count; /* How many pages being laundered? */ | |
55e303ae A |
253 | extern |
254 | int vm_page_burst_count; /* How many pages being laundered to EMM? */ | |
255 | extern | |
256 | int vm_page_throttled_count;/* Count of zero-fill allocations throttled */ | |
1c79356b A |
257 | |
258 | decl_mutex_data(,vm_page_queue_lock) | |
259 | /* lock on active and inactive page queues */ | |
260 | decl_mutex_data(,vm_page_queue_free_lock) | |
261 | /* lock on free page queue */ | |
262 | decl_simple_lock_data(extern,vm_page_preppin_lock) /* lock for prep/pin */ | |
9bccf70c | 263 | decl_mutex_data(,vm_page_zero_fill_lock) |
1c79356b A |
264 | |
265 | extern unsigned int vm_page_free_wanted; | |
266 | /* how many threads are waiting for memory */ | |
267 | ||
268 | extern vm_offset_t vm_page_fictitious_addr; | |
269 | /* (fake) phys_addr of fictitious pages */ | |
270 | ||
271 | /* | |
272 | * Prototypes for functions exported by this module. | |
273 | */ | |
274 | extern void vm_page_bootstrap( | |
275 | vm_offset_t *startp, | |
276 | vm_offset_t *endp); | |
277 | ||
278 | extern void vm_page_module_init(void); | |
279 | ||
280 | extern void vm_page_create( | |
55e303ae A |
281 | ppnum_t start, |
282 | ppnum_t end); | |
1c79356b A |
283 | |
284 | extern vm_page_t vm_page_lookup( | |
285 | vm_object_t object, | |
286 | vm_object_offset_t offset); | |
287 | ||
288 | extern vm_page_t vm_page_grab_fictitious(void); | |
289 | ||
290 | extern void vm_page_release_fictitious( | |
291 | vm_page_t page); | |
292 | ||
293 | extern boolean_t vm_page_convert( | |
294 | vm_page_t page); | |
295 | ||
296 | extern void vm_page_more_fictitious(void); | |
297 | ||
298 | extern int vm_pool_low(void); | |
299 | ||
300 | extern vm_page_t vm_page_grab(void); | |
301 | ||
302 | extern void vm_page_release( | |
303 | vm_page_t page); | |
304 | ||
305 | extern void vm_page_release_limbo( | |
306 | vm_page_t page); | |
307 | ||
308 | extern void vm_page_limbo_exchange( | |
309 | vm_page_t limbo_m, | |
310 | vm_page_t new_m); | |
311 | ||
312 | extern boolean_t vm_page_wait( | |
313 | int interruptible ); | |
314 | ||
315 | extern vm_page_t vm_page_alloc( | |
316 | vm_object_t object, | |
317 | vm_object_offset_t offset); | |
318 | ||
319 | extern void vm_page_init( | |
320 | vm_page_t page, | |
55e303ae | 321 | ppnum_t phys_page); |
1c79356b A |
322 | |
323 | extern void vm_page_free( | |
324 | vm_page_t page); | |
325 | ||
326 | extern void vm_page_activate( | |
327 | vm_page_t page); | |
328 | ||
329 | extern void vm_page_deactivate( | |
330 | vm_page_t page); | |
331 | ||
332 | extern void vm_page_rename( | |
333 | vm_page_t page, | |
334 | vm_object_t new_object, | |
335 | vm_object_offset_t new_offset); | |
336 | ||
337 | extern void vm_page_insert( | |
338 | vm_page_t page, | |
339 | vm_object_t object, | |
340 | vm_object_offset_t offset); | |
341 | ||
342 | extern void vm_page_replace( | |
343 | vm_page_t mem, | |
344 | vm_object_t object, | |
345 | vm_object_offset_t offset); | |
346 | ||
347 | extern void vm_page_remove( | |
348 | vm_page_t page); | |
349 | ||
350 | extern void vm_page_zero_fill( | |
351 | vm_page_t page); | |
352 | ||
353 | extern void vm_page_part_zero_fill( | |
354 | vm_page_t m, | |
355 | vm_offset_t m_pa, | |
356 | vm_size_t len); | |
357 | ||
358 | extern void vm_page_copy( | |
359 | vm_page_t src_page, | |
360 | vm_page_t dest_page); | |
361 | ||
362 | extern void vm_page_part_copy( | |
363 | vm_page_t src_m, | |
364 | vm_offset_t src_pa, | |
365 | vm_page_t dst_m, | |
366 | vm_offset_t dst_pa, | |
367 | vm_size_t len); | |
368 | ||
369 | extern void vm_page_wire( | |
370 | vm_page_t page); | |
371 | ||
372 | extern void vm_page_unwire( | |
373 | vm_page_t page); | |
374 | ||
375 | extern void vm_set_page_size(void); | |
376 | ||
377 | extern void vm_page_gobble( | |
378 | vm_page_t page); | |
379 | ||
1c79356b A |
380 | /* |
381 | * Functions implemented as macros. m->wanted and m->busy are | |
382 | * protected by the object lock. | |
383 | */ | |
384 | ||
385 | #define PAGE_ASSERT_WAIT(m, interruptible) \ | |
9bccf70c A |
386 | (((m)->wanted = TRUE), \ |
387 | assert_wait((event_t) (m), (interruptible))) | |
388 | ||
389 | #define PAGE_SLEEP(o, m, interruptible) \ | |
390 | (((m)->wanted = TRUE), \ | |
391 | thread_sleep_vm_object((o), (m), (interruptible))) | |
1c79356b A |
392 | |
393 | #define PAGE_WAKEUP_DONE(m) \ | |
394 | MACRO_BEGIN \ | |
395 | (m)->busy = FALSE; \ | |
396 | if ((m)->wanted) { \ | |
397 | (m)->wanted = FALSE; \ | |
398 | thread_wakeup((event_t) (m)); \ | |
399 | } \ | |
400 | MACRO_END | |
401 | ||
402 | #define PAGE_WAKEUP(m) \ | |
403 | MACRO_BEGIN \ | |
404 | if ((m)->wanted) { \ | |
405 | (m)->wanted = FALSE; \ | |
406 | thread_wakeup((event_t) (m)); \ | |
407 | } \ | |
408 | MACRO_END | |
409 | ||
410 | #define VM_PAGE_FREE(p) \ | |
411 | MACRO_BEGIN \ | |
412 | vm_page_lock_queues(); \ | |
413 | vm_page_free(p); \ | |
414 | vm_page_unlock_queues(); \ | |
415 | MACRO_END | |
416 | ||
417 | #define VM_PAGE_GRAB_FICTITIOUS(M) \ | |
418 | MACRO_BEGIN \ | |
419 | while ((M = vm_page_grab_fictitious()) == VM_PAGE_NULL) \ | |
420 | vm_page_more_fictitious(); \ | |
421 | MACRO_END | |
422 | ||
423 | #define VM_PAGE_THROTTLED() \ | |
55e303ae A |
424 | (vm_page_free_count < vm_page_free_min && \ |
425 | !current_thread()->vm_privilege && \ | |
426 | ++vm_page_throttled_count) | |
1c79356b A |
427 | |
428 | #define VM_PAGE_WAIT() ((void)vm_page_wait(THREAD_UNINT)) | |
429 | ||
430 | #define vm_page_lock_queues() mutex_lock(&vm_page_queue_lock) | |
431 | #define vm_page_unlock_queues() mutex_unlock(&vm_page_queue_lock) | |
432 | #define vm_page_pin_lock() simple_lock(&vm_page_preppin_lock) | |
433 | #define vm_page_pin_unlock() simple_unlock(&vm_page_preppin_lock) | |
434 | ||
435 | #define VM_PAGE_QUEUES_REMOVE(mem) \ | |
436 | MACRO_BEGIN \ | |
437 | if (mem->active) { \ | |
438 | assert(!mem->inactive); \ | |
439 | queue_remove(&vm_page_queue_active, \ | |
440 | mem, vm_page_t, pageq); \ | |
441 | mem->active = FALSE; \ | |
442 | if (!mem->fictitious) \ | |
443 | vm_page_active_count--; \ | |
444 | } \ | |
445 | \ | |
446 | if (mem->inactive) { \ | |
447 | assert(!mem->active); \ | |
9bccf70c A |
448 | if (mem->zero_fill) { \ |
449 | queue_remove(&vm_page_queue_zf, \ | |
450 | mem, vm_page_t, pageq); \ | |
451 | } else { \ | |
452 | queue_remove(&vm_page_queue_inactive, \ | |
1c79356b | 453 | mem, vm_page_t, pageq); \ |
9bccf70c | 454 | } \ |
1c79356b A |
455 | mem->inactive = FALSE; \ |
456 | if (!mem->fictitious) \ | |
457 | vm_page_inactive_count--; \ | |
458 | } \ | |
459 | MACRO_END | |
460 | ||
461 | #endif /* _VM_VM_PAGE_H_ */ |