2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young
63 * Resident memory system definitions.
66 #ifndef _VM_VM_PAGE_H_
67 #define _VM_VM_PAGE_H_
71 #include <mach/boolean.h>
72 #include <mach/vm_prot.h>
73 #include <mach/vm_param.h>
74 #include <vm/vm_object.h>
75 #include <kern/queue.h>
76 #include <kern/lock.h>
78 #include <kern/macro_help.h>
79 #include <libkern/OSAtomic.h>
83 * VM_PAGE_MIN_SPECULATIVE_AGE_Q through VM_PAGE_MAX_SPECULATIVE_AGE_Q
84 * represents a set of aging bins that are 'protected'...
86 * VM_PAGE_SPECULATIVE_AGED_Q is a list of the speculative pages that have
87 * not yet been 'claimed' but have been aged out of the protective bins
88 * this occurs in vm_page_speculate when it advances to the next bin
89 * and discovers that it is still occupied... at that point, all of the
90 * pages in that bin are moved to the VM_PAGE_SPECULATIVE_AGED_Q. the pages
91 * in that bin are all guaranteed to have reached at least the maximum age
92 * we allow for a protected page... they can be older if there is no
93 * memory pressure to pull them from the bin, or there are no new speculative pages
94 * being generated to push them out.
95 * this list is the one that vm_pageout_scan will prefer when looking
96 * for pages to move to the underweight free list
98 * VM_PAGE_MAX_SPECULATIVE_AGE_Q * VM_PAGE_SPECULATIVE_Q_AGE_MS
99 * defines the amount of time a speculative page is normally
100 * allowed to live in the 'protected' state (i.e. not available
101 * to be stolen if vm_pageout_scan is running and looking for
102 * pages)... however, if the total number of speculative pages
103 * in the protected state exceeds our limit (defined in vm_pageout.c)
104 * and there are none available in VM_PAGE_SPECULATIVE_AGED_Q, then
105 * vm_pageout_scan is allowed to steal pages from the protected
106 * bucket even if they are underage.
108 * vm_pageout_scan is also allowed to pull pages from a protected
109 * bin if the bin has reached the "age of consent" we've set
111 #define VM_PAGE_MAX_SPECULATIVE_AGE_Q 10
112 #define VM_PAGE_MIN_SPECULATIVE_AGE_Q 1
113 #define VM_PAGE_SPECULATIVE_AGED_Q 0
115 #define VM_PAGE_SPECULATIVE_Q_AGE_MS 500
117 struct vm_speculative_age_q
{
119 * memory queue for speculative pages via clustered pageins
122 mach_timespec_t age_ts
;
128 struct vm_speculative_age_q vm_page_queue_speculative
[];
130 extern int speculative_steal_index
;
131 extern int speculative_age_index
;
132 extern unsigned int vm_page_speculative_q_age_ms
;
136 * Management of resident (logical) pages.
138 * A small structure is kept for each resident
139 * page, indexed by page number. Each structure
140 * is an element of several lists:
142 * A hash table bucket used to quickly
143 * perform object/offset lookups
145 * A list of all pages for a given object,
146 * so they can be quickly deactivated at
147 * time of deallocation.
149 * An ordered list of pages due for pageout.
151 * In addition, the structure contains the object
152 * and offset to which this page belongs (for pageout),
153 * and sundry status bits.
155 * Fields in this structure are locked either by the lock on the
156 * object that the page belongs to (O) or by the lock on the page
157 * queues (P). [Some fields require that both locks be held to
158 * change that field; holding either lock is sufficient to read.]
162 queue_chain_t pageq
; /* queue info for FIFO */
163 /* queue or free list (P) */
165 queue_chain_t listq
; /* all pages in same object (O) */
166 struct vm_page
*next
; /* VP bucket link (O) */
168 vm_object_t object
; /* which object am I in (O&P) */
169 vm_object_offset_t offset
; /* offset into that object (O,P) */
172 * The following word of flags is protected
173 * by the "page queues" lock.
175 * we use the 'wire_count' field to store the local
176 * queue id if local queues are enabled...
177 * see the comments at 'VM_PAGE_QUEUES_REMOVE' as to
178 * why this is safe to do
180 #define local_id wire_count
181 unsigned int wire_count
:16, /* how many wired down maps use me? (O&P) */
182 /* boolean_t */ inactive
:1, /* page is in inactive list (P) */
184 active
:1, /* page is in active list (P) */
185 pageout_queue
:1,/* page is on queue for pageout (P) */
186 speculative
:1, /* page is on speculative list (P) */
187 laundry
:1, /* page is being cleaned now (P)*/
188 free
:1, /* page is on free list (P) */
189 reference
:1, /* page has been used (P) */
190 gobbled
:1, /* page used internally (P) */
191 private:1, /* Page should not be returned to
192 * the free list (P) */
193 throttled
:1, /* pager is not responding (P) */
195 no_cache
:1, /* page is not to be cached and should
196 * be reused ahead of other pages (P) */
197 __unused_pageq_bits
:3; /* 3 bits available here */
199 ppnum_t phys_page
; /* Physical address of page, passed
200 * to pmap_enter (read-only) */
203 * The following word of flags is protected
204 * by the "VM object" lock.
207 /* boolean_t */ busy
:1, /* page is in transit (O) */
208 wanted
:1, /* someone is waiting for page (O) */
209 tabled
:1, /* page is in VP table (O) */
210 fictitious
:1, /* Physical page doesn't exist (O) */
212 * IMPORTANT: the "pmapped" bit can be turned on while holding the
213 * VM object "shared" lock. See vm_fault_enter().
214 * This is OK as long as it's the only bit in this bit field that
215 * can be updated without holding the VM object "exclusive" lock.
217 pmapped
:1, /* page has been entered at some
218 * point into a pmap (O **shared**) */
219 wpmapped
:1, /* page has been entered at some
220 * point into a pmap for write (O) */
221 pageout
:1, /* page wired & busy for pageout (O) */
222 absent
:1, /* Data has been requested, but is
223 * not yet available (O) */
224 error
:1, /* Data manager was unable to provide
225 * data due to error (O) */
226 dirty
:1, /* Page must be cleaned (O) */
227 cleaning
:1, /* Page clean has begun (O) */
228 precious
:1, /* Page is precious; data must be
229 * returned even if clean (O) */
230 clustered
:1, /* page is not the faulted page (O) */
231 overwriting
:1, /* Request to unlock has been made
232 * without having data. (O)
233 * [See vm_fault_page_overwrite] */
234 restart
:1, /* Page was pushed higher in shadow
235 chain by copy_call-related pagers;
236 start again at top of chain */
237 unusual
:1, /* Page is absent, error, restart or
239 encrypted
:1, /* encrypted for secure swap (O) */
240 encrypted_cleaning
:1, /* encrypting page */
241 list_req_pending
:1, /* pagein/pageout alt mechanism */
242 /* allows creation of list */
243 /* requests on pages that are */
244 /* actively being paged. */
245 dump_cleaning
:1, /* set by the pageout daemon when */
246 /* a page being cleaned is */
247 /* encountered and targeted as */
248 /* a pageout candidate */
249 cs_validated
:1, /* code-signing: page was checked */
250 cs_tainted
:1, /* code-signing: page is tainted */
254 __unused_object_bits
:7; /* 7 bits available here */
257 unsigned int __unused_padding
; /* Pad structure explicitly
258 * to 8-byte multiple for LP64 */
262 #define DEBUG_ENCRYPTED_SWAP 1
263 #if DEBUG_ENCRYPTED_SWAP
264 #define ASSERT_PAGE_DECRYPTED(page) \
266 if ((page)->encrypted) { \
267 panic("VM page %p should not be encrypted here\n", \
271 #else /* DEBUG_ENCRYPTED_SWAP */
272 #define ASSERT_PAGE_DECRYPTED(page) assert(!(page)->encrypted)
273 #endif /* DEBUG_ENCRYPTED_SWAP */
275 typedef struct vm_page
*vm_page_t
;
278 typedef struct vm_locks_array
{
279 char pad
__attribute__ ((aligned (64)));
280 lck_mtx_t vm_page_queue_lock2
__attribute__ ((aligned (64)));
281 lck_mtx_t vm_page_queue_free_lock2
__attribute__ ((aligned (64)));
282 char pad2
__attribute__ ((aligned (64)));
286 #define VM_PAGE_WIRED(m) ((!(m)->local && (m)->wire_count))
287 #define VM_PAGE_NULL ((vm_page_t) 0)
288 #define NEXT_PAGE(m) ((vm_page_t) (m)->pageq.next)
289 #define NEXT_PAGE_PTR(m) ((vm_page_t *) &(m)->pageq.next)
292 * XXX The unusual bit should not be necessary. Most of the bit
293 * XXX fields above really want to be masks.
297 * For debugging, this macro can be defined to perform
298 * some useful check on a page structure.
301 #define VM_PAGE_CHECK(mem) \
303 VM_PAGE_QUEUES_ASSERT(mem, 1); \
308 * The free page list is actually n lists, one per color,
309 * where the number of colors is a function of the machine's
310 * cache geometry set at system initialization. To disable
311 * coloring, set vm_colors to 1 and vm_color_mask to 0.
312 * The boot-arg "colors" may be used to override vm_colors.
313 * Note that there is little harm in having more colors than needed.
316 #define MAX_COLORS 128
317 #define DEFAULT_COLORS 32
320 unsigned int vm_colors
; /* must be in range 1..MAX_COLORS */
322 unsigned int vm_color_mask
; /* must be (vm_colors-1) */
324 unsigned int vm_cache_geometry_colors
; /* optimal #colors based on cache geometry */
327 * Wired memory is a very limited resource and we can't let users exhaust it
328 * and deadlock the entire system. We enforce the following limits:
330 * vm_user_wire_limit (default: all memory minus vm_global_no_user_wire_amount)
331 * how much memory can be user-wired in one user task
333 * vm_global_user_wire_limit (default: same as vm_user_wire_limit)
334 * how much memory can be user-wired in all user tasks
336 * vm_global_no_user_wire_amount (default: VM_NOT_USER_WIREABLE)
337 * how much memory must remain user-unwired at any time
339 #define VM_NOT_USER_WIREABLE (64*1024*1024) /* 64MB */
341 vm_map_size_t vm_user_wire_limit
;
343 vm_map_size_t vm_global_user_wire_limit
;
345 vm_map_size_t vm_global_no_user_wire_amount
;
348 * Each pageable resident page falls into one of three lists:
351 * Available for allocation now. The free list is
352 * actually an array of lists, one per color.
354 * Not referenced in any map, but still has an
355 * object/offset-page mapping, and may be dirty.
356 * This is the list of pages that should be
357 * paged out next. There are actually two
358 * inactive lists, one for pages brought in from
359 * disk or other backing store, and another
360 * for "zero-filled" pages. See vm_pageout_scan()
361 * for the distinction and usage.
363 * A list of pages which have been placed in
364 * at least one physical map. This list is
365 * ordered, in LRU-like fashion.
369 #define VPL_LOCK_SPIN 1
372 unsigned int vpl_count
;
373 queue_head_t vpl_queue
;
378 lck_mtx_ext_t vpl_lock_ext
;
384 char cache_line_pad
[128];
389 unsigned int vm_page_local_q_count
;
391 struct vplq
*vm_page_local_q
;
393 unsigned int vm_page_local_q_soft_limit
;
395 unsigned int vm_page_local_q_hard_limit
;
397 vm_locks_array_t vm_page_locks
;
400 queue_head_t vm_page_queue_free
[MAX_COLORS
]; /* memory free queue */
402 queue_head_t vm_lopage_queue_free
; /* low memory free queue */
404 queue_head_t vm_page_queue_active
; /* active memory queue */
406 queue_head_t vm_page_queue_inactive
; /* inactive memory queue for normal pages */
408 queue_head_t vm_page_queue_zf
; /* inactive memory queue for zero fill */
410 queue_head_t vm_page_queue_throttled
; /* memory queue for throttled pageout pages */
413 vm_offset_t first_phys_addr
; /* physical address for first_page */
415 vm_offset_t last_phys_addr
; /* physical address for last_page */
418 unsigned int vm_page_free_count
; /* How many pages are free? (sum of all colors) */
420 unsigned int vm_page_fictitious_count
;/* How many fictitious pages are free? */
422 unsigned int vm_page_active_count
; /* How many pages are active? */
424 unsigned int vm_page_inactive_count
; /* How many pages are inactive? */
426 unsigned int vm_page_throttled_count
;/* How many inactives are throttled */
428 unsigned int vm_page_speculative_count
; /* How many speculative pages are unclaimed? */
430 unsigned int vm_page_wire_count
; /* How many pages are wired? */
432 unsigned int vm_page_free_target
; /* How many do we want free? */
434 unsigned int vm_page_free_min
; /* When to wakeup pageout */
436 unsigned int vm_page_throttle_limit
; /* When to throttle new page creation */
438 uint32_t vm_page_creation_throttle
; /* When to throttle new page creation */
440 unsigned int vm_page_inactive_target
;/* How many do we want inactive? */
442 unsigned int vm_page_inactive_min
; /* When do wakeup pageout */
444 unsigned int vm_page_free_reserved
; /* How many pages reserved to do pageout */
446 unsigned int vm_page_throttle_count
; /* Count of page allocations throttled */
448 unsigned int vm_page_gobble_count
;
450 #if DEVELOPMENT || DEBUG
452 unsigned int vm_page_speculative_used
;
456 unsigned int vm_page_purgeable_count
;/* How many pages are purgeable now ? */
458 unsigned int vm_page_purgeable_wired_count
;/* How many purgeable pages are wired now ? */
460 uint64_t vm_page_purged_count
; /* How many pages got purged so far ? */
462 extern unsigned int vm_page_free_wanted
;
463 /* how many threads are waiting for memory */
465 extern unsigned int vm_page_free_wanted_privileged
;
466 /* how many VM privileged threads are waiting for memory */
468 extern ppnum_t vm_page_fictitious_addr
;
469 /* (fake) phys_addr of fictitious pages */
471 extern ppnum_t vm_page_guard_addr
;
472 /* (fake) phys_addr of guard pages */
475 extern boolean_t vm_page_deactivate_hint
;
478 0 = all pages avail ( default. )
479 1 = disable high mem ( cap max pages to 4G)
482 extern int vm_himemory_mode
;
484 extern boolean_t vm_lopage_needed
;
485 extern uint32_t vm_lopage_free_count
;
486 extern uint32_t vm_lopage_free_limit
;
487 extern uint32_t vm_lopage_lowater
;
488 extern boolean_t vm_lopage_refill
;
489 extern uint64_t max_valid_dma_address
;
490 extern ppnum_t max_valid_low_ppnum
;
493 * Prototypes for functions exported by this module.
495 extern void vm_page_bootstrap(
497 vm_offset_t
*endp
) __attribute__((section("__TEXT, initcode")));
499 extern void vm_page_module_init(void) __attribute__((section("__TEXT, initcode")));
501 extern void vm_page_init_local_q(void);
503 extern void vm_page_create(
507 extern vm_page_t
vm_page_lookup(
509 vm_object_offset_t offset
);
511 extern vm_page_t
vm_page_grab_fictitious(void);
513 extern vm_page_t
vm_page_grab_guard(void);
515 extern void vm_page_release_fictitious(
518 extern void vm_page_more_fictitious(void);
520 extern int vm_pool_low(void);
522 extern vm_page_t
vm_page_grab(void);
524 extern vm_page_t
vm_page_grablo(void);
526 extern void vm_page_release(
529 extern boolean_t
vm_page_wait(
532 extern vm_page_t
vm_page_alloc(
534 vm_object_offset_t offset
);
536 extern vm_page_t
vm_page_alloclo(
538 vm_object_offset_t offset
);
540 extern vm_page_t
vm_page_alloc_guard(
542 vm_object_offset_t offset
);
544 extern void vm_page_init(
549 extern void vm_page_free(
552 extern void vm_page_free_unlocked(
554 boolean_t remove_from_hash
);
556 extern void vm_page_activate(
559 extern void vm_page_deactivate(
562 extern void vm_page_deactivate_internal(
564 boolean_t clear_hw_reference
);
566 extern void vm_page_lru(
569 extern void vm_page_speculate(
573 extern void vm_page_speculate_ageit(
574 struct vm_speculative_age_q
*aq
);
576 extern void vm_page_reactivate_all_throttled(void);
578 extern void vm_page_reactivate_local(uint32_t lid
, boolean_t force
, boolean_t nolocks
);
580 extern void vm_page_rename(
582 vm_object_t new_object
,
583 vm_object_offset_t new_offset
,
584 boolean_t encrypted_ok
);
586 extern void vm_page_insert(
589 vm_object_offset_t offset
);
591 extern void vm_page_insert_internal(
594 vm_object_offset_t offset
,
595 boolean_t queues_lock_held
,
596 boolean_t insert_in_hash
);
598 extern void vm_page_replace(
601 vm_object_offset_t offset
);
603 extern void vm_page_remove(
605 boolean_t remove_from_hash
);
607 extern void vm_page_zero_fill(
610 extern void vm_page_part_zero_fill(
615 extern void vm_page_copy(
617 vm_page_t dest_page
);
619 extern void vm_page_part_copy(
626 extern void vm_page_wire(
629 extern void vm_page_unwire(
633 extern void vm_set_page_size(void);
635 extern void vm_page_gobble(
638 extern void vm_page_validate_cs(vm_page_t page
);
639 extern void vm_page_validate_cs_mapped(
643 extern void vm_page_free_prepare_queues(
646 extern void vm_page_free_prepare_object(
648 boolean_t remove_from_hash
);
650 extern void vm_check_memorystatus(void);
654 * Functions implemented as macros. m->wanted and m->busy are
655 * protected by the object lock.
658 #define PAGE_ASSERT_WAIT(m, interruptible) \
659 (((m)->wanted = TRUE), \
660 assert_wait((event_t) (m), (interruptible)))
662 #define PAGE_SLEEP(o, m, interruptible) \
663 (((m)->wanted = TRUE), \
664 thread_sleep_vm_object((o), (m), (interruptible)))
666 #define PAGE_WAKEUP_DONE(m) \
670 (m)->wanted = FALSE; \
671 thread_wakeup((event_t) (m)); \
675 #define PAGE_WAKEUP(m) \
678 (m)->wanted = FALSE; \
679 thread_wakeup((event_t) (m)); \
683 #define VM_PAGE_FREE(p) \
685 vm_page_free_unlocked(p, TRUE); \
688 #define VM_PAGE_GRAB_FICTITIOUS(M) \
690 while ((M = vm_page_grab_fictitious()) == VM_PAGE_NULL) \
691 vm_page_more_fictitious(); \
694 #define VM_PAGE_WAIT() ((void)vm_page_wait(THREAD_UNINT))
696 #define vm_page_queue_lock (vm_page_locks.vm_page_queue_lock2)
697 #define vm_page_queue_free_lock (vm_page_locks.vm_page_queue_free_lock2)
699 #define vm_page_lock_queues() lck_mtx_lock(&vm_page_queue_lock)
700 #define vm_page_unlock_queues() lck_mtx_unlock(&vm_page_queue_lock)
702 #define vm_page_lockspin_queues() lck_mtx_lock_spin(&vm_page_queue_lock)
703 #define vm_page_trylockspin_queues() lck_mtx_try_lock_spin(&vm_page_queue_lock)
704 #define vm_page_lockconvert_queues() lck_mtx_convert_spin(&vm_page_queue_lock)
707 #define VPL_LOCK_INIT(vlq, vpl_grp, vpl_attr) lck_spin_init(&vlq->vpl_lock, vpl_grp, vpl_attr)
708 #define VPL_LOCK(vpl) lck_spin_lock(vpl)
709 #define VPL_UNLOCK(vpl) lck_spin_unlock(vpl)
711 #define VPL_LOCK_INIT(vlq, vpl_grp, vpl_attr) lck_mtx_init_ext(&vlq->vpl_lock, &vlq->vpl_lock_ext, vpl_grp, vpl_attr)
712 #define VPL_LOCK(vpl) lck_mtx_lock_spin(vpl)
713 #define VPL_UNLOCK(vpl) lck_mtx_unlock(vpl)
717 extern void vm_page_queues_assert(vm_page_t mem
, int val
);
718 #define VM_PAGE_QUEUES_ASSERT(mem, val) vm_page_queues_assert((mem), (val))
720 #define VM_PAGE_QUEUES_ASSERT(mem, val)
725 * 'vm_fault_enter' will place newly created pages (zero-fill and COW) onto the
726 * local queues if they exist... its the only spot in the system where we add pages
727 * to those queues... once on those queues, those pages can only move to one of the
728 * global page queues or the free queues... they NEVER move from local q to local q.
729 * the 'local' state is stable when VM_PAGE_QUEUES_REMOVE is called since we're behind
730 * the global vm_page_queue_lock at this point... we still need to take the local lock
731 * in case this operation is being run on a different CPU then the local queue's identity,
732 * but we don't have to worry about the page moving to a global queue or becoming wired
733 * while we're grabbing the local lock since those operations would require the global
734 * vm_page_queue_lock to be held, and we already own it.
736 * this is why its safe to utilze the wire_count field in the vm_page_t as the local_id...
737 * 'wired' and local are ALWAYS mutually exclusive conditions.
739 #define VM_PAGE_QUEUES_REMOVE(mem) \
741 VM_PAGE_QUEUES_ASSERT(mem, 1); \
742 assert(!mem->laundry); \
743 assert(!mem->pageout_queue); \
746 assert(mem->object != kernel_object); \
747 assert(!mem->inactive && !mem->speculative); \
748 assert(!mem->active && !mem->throttled); \
749 assert(!mem->fictitious); \
750 lq = &vm_page_local_q[mem->local_id].vpl_un.vpl; \
751 VPL_LOCK(&lq->vpl_lock); \
752 queue_remove(&lq->vpl_queue, \
753 mem, vm_page_t, pageq); \
754 mem->local = FALSE; \
757 VPL_UNLOCK(&lq->vpl_lock); \
760 else if (mem->active) { \
761 assert(mem->object != kernel_object); \
762 assert(!mem->inactive && !mem->speculative); \
763 assert(!mem->throttled); \
764 assert(!mem->fictitious); \
765 queue_remove(&vm_page_queue_active, \
766 mem, vm_page_t, pageq); \
767 mem->active = FALSE; \
768 vm_page_active_count--; \
771 else if (mem->inactive) { \
772 assert(mem->object != kernel_object); \
773 assert(!mem->active && !mem->speculative); \
774 assert(!mem->throttled); \
775 assert(!mem->fictitious); \
776 if (mem->zero_fill) { \
777 queue_remove(&vm_page_queue_zf, \
778 mem, vm_page_t, pageq); \
779 vm_zf_queue_count--; \
781 queue_remove(&vm_page_queue_inactive, \
782 mem, vm_page_t, pageq); \
784 mem->inactive = FALSE; \
785 vm_page_inactive_count--; \
786 vm_purgeable_q_advance_all(); \
789 else if (mem->throttled) { \
790 assert(!mem->active && !mem->inactive); \
791 assert(!mem->speculative); \
792 assert(!mem->fictitious); \
793 queue_remove(&vm_page_queue_throttled, \
794 mem, vm_page_t, pageq); \
795 mem->throttled = FALSE; \
796 vm_page_throttled_count--; \
799 else if (mem->speculative) { \
800 assert(!mem->active && !mem->inactive); \
801 assert(!mem->throttled); \
802 assert(!mem->fictitious); \
803 remque(&mem->pageq); \
804 mem->speculative = FALSE; \
805 vm_page_speculative_count--; \
808 else if (mem->pageq.next || mem->pageq.prev) \
809 panic("VM_PAGE_QUEUES_REMOVE: unmarked page on Q"); \
810 mem->pageq.next = NULL; \
811 mem->pageq.prev = NULL; \
812 VM_PAGE_QUEUES_ASSERT(mem, 0); \
816 #define VM_PAGE_ENQUEUE_INACTIVE(mem, first) \
818 VM_PAGE_QUEUES_ASSERT(mem, 0); \
819 assert(!mem->fictitious); \
820 assert(!mem->laundry); \
821 assert(!mem->pageout_queue); \
822 if (mem->zero_fill) { \
824 queue_enter_first(&vm_page_queue_zf, mem, vm_page_t, pageq); \
826 queue_enter(&vm_page_queue_zf, mem, vm_page_t, pageq); \
827 vm_zf_queue_count++; \
830 queue_enter_first(&vm_page_queue_inactive, mem, vm_page_t, pageq); \
832 queue_enter(&vm_page_queue_inactive, mem, vm_page_t, pageq); \
834 mem->inactive = TRUE; \
835 vm_page_inactive_count++; \
836 token_new_pagecount++; \
840 #if DEVELOPMENT || DEBUG
841 #define VM_PAGE_SPECULATIVE_USED_ADD() \
843 OSAddAtomic(1, &vm_page_speculative_used); \
846 #define VM_PAGE_SPECULATIVE_USED_ADD()
850 #define VM_PAGE_CONSUME_CLUSTERED(mem) \
852 if (mem->clustered) { \
853 assert(mem->object); \
854 mem->object->pages_used++; \
855 mem->clustered = FALSE; \
856 VM_PAGE_SPECULATIVE_USED_ADD(); \
862 #define DW_vm_page_unwire 0x01
863 #define DW_vm_page_wire 0x02
864 #define DW_vm_page_free 0x04
865 #define DW_vm_page_activate 0x08
866 #define DW_vm_page_deactivate_internal 0x10
867 #define DW_vm_page_speculate 0x20
868 #define DW_vm_page_lru 0x40
869 #define DW_vm_pageout_throttle_up 0x80
870 #define DW_PAGE_WAKEUP 0x100
871 #define DW_clear_busy 0x200
872 #define DW_clear_reference 0x400
873 #define DW_set_reference 0x800
874 #define DW_move_page 0x1000
875 #define DW_VM_PAGE_QUEUES_REMOVE 0x2000
876 #define DW_set_list_req_pending 0x4000
878 struct vm_page_delayed_work
{
883 void vm_page_do_delayed_work(vm_object_t object
, struct vm_page_delayed_work
*dwp
, int dw_count
);
885 extern unsigned int vm_max_delayed_work_limit
;
887 #define DEFAULT_DELAYED_WORK_LIMIT 32
889 #define DELAYED_WORK_LIMIT(max) ((vm_max_delayed_work_limit >= max ? max : vm_max_delayed_work_limit))
892 * vm_page_do_delayed_work may need to drop the object lock...
893 * if it does, we need the pages it's looking at to
894 * be held stable via the busy bit, so if busy isn't already
895 * set, we need to set it and ask vm_page_do_delayed_work
896 * to clear it and wakeup anyone that might have blocked on
897 * it once we're done processing the page.
899 * additionally, we can't call vm_page_do_delayed_work with
900 * list_req_pending == TRUE since it may need to
901 * drop the object lock before dealing
902 * with this page and because list_req_pending == TRUE,
903 * busy == TRUE will NOT protect this page from being stolen
904 * so clear list_req_pending and ask vm_page_do_delayed_work
905 * to re-set it once it holds both the pageq and object locks
908 #define VM_PAGE_ADD_DELAYED_WORK(dwp, mem, dw_cnt) \
910 if (mem->busy == FALSE) { \
912 if ( !(dwp->dw_mask & DW_vm_page_free)) \
913 dwp->dw_mask |= (DW_clear_busy | DW_PAGE_WAKEUP); \
915 if (mem->list_req_pending) { \
916 mem->list_req_pending = FALSE; \
917 dwp->dw_mask |= DW_set_list_req_pending; \
924 extern vm_page_t
vm_object_page_grab(vm_object_t
);
927 #endif /* _VM_VM_PAGE_H_ */