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_
70 #include <vm/vm_options.h>
72 #include <mach/boolean.h>
73 #include <mach/vm_prot.h>
74 #include <mach/vm_param.h>
75 #include <vm/vm_object.h>
76 #include <kern/queue.h>
77 #include <kern/lock.h>
79 #include <kern/macro_help.h>
80 #include <libkern/OSAtomic.h>
84 * VM_PAGE_MIN_SPECULATIVE_AGE_Q through VM_PAGE_MAX_SPECULATIVE_AGE_Q
85 * represents a set of aging bins that are 'protected'...
87 * VM_PAGE_SPECULATIVE_AGED_Q is a list of the speculative pages that have
88 * not yet been 'claimed' but have been aged out of the protective bins
89 * this occurs in vm_page_speculate when it advances to the next bin
90 * and discovers that it is still occupied... at that point, all of the
91 * pages in that bin are moved to the VM_PAGE_SPECULATIVE_AGED_Q. the pages
92 * in that bin are all guaranteed to have reached at least the maximum age
93 * we allow for a protected page... they can be older if there is no
94 * memory pressure to pull them from the bin, or there are no new speculative pages
95 * being generated to push them out.
96 * this list is the one that vm_pageout_scan will prefer when looking
97 * for pages to move to the underweight free list
99 * VM_PAGE_MAX_SPECULATIVE_AGE_Q * VM_PAGE_SPECULATIVE_Q_AGE_MS
100 * defines the amount of time a speculative page is normally
101 * allowed to live in the 'protected' state (i.e. not available
102 * to be stolen if vm_pageout_scan is running and looking for
103 * pages)... however, if the total number of speculative pages
104 * in the protected state exceeds our limit (defined in vm_pageout.c)
105 * and there are none available in VM_PAGE_SPECULATIVE_AGED_Q, then
106 * vm_pageout_scan is allowed to steal pages from the protected
107 * bucket even if they are underage.
109 * vm_pageout_scan is also allowed to pull pages from a protected
110 * bin if the bin has reached the "age of consent" we've set
112 #define VM_PAGE_MAX_SPECULATIVE_AGE_Q 10
113 #define VM_PAGE_MIN_SPECULATIVE_AGE_Q 1
114 #define VM_PAGE_SPECULATIVE_AGED_Q 0
116 #define VM_PAGE_SPECULATIVE_Q_AGE_MS 500
118 struct vm_speculative_age_q
{
120 * memory queue for speculative pages via clustered pageins
123 mach_timespec_t age_ts
;
129 struct vm_speculative_age_q vm_page_queue_speculative
[];
131 extern int speculative_steal_index
;
132 extern int speculative_age_index
;
133 extern unsigned int vm_page_speculative_q_age_ms
;
136 #define VM_PAGE_COMPRESSOR_COUNT (compressor_object->resident_page_count)
139 * Management of resident (logical) pages.
141 * A small structure is kept for each resident
142 * page, indexed by page number. Each structure
143 * is an element of several lists:
145 * A hash table bucket used to quickly
146 * perform object/offset lookups
148 * A list of all pages for a given object,
149 * so they can be quickly deactivated at
150 * time of deallocation.
152 * An ordered list of pages due for pageout.
154 * In addition, the structure contains the object
155 * and offset to which this page belongs (for pageout),
156 * and sundry status bits.
158 * Fields in this structure are locked either by the lock on the
159 * object that the page belongs to (O) or by the lock on the page
160 * queues (P). [Some fields require that both locks be held to
161 * change that field; holding either lock is sufficient to read.]
165 queue_chain_t pageq
; /* queue info for FIFO */
166 /* queue or free list (P) */
168 queue_chain_t listq
; /* all pages in same object (O) */
169 struct vm_page
*next
; /* VP bucket link (O) */
171 vm_object_t object
; /* which object am I in (O&P) */
172 vm_object_offset_t offset
; /* offset into that object (O,P) */
175 * The following word of flags is protected
176 * by the "page queues" lock.
178 * we use the 'wire_count' field to store the local
179 * queue id if local queues are enabled...
180 * see the comments at 'VM_PAGE_QUEUES_REMOVE' as to
181 * why this is safe to do
183 #define local_id wire_count
184 unsigned int wire_count
:16, /* how many wired down maps use me? (O&P) */
185 /* boolean_t */ active
:1, /* page is in active list (P) */
186 inactive
:1, /* page is in inactive list (P) */
187 clean_queue
:1, /* page is in pre-cleaned list (P) */
188 local
:1, /* page is in one of the local queues (P) */
189 speculative
:1, /* page is in speculative list (P) */
190 throttled
:1, /* pager is not responding or doesn't exist(P) */
191 free
:1, /* page is on free list (P) */
192 pageout_queue
:1,/* page is on queue for pageout (P) */
193 laundry
:1, /* page is being cleaned now (P)*/
194 reference
:1, /* page has been used (P) */
195 gobbled
:1, /* page used internally (P) */
196 private:1, /* Page should not be returned to
197 * the free list (P) */
198 no_cache
:1, /* page is not to be cached and should
199 * be reused ahead of other pages (P) */
201 __unused_pageq_bits
:2; /* 2 bits available here */
203 ppnum_t phys_page
; /* Physical address of page, passed
204 * to pmap_enter (read-only) */
207 * The following word of flags is protected
208 * by the "VM object" lock.
211 /* boolean_t */ busy
:1, /* page is in transit (O) */
212 wanted
:1, /* someone is waiting for page (O) */
213 tabled
:1, /* page is in VP table (O) */
214 hashed
:1, /* page is in vm_page_buckets[]
215 (O) + the bucket lock */
216 fictitious
:1, /* Physical page doesn't exist (O) */
218 * IMPORTANT: the "pmapped" bit can be turned on while holding the
219 * VM object "shared" lock. See vm_fault_enter().
220 * This is OK as long as it's the only bit in this bit field that
221 * can be updated without holding the VM object "exclusive" lock.
223 pmapped
:1, /* page has been entered at some
224 * point into a pmap (O **shared**) */
225 wpmapped
:1, /* page has been entered at some
226 * point into a pmap for write (O) */
227 pageout
:1, /* page wired & busy for pageout (O) */
228 absent
:1, /* Data has been requested, but is
229 * not yet available (O) */
230 error
:1, /* Data manager was unable to provide
231 * data due to error (O) */
232 dirty
:1, /* Page must be cleaned (O) */
233 cleaning
:1, /* Page clean has begun (O) */
234 precious
:1, /* Page is precious; data must be
235 * returned even if clean (O) */
236 clustered
:1, /* page is not the faulted page (O) */
237 overwriting
:1, /* Request to unlock has been made
238 * without having data. (O)
239 * [See vm_fault_page_overwrite] */
240 restart
:1, /* Page was pushed higher in shadow
241 chain by copy_call-related pagers;
242 start again at top of chain */
243 unusual
:1, /* Page is absent, error, restart or
245 encrypted
:1, /* encrypted for secure swap (O) */
246 encrypted_cleaning
:1, /* encrypting page */
247 cs_validated
:1, /* code-signing: page was checked */
248 cs_tainted
:1, /* code-signing: page is tainted */
252 was_dirty
:1, /* was this page previously dirty? */
253 compressor
:1, /* page owned by compressor pool */
254 written_by_kernel
:1, /* page was written by kernel (i.e. decompressed) */
255 __unused_object_bits
:5; /* 5 bits available here */
258 unsigned int __unused_padding
; /* Pad structure explicitly
259 * to 8-byte multiple for LP64 */
263 #define DEBUG_ENCRYPTED_SWAP 1
264 #if DEBUG_ENCRYPTED_SWAP
265 #define ASSERT_PAGE_DECRYPTED(page) \
267 if ((page)->encrypted) { \
268 panic("VM page %p should not be encrypted here\n", \
272 #else /* DEBUG_ENCRYPTED_SWAP */
273 #define ASSERT_PAGE_DECRYPTED(page) assert(!(page)->encrypted)
274 #endif /* DEBUG_ENCRYPTED_SWAP */
276 typedef struct vm_page
*vm_page_t
;
279 typedef struct vm_locks_array
{
280 char pad
__attribute__ ((aligned (64)));
281 lck_mtx_t vm_page_queue_lock2
__attribute__ ((aligned (64)));
282 lck_mtx_t vm_page_queue_free_lock2
__attribute__ ((aligned (64)));
283 char pad2
__attribute__ ((aligned (64)));
287 #define VM_PAGE_WIRED(m) ((!(m)->local && (m)->wire_count))
288 #define VM_PAGE_NULL ((vm_page_t) 0)
289 #define NEXT_PAGE(m) ((vm_page_t) (m)->pageq.next)
290 #define NEXT_PAGE_PTR(m) ((vm_page_t *) &(m)->pageq.next)
293 * XXX The unusual bit should not be necessary. Most of the bit
294 * XXX fields above really want to be masks.
298 * For debugging, this macro can be defined to perform
299 * some useful check on a page structure.
302 #define VM_PAGE_CHECK(mem) \
304 VM_PAGE_QUEUES_ASSERT(mem, 1); \
309 * The free page list is actually n lists, one per color,
310 * where the number of colors is a function of the machine's
311 * cache geometry set at system initialization. To disable
312 * coloring, set vm_colors to 1 and vm_color_mask to 0.
313 * The boot-arg "colors" may be used to override vm_colors.
314 * Note that there is little harm in having more colors than needed.
317 #define MAX_COLORS 128
318 #define DEFAULT_COLORS 32
321 unsigned int vm_colors
; /* must be in range 1..MAX_COLORS */
323 unsigned int vm_color_mask
; /* must be (vm_colors-1) */
325 unsigned int vm_cache_geometry_colors
; /* optimal #colors based on cache geometry */
328 * Wired memory is a very limited resource and we can't let users exhaust it
329 * and deadlock the entire system. We enforce the following limits:
331 * vm_user_wire_limit (default: all memory minus vm_global_no_user_wire_amount)
332 * how much memory can be user-wired in one user task
334 * vm_global_user_wire_limit (default: same as vm_user_wire_limit)
335 * how much memory can be user-wired in all user tasks
337 * vm_global_no_user_wire_amount (default: VM_NOT_USER_WIREABLE)
338 * how much memory must remain user-unwired at any time
340 #define VM_NOT_USER_WIREABLE (64*1024*1024) /* 64MB */
342 vm_map_size_t vm_user_wire_limit
;
344 vm_map_size_t vm_global_user_wire_limit
;
346 vm_map_size_t vm_global_no_user_wire_amount
;
349 * Each pageable resident page falls into one of three lists:
352 * Available for allocation now. The free list is
353 * actually an array of lists, one per color.
355 * Not referenced in any map, but still has an
356 * object/offset-page mapping, and may be dirty.
357 * This is the list of pages that should be
358 * paged out next. There are actually two
359 * inactive lists, one for pages brought in from
360 * disk or other backing store, and another
361 * for "zero-filled" pages. See vm_pageout_scan()
362 * for the distinction and usage.
364 * A list of pages which have been placed in
365 * at least one physical map. This list is
366 * ordered, in LRU-like fashion.
370 #define VPL_LOCK_SPIN 1
373 unsigned int vpl_count
;
374 unsigned int vpl_internal_count
;
375 unsigned int vpl_external_count
;
376 queue_head_t vpl_queue
;
381 lck_mtx_ext_t vpl_lock_ext
;
387 char cache_line_pad
[128];
392 unsigned int vm_page_local_q_count
;
394 struct vplq
*vm_page_local_q
;
396 unsigned int vm_page_local_q_soft_limit
;
398 unsigned int vm_page_local_q_hard_limit
;
400 vm_locks_array_t vm_page_locks
;
403 queue_head_t vm_page_queue_free
[MAX_COLORS
]; /* memory free queue */
405 queue_head_t vm_lopage_queue_free
; /* low memory free queue */
407 queue_head_t vm_page_queue_active
; /* active memory queue */
409 queue_head_t vm_page_queue_inactive
; /* inactive memory queue for normal pages */
411 queue_head_t vm_page_queue_cleaned
; /* clean-queue inactive memory */
413 queue_head_t vm_page_queue_anonymous
; /* inactive memory queue for anonymous pages */
415 queue_head_t vm_page_queue_throttled
; /* memory queue for throttled pageout pages */
418 vm_offset_t first_phys_addr
; /* physical address for first_page */
420 vm_offset_t last_phys_addr
; /* physical address for last_page */
423 unsigned int vm_page_free_count
; /* How many pages are free? (sum of all colors) */
425 unsigned int vm_page_fictitious_count
;/* How many fictitious pages are free? */
427 unsigned int vm_page_active_count
; /* How many pages are active? */
429 unsigned int vm_page_inactive_count
; /* How many pages are inactive? */
431 unsigned int vm_page_cleaned_count
; /* How many pages are in the clean queue? */
433 unsigned int vm_page_throttled_count
;/* How many inactives are throttled */
435 unsigned int vm_page_speculative_count
; /* How many speculative pages are unclaimed? */
436 extern unsigned int vm_page_pageable_internal_count
;
437 extern unsigned int vm_page_pageable_external_count
;
439 unsigned int vm_page_external_count
; /* How many pages are file-backed? */
441 unsigned int vm_page_internal_count
; /* How many pages are anonymous? */
443 unsigned int vm_page_wire_count
; /* How many pages are wired? */
445 unsigned int vm_page_wire_count_initial
; /* How many pages wired at startup */
447 unsigned int vm_page_free_target
; /* How many do we want free? */
449 unsigned int vm_page_free_min
; /* When to wakeup pageout */
451 unsigned int vm_page_throttle_limit
; /* When to throttle new page creation */
453 uint32_t vm_page_creation_throttle
; /* When to throttle new page creation */
455 unsigned int vm_page_inactive_target
;/* How many do we want inactive? */
457 unsigned int vm_page_anonymous_min
; /* When it's ok to pre-clean */
459 unsigned int vm_page_inactive_min
; /* When do wakeup pageout */
461 unsigned int vm_page_free_reserved
; /* How many pages reserved to do pageout */
463 unsigned int vm_page_throttle_count
; /* Count of page allocations throttled */
465 unsigned int vm_page_gobble_count
;
467 #if DEVELOPMENT || DEBUG
469 unsigned int vm_page_speculative_used
;
473 unsigned int vm_page_purgeable_count
;/* How many pages are purgeable now ? */
475 unsigned int vm_page_purgeable_wired_count
;/* How many purgeable pages are wired now ? */
477 uint64_t vm_page_purged_count
; /* How many pages got purged so far ? */
479 extern unsigned int vm_page_free_wanted
;
480 /* how many threads are waiting for memory */
482 extern unsigned int vm_page_free_wanted_privileged
;
483 /* how many VM privileged threads are waiting for memory */
485 extern ppnum_t vm_page_fictitious_addr
;
486 /* (fake) phys_addr of fictitious pages */
488 extern ppnum_t vm_page_guard_addr
;
489 /* (fake) phys_addr of guard pages */
492 extern boolean_t vm_page_deactivate_hint
;
494 extern int vm_compressor_mode
;
497 0 = all pages avail ( default. )
498 1 = disable high mem ( cap max pages to 4G)
501 extern int vm_himemory_mode
;
503 extern boolean_t vm_lopage_needed
;
504 extern uint32_t vm_lopage_free_count
;
505 extern uint32_t vm_lopage_free_limit
;
506 extern uint32_t vm_lopage_lowater
;
507 extern boolean_t vm_lopage_refill
;
508 extern uint64_t max_valid_dma_address
;
509 extern ppnum_t max_valid_low_ppnum
;
512 * Prototypes for functions exported by this module.
514 extern void vm_page_bootstrap(
518 extern void vm_page_module_init(void);
520 extern void vm_page_init_local_q(void);
522 extern void vm_page_create(
526 extern vm_page_t
vm_page_lookup(
528 vm_object_offset_t offset
);
530 extern vm_page_t
vm_page_grab_fictitious(void);
532 extern vm_page_t
vm_page_grab_guard(void);
534 extern void vm_page_release_fictitious(
537 extern void vm_page_more_fictitious(void);
539 extern int vm_pool_low(void);
541 extern vm_page_t
vm_page_grab(void);
543 extern vm_page_t
vm_page_grablo(void);
545 extern void vm_page_release(
548 extern boolean_t
vm_page_wait(
551 extern vm_page_t
vm_page_alloc(
553 vm_object_offset_t offset
);
555 extern vm_page_t
vm_page_alloclo(
557 vm_object_offset_t offset
);
559 extern vm_page_t
vm_page_alloc_guard(
561 vm_object_offset_t offset
);
563 extern void vm_page_init(
568 extern void vm_page_free(
571 extern void vm_page_free_unlocked(
573 boolean_t remove_from_hash
);
575 extern void vm_page_activate(
578 extern void vm_page_deactivate(
581 extern void vm_page_deactivate_internal(
583 boolean_t clear_hw_reference
);
585 extern void vm_page_enqueue_cleaned(vm_page_t page
);
587 extern void vm_page_lru(
590 extern void vm_page_speculate(
594 extern void vm_page_speculate_ageit(
595 struct vm_speculative_age_q
*aq
);
597 extern void vm_page_reactivate_all_throttled(void);
599 extern void vm_page_reactivate_local(uint32_t lid
, boolean_t force
, boolean_t nolocks
);
601 extern void vm_page_rename(
603 vm_object_t new_object
,
604 vm_object_offset_t new_offset
,
605 boolean_t encrypted_ok
);
607 extern void vm_page_insert(
610 vm_object_offset_t offset
);
612 extern void vm_page_insert_internal(
615 vm_object_offset_t offset
,
616 boolean_t queues_lock_held
,
617 boolean_t insert_in_hash
,
618 boolean_t batch_pmap_op
);
620 extern void vm_page_replace(
623 vm_object_offset_t offset
);
625 extern void vm_page_remove(
627 boolean_t remove_from_hash
);
629 extern void vm_page_zero_fill(
632 extern void vm_page_part_zero_fill(
637 extern void vm_page_copy(
639 vm_page_t dest_page
);
641 extern void vm_page_part_copy(
648 extern void vm_page_wire(
651 extern void vm_page_unwire(
655 extern void vm_set_page_size(void);
657 extern void vm_page_gobble(
660 extern void vm_page_validate_cs(vm_page_t page
);
661 extern void vm_page_validate_cs_mapped(
665 extern void vm_page_free_prepare_queues(
668 extern void vm_page_free_prepare_object(
670 boolean_t remove_from_hash
);
673 extern void memorystatus_pages_update(unsigned int pages_avail
);
675 #define VM_CHECK_MEMORYSTATUS do { \
676 memorystatus_pages_update( \
677 vm_page_external_count + \
678 vm_page_free_count + \
679 (VM_DYNAMIC_PAGING_ENABLED(memory_manager_default) ? 0 : vm_page_purgeable_count) \
683 #else /* CONFIG_JETSAM */
686 extern void vm_pressure_response(void);
688 #define VM_CHECK_MEMORYSTATUS vm_pressure_response()
691 #endif /* CONFIG_JETSAM */
694 * Functions implemented as macros. m->wanted and m->busy are
695 * protected by the object lock.
698 #define SET_PAGE_DIRTY(m, set_pmap_modified) \
700 vm_page_t __page__ = (m); \
701 __page__->dirty = TRUE; \
704 #define PAGE_ASSERT_WAIT(m, interruptible) \
705 (((m)->wanted = TRUE), \
706 assert_wait((event_t) (m), (interruptible)))
708 #define PAGE_SLEEP(o, m, interruptible) \
709 (((m)->wanted = TRUE), \
710 thread_sleep_vm_object((o), (m), (interruptible)))
712 #define PAGE_WAKEUP_DONE(m) \
716 (m)->wanted = FALSE; \
717 thread_wakeup((event_t) (m)); \
721 #define PAGE_WAKEUP(m) \
724 (m)->wanted = FALSE; \
725 thread_wakeup((event_t) (m)); \
729 #define VM_PAGE_FREE(p) \
731 vm_page_free_unlocked(p, TRUE); \
734 #define VM_PAGE_GRAB_FICTITIOUS(M) \
736 while ((M = vm_page_grab_fictitious()) == VM_PAGE_NULL) \
737 vm_page_more_fictitious(); \
740 #define VM_PAGE_WAIT() ((void)vm_page_wait(THREAD_UNINT))
742 #define vm_page_queue_lock (vm_page_locks.vm_page_queue_lock2)
743 #define vm_page_queue_free_lock (vm_page_locks.vm_page_queue_free_lock2)
745 #define vm_page_lock_queues() lck_mtx_lock(&vm_page_queue_lock)
746 #define vm_page_unlock_queues() lck_mtx_unlock(&vm_page_queue_lock)
748 #define vm_page_lockspin_queues() lck_mtx_lock_spin(&vm_page_queue_lock)
749 #define vm_page_trylockspin_queues() lck_mtx_try_lock_spin(&vm_page_queue_lock)
750 #define vm_page_lockconvert_queues() lck_mtx_convert_spin(&vm_page_queue_lock)
753 #define VPL_LOCK_INIT(vlq, vpl_grp, vpl_attr) lck_spin_init(&vlq->vpl_lock, vpl_grp, vpl_attr)
754 #define VPL_LOCK(vpl) lck_spin_lock(vpl)
755 #define VPL_UNLOCK(vpl) lck_spin_unlock(vpl)
757 #define VPL_LOCK_INIT(vlq, vpl_grp, vpl_attr) lck_mtx_init_ext(&vlq->vpl_lock, &vlq->vpl_lock_ext, vpl_grp, vpl_attr)
758 #define VPL_LOCK(vpl) lck_mtx_lock_spin(vpl)
759 #define VPL_UNLOCK(vpl) lck_mtx_unlock(vpl)
763 extern void vm_page_queues_assert(vm_page_t mem
, int val
);
764 #define VM_PAGE_QUEUES_ASSERT(mem, val) vm_page_queues_assert((mem), (val))
766 #define VM_PAGE_QUEUES_ASSERT(mem, val)
771 * 'vm_fault_enter' will place newly created pages (zero-fill and COW) onto the
772 * local queues if they exist... its the only spot in the system where we add pages
773 * to those queues... once on those queues, those pages can only move to one of the
774 * global page queues or the free queues... they NEVER move from local q to local q.
775 * the 'local' state is stable when VM_PAGE_QUEUES_REMOVE is called since we're behind
776 * the global vm_page_queue_lock at this point... we still need to take the local lock
777 * in case this operation is being run on a different CPU then the local queue's identity,
778 * but we don't have to worry about the page moving to a global queue or becoming wired
779 * while we're grabbing the local lock since those operations would require the global
780 * vm_page_queue_lock to be held, and we already own it.
782 * this is why its safe to utilze the wire_count field in the vm_page_t as the local_id...
783 * 'wired' and local are ALWAYS mutually exclusive conditions.
786 #define VM_PAGE_QUEUES_REMOVE(mem) \
788 boolean_t was_pageable; \
790 VM_PAGE_QUEUES_ASSERT(mem, 1); \
791 assert(!mem->laundry); \
793 * if (mem->pageout_queue) \
794 * NOTE: VM_PAGE_QUEUES_REMOVE does not deal with removing pages from the pageout queue... \
795 * the caller is responsible for determing if the page is on that queue, and if so, must \
796 * either first remove it (it needs both the page queues lock and the object lock to do \
797 * this via vm_pageout_steal_laundry), or avoid the call to VM_PAGE_QUEUES_REMOVE \
801 assert(mem->object != kernel_object); \
802 assert(mem->object != compressor_object); \
803 assert(!mem->inactive && !mem->speculative); \
804 assert(!mem->active && !mem->throttled); \
805 assert(!mem->clean_queue); \
806 assert(!mem->fictitious); \
807 lq = &vm_page_local_q[mem->local_id].vpl_un.vpl; \
808 VPL_LOCK(&lq->vpl_lock); \
809 queue_remove(&lq->vpl_queue, \
810 mem, vm_page_t, pageq); \
811 mem->local = FALSE; \
814 if (mem->object->internal) { \
815 lq->vpl_internal_count--; \
817 lq->vpl_external_count--; \
819 VPL_UNLOCK(&lq->vpl_lock); \
820 was_pageable = FALSE; \
823 else if (mem->active) { \
824 assert(mem->object != kernel_object); \
825 assert(mem->object != compressor_object); \
826 assert(!mem->inactive && !mem->speculative); \
827 assert(!mem->clean_queue); \
828 assert(!mem->throttled); \
829 assert(!mem->fictitious); \
830 queue_remove(&vm_page_queue_active, \
831 mem, vm_page_t, pageq); \
832 mem->active = FALSE; \
833 vm_page_active_count--; \
834 was_pageable = TRUE; \
837 else if (mem->inactive) { \
838 assert(mem->object != kernel_object); \
839 assert(mem->object != compressor_object); \
840 assert(!mem->active && !mem->speculative); \
841 assert(!mem->throttled); \
842 assert(!mem->fictitious); \
843 vm_page_inactive_count--; \
844 if (mem->clean_queue) { \
845 queue_remove(&vm_page_queue_cleaned, \
846 mem, vm_page_t, pageq); \
847 mem->clean_queue = FALSE; \
848 vm_page_cleaned_count--; \
850 if (mem->object->internal) { \
851 queue_remove(&vm_page_queue_anonymous, \
852 mem, vm_page_t, pageq); \
853 vm_page_anonymous_count--; \
855 queue_remove(&vm_page_queue_inactive, \
856 mem, vm_page_t, pageq); \
858 vm_purgeable_q_advance_all(); \
860 mem->inactive = FALSE; \
861 was_pageable = TRUE; \
864 else if (mem->throttled) { \
865 assert(mem->object != compressor_object); \
866 assert(!mem->active && !mem->inactive); \
867 assert(!mem->speculative); \
868 assert(!mem->fictitious); \
869 queue_remove(&vm_page_queue_throttled, \
870 mem, vm_page_t, pageq); \
871 mem->throttled = FALSE; \
872 vm_page_throttled_count--; \
873 was_pageable = FALSE; \
876 else if (mem->speculative) { \
877 assert(mem->object != compressor_object); \
878 assert(!mem->active && !mem->inactive); \
879 assert(!mem->throttled); \
880 assert(!mem->fictitious); \
881 remque(&mem->pageq); \
882 mem->speculative = FALSE; \
883 vm_page_speculative_count--; \
884 was_pageable = TRUE; \
887 else if (mem->pageq.next || mem->pageq.prev) { \
888 was_pageable = FALSE; \
889 panic("VM_PAGE_QUEUES_REMOVE: unmarked page on Q"); \
891 was_pageable = FALSE; \
894 mem->pageq.next = NULL; \
895 mem->pageq.prev = NULL; \
896 VM_PAGE_QUEUES_ASSERT(mem, 0); \
897 if (was_pageable) { \
898 if (mem->object->internal) { \
899 vm_page_pageable_internal_count--; \
901 vm_page_pageable_external_count--; \
907 #define VM_PAGE_ENQUEUE_INACTIVE(mem, first) \
909 VM_PAGE_QUEUES_ASSERT(mem, 0); \
910 assert(!mem->fictitious); \
911 assert(!mem->laundry); \
912 assert(!mem->pageout_queue); \
913 if (mem->object->internal) { \
915 queue_enter_first(&vm_page_queue_anonymous, mem, vm_page_t, pageq); \
917 queue_enter(&vm_page_queue_anonymous, mem, vm_page_t, pageq); \
918 vm_page_anonymous_count++; \
919 vm_page_pageable_internal_count++; \
922 queue_enter_first(&vm_page_queue_inactive, mem, vm_page_t, pageq); \
924 queue_enter(&vm_page_queue_inactive, mem, vm_page_t, pageq); \
925 vm_page_pageable_external_count++; \
927 mem->inactive = TRUE; \
928 vm_page_inactive_count++; \
929 token_new_pagecount++; \
933 #if DEVELOPMENT || DEBUG
934 #define VM_PAGE_SPECULATIVE_USED_ADD() \
936 OSAddAtomic(1, &vm_page_speculative_used); \
939 #define VM_PAGE_SPECULATIVE_USED_ADD()
943 #define VM_PAGE_CONSUME_CLUSTERED(mem) \
945 if (mem->clustered) { \
946 assert(mem->object); \
947 mem->object->pages_used++; \
948 mem->clustered = FALSE; \
949 VM_PAGE_SPECULATIVE_USED_ADD(); \
955 #define DW_vm_page_unwire 0x01
956 #define DW_vm_page_wire 0x02
957 #define DW_vm_page_free 0x04
958 #define DW_vm_page_activate 0x08
959 #define DW_vm_page_deactivate_internal 0x10
960 #define DW_vm_page_speculate 0x20
961 #define DW_vm_page_lru 0x40
962 #define DW_vm_pageout_throttle_up 0x80
963 #define DW_PAGE_WAKEUP 0x100
964 #define DW_clear_busy 0x200
965 #define DW_clear_reference 0x400
966 #define DW_set_reference 0x800
967 #define DW_move_page 0x1000
968 #define DW_VM_PAGE_QUEUES_REMOVE 0x2000
969 #define DW_enqueue_cleaned 0x4000
971 struct vm_page_delayed_work
{
976 void vm_page_do_delayed_work(vm_object_t object
, struct vm_page_delayed_work
*dwp
, int dw_count
);
978 extern unsigned int vm_max_delayed_work_limit
;
980 #define DEFAULT_DELAYED_WORK_LIMIT 32
982 #define DELAYED_WORK_LIMIT(max) ((vm_max_delayed_work_limit >= max ? max : vm_max_delayed_work_limit))
985 * vm_page_do_delayed_work may need to drop the object lock...
986 * if it does, we need the pages it's looking at to
987 * be held stable via the busy bit, so if busy isn't already
988 * set, we need to set it and ask vm_page_do_delayed_work
989 * to clear it and wakeup anyone that might have blocked on
990 * it once we're done processing the page.
993 #define VM_PAGE_ADD_DELAYED_WORK(dwp, mem, dw_cnt) \
995 if (mem->busy == FALSE) { \
997 if ( !(dwp->dw_mask & DW_vm_page_free)) \
998 dwp->dw_mask |= (DW_clear_busy | DW_PAGE_WAKEUP); \
1005 extern vm_page_t
vm_object_page_grab(vm_object_t
);
1007 #if VM_PAGE_BUCKETS_CHECK
1008 extern void vm_page_buckets_check(void);
1009 #endif /* VM_PAGE_BUCKETS_CHECK */
1011 #endif /* _VM_VM_PAGE_H_ */