4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1994 John S. Dyson
8 * Copyright (c) 1994 David Greenman
12 * This code is derived from software contributed to Berkeley by
13 * The Mach Operating System project at Carnegie-Mellon University.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * from: @(#)vm_fault.c 8.4 (Berkeley) 1/12/94
42 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
43 * All rights reserved.
45 * Authors: Avadis Tevanian, Jr., Michael Wayne Young
47 * Permission to use, copy, modify and distribute this software and
48 * its documentation is hereby granted, provided that both the copyright
49 * notice and this permission notice appear in all copies of the
50 * software, derivative works or modified versions, and any portions
51 * thereof, and that both notices appear in supporting documentation.
53 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
54 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
55 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
57 * Carnegie Mellon requests users of this software to return to
59 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
60 * School of Computer Science
61 * Carnegie Mellon University
62 * Pittsburgh PA 15213-3890
64 * any improvements or extensions that they make and grant Carnegie the
65 * rights to redistribute these changes.
67 * $FreeBSD: src/sys/vm/vm_fault.c,v 1.108.2.8 2002/02/26 05:49:27 silby Exp $
68 * $DragonFly: src/sys/vm/vm_fault.c,v 1.47 2008/07/01 02:02:56 dillon Exp $
72 * Page fault handling module.
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
79 #include <sys/vnode.h>
80 #include <sys/resourcevar.h>
81 #include <sys/vmmeter.h>
82 #include <sys/vkernel.h>
84 #include <sys/sysctl.h>
86 #include <cpu/lwbuf.h>
89 #include <vm/vm_param.h>
91 #include <vm/vm_map.h>
92 #include <vm/vm_object.h>
93 #include <vm/vm_page.h>
94 #include <vm/vm_pageout.h>
95 #include <vm/vm_kern.h>
96 #include <vm/vm_pager.h>
97 #include <vm/vnode_pager.h>
98 #include <vm/vm_extern.h>
100 #include <sys/thread2.h>
101 #include <vm/vm_page2.h>
109 vm_object_t first_object;
110 vm_prot_t first_prot;
112 vm_map_entry_t entry;
113 int lookup_still_valid;
122 static int debug_cluster = 0;
123 SYSCTL_INT(_vm, OID_AUTO, debug_cluster, CTLFLAG_RW, &debug_cluster, 0, "");
124 int vm_shared_fault = 1;
125 SYSCTL_INT(_vm, OID_AUTO, shared_fault, CTLFLAG_RW, &vm_shared_fault, 0,
126 "Allow shared token on vm_object");
127 static long vm_shared_hit = 0;
128 SYSCTL_LONG(_vm, OID_AUTO, shared_hit, CTLFLAG_RW, &vm_shared_hit, 0,
129 "Successful shared faults");
130 static long vm_shared_miss = 0;
131 SYSCTL_LONG(_vm, OID_AUTO, shared_miss, CTLFLAG_RW, &vm_shared_miss, 0,
132 "Unsuccessful shared faults");
134 static int vm_fault_object(struct faultstate *, vm_pindex_t, vm_prot_t, int);
135 static int vm_fault_vpagetable(struct faultstate *, vm_pindex_t *,
138 static int vm_fault_additional_pages (vm_page_t, int, int, vm_page_t *, int *);
140 static void vm_set_nosync(vm_page_t m, vm_map_entry_t entry);
141 static void vm_prefault(pmap_t pmap, vm_offset_t addra,
142 vm_map_entry_t entry, int prot, int fault_flags);
143 static void vm_prefault_quick(pmap_t pmap, vm_offset_t addra,
144 vm_map_entry_t entry, int prot, int fault_flags);
147 release_page(struct faultstate *fs)
149 vm_page_deactivate(fs->m);
150 vm_page_wakeup(fs->m);
155 * NOTE: Once unlocked any cached fs->entry becomes invalid, any reuse
156 * requires relocking and then checking the timestamp.
158 * NOTE: vm_map_lock_read() does not bump fs->map->timestamp so we do
159 * not have to update fs->map_generation here.
161 * NOTE: This function can fail due to a deadlock against the caller's
162 * holding of a vm_page BUSY.
165 relock_map(struct faultstate *fs)
169 if (fs->lookup_still_valid == FALSE && fs->map) {
170 error = vm_map_lock_read_to(fs->map);
172 fs->lookup_still_valid = TRUE;
180 unlock_map(struct faultstate *fs)
182 if (fs->lookup_still_valid && fs->map) {
183 vm_map_lookup_done(fs->map, fs->entry, 0);
184 fs->lookup_still_valid = FALSE;
189 * Clean up after a successful call to vm_fault_object() so another call
190 * to vm_fault_object() can be made.
193 _cleanup_successful_fault(struct faultstate *fs, int relock)
195 if (fs->object != fs->first_object) {
196 vm_page_free(fs->first_m);
197 vm_object_pip_wakeup(fs->object);
200 fs->object = fs->first_object;
201 if (relock && fs->lookup_still_valid == FALSE) {
203 vm_map_lock_read(fs->map);
204 fs->lookup_still_valid = TRUE;
209 _unlock_things(struct faultstate *fs, int dealloc)
211 _cleanup_successful_fault(fs, 0);
213 /*vm_object_deallocate(fs->first_object);*/
214 /*fs->first_object = NULL; drop used later on */
217 if (fs->vp != NULL) {
223 #define unlock_things(fs) _unlock_things(fs, 0)
224 #define unlock_and_deallocate(fs) _unlock_things(fs, 1)
225 #define cleanup_successful_fault(fs) _cleanup_successful_fault(fs, 1)
230 * Determine if the pager for the current object *might* contain the page.
232 * We only need to try the pager if this is not a default object (default
233 * objects are zero-fill and have no real pager), and if we are not taking
234 * a wiring fault or if the FS entry is wired.
236 #define TRYPAGER(fs) \
237 (fs->object->type != OBJT_DEFAULT && \
238 (((fs->fault_flags & VM_FAULT_WIRE_MASK) == 0) || fs->wired))
243 * Handle a page fault occuring at the given address, requiring the given
244 * permissions, in the map specified. If successful, the page is inserted
245 * into the associated physical map.
247 * NOTE: The given address should be truncated to the proper page address.
249 * KERN_SUCCESS is returned if the page fault is handled; otherwise,
250 * a standard error specifying why the fault is fatal is returned.
252 * The map in question must be referenced, and remains so.
253 * The caller may hold no locks.
254 * No other requirements.
257 vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags)
260 vm_pindex_t first_pindex;
261 struct faultstate fs;
266 vm_page_pcpu_cache();
268 fs.fault_flags = fault_flags;
272 if ((lp = curthread->td_lwp) != NULL)
273 lp->lwp_flags |= LWP_PAGING;
275 lwkt_gettoken(&map->token);
279 * Find the vm_map_entry representing the backing store and resolve
280 * the top level object and page index. This may have the side
281 * effect of executing a copy-on-write on the map entry and/or
282 * creating a shadow object, but will not COW any actual VM pages.
284 * On success fs.map is left read-locked and various other fields
285 * are initialized but not otherwise referenced or locked.
287 * NOTE! vm_map_lookup will try to upgrade the fault_type to
288 * VM_FAULT_WRITE if the map entry is a virtual page table and also
289 * writable, so we can set the 'A'accessed bit in the virtual page
293 result = vm_map_lookup(&fs.map, vaddr, fault_type,
294 &fs.entry, &fs.first_object,
295 &first_pindex, &fs.first_prot, &fs.wired);
298 * If the lookup failed or the map protections are incompatible,
299 * the fault generally fails. However, if the caller is trying
300 * to do a user wiring we have more work to do.
302 if (result != KERN_SUCCESS) {
303 if (result != KERN_PROTECTION_FAILURE ||
304 (fs.fault_flags & VM_FAULT_WIRE_MASK) != VM_FAULT_USER_WIRE)
306 if (result == KERN_INVALID_ADDRESS && growstack &&
307 map != &kernel_map && curproc != NULL) {
308 result = vm_map_growstack(curproc, vaddr);
309 if (result == KERN_SUCCESS) {
314 result = KERN_FAILURE;
320 * If we are user-wiring a r/w segment, and it is COW, then
321 * we need to do the COW operation. Note that we don't
322 * currently COW RO sections now, because it is NOT desirable
323 * to COW .text. We simply keep .text from ever being COW'ed
324 * and take the heat that one cannot debug wired .text sections.
326 result = vm_map_lookup(&fs.map, vaddr,
327 VM_PROT_READ|VM_PROT_WRITE|
328 VM_PROT_OVERRIDE_WRITE,
329 &fs.entry, &fs.first_object,
330 &first_pindex, &fs.first_prot,
332 if (result != KERN_SUCCESS) {
333 result = KERN_FAILURE;
338 * If we don't COW now, on a user wire, the user will never
339 * be able to write to the mapping. If we don't make this
340 * restriction, the bookkeeping would be nearly impossible.
342 * XXX We have a shared lock, this will have a MP race but
343 * I don't see how it can hurt anything.
345 if ((fs.entry->protection & VM_PROT_WRITE) == 0)
346 fs.entry->max_protection &= ~VM_PROT_WRITE;
350 * fs.map is read-locked
352 * Misc checks. Save the map generation number to detect races.
354 fs.map_generation = fs.map->timestamp;
355 fs.lookup_still_valid = TRUE;
357 fs.object = fs.first_object; /* so unlock_and_deallocate works */
361 if (fs.entry->eflags & (MAP_ENTRY_NOFAULT | MAP_ENTRY_KSTACK)) {
362 if (fs.entry->eflags & MAP_ENTRY_NOFAULT) {
363 panic("vm_fault: fault on nofault entry, addr: %p",
366 if ((fs.entry->eflags & MAP_ENTRY_KSTACK) &&
367 vaddr >= fs.entry->start &&
368 vaddr < fs.entry->start + PAGE_SIZE) {
369 panic("vm_fault: fault on stack guard, addr: %p",
375 * A system map entry may return a NULL object. No object means
376 * no pager means an unrecoverable kernel fault.
378 if (fs.first_object == NULL) {
379 panic("vm_fault: unrecoverable fault at %p in entry %p",
380 (void *)vaddr, fs.entry);
384 * Fail here if not a trivial anonymous page fault and TDF_NOFAULT
387 if ((curthread->td_flags & TDF_NOFAULT) &&
389 fs.first_object->type == OBJT_VNODE ||
390 fs.first_object->backing_object)) {
391 result = KERN_FAILURE;
397 * Attempt to shortcut the fault if the lookup returns a
398 * terminal object and the page is present. This allows us
399 * to obtain a shared token on the object instead of an exclusive
400 * token, which theoretically should allow concurrent faults.
402 * We cannot acquire a shared token on kernel_map, at least not
403 * on i386, because the i386 pmap code uses the kernel_object for
404 * its page table page management, resulting in a shared->exclusive
405 * sequence which will deadlock. This will not happen normally
406 * anyway, except on well cached pageable kmem (like pipe buffers),
407 * so it should not impact performance.
409 if (vm_shared_fault &&
410 fs.first_object->backing_object == NULL &&
411 fs.entry->maptype == VM_MAPTYPE_NORMAL &&
412 fs.map != &kernel_map) {
414 vm_object_hold_shared(fs.first_object);
415 /*fs.vp = vnode_pager_lock(fs.first_object);*/
416 fs.m = vm_page_lookup_busy_try(fs.first_object,
419 if (error == 0 && fs.m) {
421 * Activate the page and figure out if we can
422 * short-cut a quick mapping.
424 * WARNING! We cannot call swap_pager_unswapped()
425 * with a shared token! Note that we
426 * have to test fs.first_prot here.
428 vm_page_activate(fs.m);
429 if (fs.m->valid == VM_PAGE_BITS_ALL &&
430 ((fs.m->flags & PG_SWAPPED) == 0 ||
431 (fs.first_prot & VM_PROT_WRITE) == 0 ||
432 (fs.fault_flags & VM_FAULT_DIRTY) == 0)) {
433 fs.lookup_still_valid = TRUE;
435 fs.object = fs.first_object;
436 fs.prot = fs.first_prot;
438 fault_type = fs.first_prot;
439 if (fs.prot & VM_PROT_WRITE) {
440 vm_object_set_writeable_dirty(
442 vm_set_nosync(fs.m, fs.entry);
443 if (fs.fault_flags & VM_FAULT_DIRTY) {
446 swap_pager_unswapped(fs.m);
449 result = KERN_SUCCESS;
450 fault_flags |= VM_FAULT_BURST_QUICK;
451 fault_flags &= ~VM_FAULT_BURST;
455 vm_page_wakeup(fs.m);
458 vm_object_drop(fs.first_object); /* XXX drop on shared tok?*/
463 * Bump the paging-in-progress count to prevent size changes (e.g.
464 * truncation operations) during I/O. This must be done after
465 * obtaining the vnode lock in order to avoid possible deadlocks.
467 vm_object_hold(fs.first_object);
469 fs.vp = vnode_pager_lock(fs.first_object);
472 fs.lookup_still_valid = TRUE;
474 fs.object = fs.first_object; /* so unlock_and_deallocate works */
479 * If the entry is wired we cannot change the page protection.
482 fault_type = fs.first_prot;
485 * The page we want is at (first_object, first_pindex), but if the
486 * vm_map_entry is VM_MAPTYPE_VPAGETABLE we have to traverse the
487 * page table to figure out the actual pindex.
489 * NOTE! DEVELOPMENT IN PROGRESS, THIS IS AN INITIAL IMPLEMENTATION
492 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
493 result = vm_fault_vpagetable(&fs, &first_pindex,
494 fs.entry->aux.master_pde,
496 if (result == KERN_TRY_AGAIN) {
497 vm_object_drop(fs.first_object);
501 if (result != KERN_SUCCESS)
506 * Now we have the actual (object, pindex), fault in the page. If
507 * vm_fault_object() fails it will unlock and deallocate the FS
508 * data. If it succeeds everything remains locked and fs->object
509 * will have an additional PIP count if it is not equal to
512 * vm_fault_object will set fs->prot for the pmap operation. It is
513 * allowed to set VM_PROT_WRITE if fault_type == VM_PROT_READ if the
514 * page can be safely written. However, it will force a read-only
515 * mapping for a read fault if the memory is managed by a virtual
518 * If the fault code uses the shared object lock shortcut
519 * we must not try to burst (we can't allocate VM pages).
521 result = vm_fault_object(&fs, first_pindex, fault_type, 1);
523 fault_flags &= ~VM_FAULT_BURST;
525 if (result == KERN_TRY_AGAIN) {
526 vm_object_drop(fs.first_object);
530 if (result != KERN_SUCCESS)
535 * On success vm_fault_object() does not unlock or deallocate, and fs.m
536 * will contain a busied page.
538 * Enter the page into the pmap and do pmap-related adjustments.
540 vm_page_flag_set(fs.m, PG_REFERENCED);
541 pmap_enter(fs.map->pmap, vaddr, fs.m, fs.prot, fs.wired, fs.entry);
542 mycpu->gd_cnt.v_vm_faults++;
543 if (curthread->td_lwp)
544 ++curthread->td_lwp->lwp_ru.ru_minflt;
546 /*KKASSERT(fs.m->queue == PQ_NONE); page-in op may deactivate page */
547 KKASSERT(fs.m->flags & PG_BUSY);
550 * If the page is not wired down, then put it where the pageout daemon
553 if (fs.fault_flags & VM_FAULT_WIRE_MASK) {
557 vm_page_unwire(fs.m, 1);
559 vm_page_activate(fs.m);
561 vm_page_wakeup(fs.m);
564 * Burst in a few more pages if possible. The fs.map should still
565 * be locked. To avoid interlocking against a vnode->getblk
566 * operation we had to be sure to unbusy our primary vm_page above
569 if (fault_flags & VM_FAULT_BURST) {
570 if ((fs.fault_flags & VM_FAULT_WIRE_MASK) == 0
572 vm_prefault(fs.map->pmap, vaddr,
573 fs.entry, fs.prot, fault_flags);
576 if (fault_flags & VM_FAULT_BURST_QUICK) {
577 if ((fs.fault_flags & VM_FAULT_WIRE_MASK) == 0
579 vm_prefault_quick(fs.map->pmap, vaddr,
580 fs.entry, fs.prot, fault_flags);
585 * Unlock everything, and return
589 if (curthread->td_lwp) {
591 curthread->td_lwp->lwp_ru.ru_majflt++;
593 curthread->td_lwp->lwp_ru.ru_minflt++;
597 /*vm_object_deallocate(fs.first_object);*/
599 /*fs.first_object = NULL; must still drop later */
601 result = KERN_SUCCESS;
604 vm_object_drop(fs.first_object);
606 lwkt_reltoken(&map->token);
608 lp->lwp_flags &= ~LWP_PAGING;
613 * Fault in the specified virtual address in the current process map,
614 * returning a held VM page or NULL. See vm_fault_page() for more
620 vm_fault_page_quick(vm_offset_t va, vm_prot_t fault_type, int *errorp)
622 struct lwp *lp = curthread->td_lwp;
625 m = vm_fault_page(&lp->lwp_vmspace->vm_map, va,
626 fault_type, VM_FAULT_NORMAL, errorp);
631 * Fault in the specified virtual address in the specified map, doing all
632 * necessary manipulation of the object store and all necessary I/O. Return
633 * a held VM page or NULL, and set *errorp. The related pmap is not
636 * The returned page will be properly dirtied if VM_PROT_WRITE was specified,
637 * and marked PG_REFERENCED as well.
639 * If the page cannot be faulted writable and VM_PROT_WRITE was specified, an
640 * error will be returned.
645 vm_fault_page(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
646 int fault_flags, int *errorp)
648 vm_pindex_t first_pindex;
649 struct faultstate fs;
652 vm_prot_t orig_fault_type = fault_type;
655 fs.fault_flags = fault_flags;
656 KKASSERT((fault_flags & VM_FAULT_WIRE_MASK) == 0);
658 lwkt_gettoken(&map->token);
662 * Find the vm_map_entry representing the backing store and resolve
663 * the top level object and page index. This may have the side
664 * effect of executing a copy-on-write on the map entry and/or
665 * creating a shadow object, but will not COW any actual VM pages.
667 * On success fs.map is left read-locked and various other fields
668 * are initialized but not otherwise referenced or locked.
670 * NOTE! vm_map_lookup will upgrade the fault_type to VM_FAULT_WRITE
671 * if the map entry is a virtual page table and also writable,
672 * so we can set the 'A'accessed bit in the virtual page table entry.
675 result = vm_map_lookup(&fs.map, vaddr, fault_type,
676 &fs.entry, &fs.first_object,
677 &first_pindex, &fs.first_prot, &fs.wired);
679 if (result != KERN_SUCCESS) {
686 * fs.map is read-locked
688 * Misc checks. Save the map generation number to detect races.
690 fs.map_generation = fs.map->timestamp;
691 fs.lookup_still_valid = TRUE;
693 fs.object = fs.first_object; /* so unlock_and_deallocate works */
697 if (fs.entry->eflags & MAP_ENTRY_NOFAULT) {
698 panic("vm_fault: fault on nofault entry, addr: %lx",
703 * A system map entry may return a NULL object. No object means
704 * no pager means an unrecoverable kernel fault.
706 if (fs.first_object == NULL) {
707 panic("vm_fault: unrecoverable fault at %p in entry %p",
708 (void *)vaddr, fs.entry);
712 * Fail here if not a trivial anonymous page fault and TDF_NOFAULT
715 if ((curthread->td_flags & TDF_NOFAULT) &&
717 fs.first_object->type == OBJT_VNODE ||
718 fs.first_object->backing_object)) {
719 *errorp = KERN_FAILURE;
725 * Make a reference to this object to prevent its disposal while we
726 * are messing with it. Once we have the reference, the map is free
727 * to be diddled. Since objects reference their shadows (and copies),
728 * they will stay around as well.
730 * The reference should also prevent an unexpected collapse of the
731 * parent that might move pages from the current object into the
732 * parent unexpectedly, resulting in corruption.
734 * Bump the paging-in-progress count to prevent size changes (e.g.
735 * truncation operations) during I/O. This must be done after
736 * obtaining the vnode lock in order to avoid possible deadlocks.
738 vm_object_hold(fs.first_object);
739 fs.vp = vnode_pager_lock(fs.first_object);
742 fs.lookup_still_valid = TRUE;
744 fs.object = fs.first_object; /* so unlock_and_deallocate works */
749 * If the entry is wired we cannot change the page protection.
752 fault_type = fs.first_prot;
755 * The page we want is at (first_object, first_pindex), but if the
756 * vm_map_entry is VM_MAPTYPE_VPAGETABLE we have to traverse the
757 * page table to figure out the actual pindex.
759 * NOTE! DEVELOPMENT IN PROGRESS, THIS IS AN INITIAL IMPLEMENTATION
762 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
763 result = vm_fault_vpagetable(&fs, &first_pindex,
764 fs.entry->aux.master_pde,
766 if (result == KERN_TRY_AGAIN) {
767 vm_object_drop(fs.first_object);
771 if (result != KERN_SUCCESS) {
779 * Now we have the actual (object, pindex), fault in the page. If
780 * vm_fault_object() fails it will unlock and deallocate the FS
781 * data. If it succeeds everything remains locked and fs->object
782 * will have an additinal PIP count if it is not equal to
786 result = vm_fault_object(&fs, first_pindex, fault_type, 1);
788 if (result == KERN_TRY_AGAIN) {
789 vm_object_drop(fs.first_object);
793 if (result != KERN_SUCCESS) {
799 if ((orig_fault_type & VM_PROT_WRITE) &&
800 (fs.prot & VM_PROT_WRITE) == 0) {
801 *errorp = KERN_PROTECTION_FAILURE;
802 unlock_and_deallocate(&fs);
808 * DO NOT UPDATE THE PMAP!!! This function may be called for
809 * a pmap unrelated to the current process pmap, in which case
810 * the current cpu core will not be listed in the pmap's pm_active
811 * mask. Thus invalidation interlocks will fail to work properly.
813 * (for example, 'ps' uses procfs to read program arguments from
814 * each process's stack).
816 * In addition to the above this function will be called to acquire
817 * a page that might already be faulted in, re-faulting it
818 * continuously is a waste of time.
820 * XXX could this have been the cause of our random seg-fault
821 * issues? procfs accesses user stacks.
823 vm_page_flag_set(fs.m, PG_REFERENCED);
825 pmap_enter(fs.map->pmap, vaddr, fs.m, fs.prot, fs.wired, NULL);
826 mycpu->gd_cnt.v_vm_faults++;
827 if (curthread->td_lwp)
828 ++curthread->td_lwp->lwp_ru.ru_minflt;
832 * On success vm_fault_object() does not unlock or deallocate, and fs.m
833 * will contain a busied page. So we must unlock here after having
834 * messed with the pmap.
839 * Return a held page. We are not doing any pmap manipulation so do
840 * not set PG_MAPPED. However, adjust the page flags according to
841 * the fault type because the caller may not use a managed pmapping
842 * (so we don't want to lose the fact that the page will be dirtied
843 * if a write fault was specified).
846 vm_page_activate(fs.m);
847 if (fault_type & VM_PROT_WRITE)
850 if (curthread->td_lwp) {
852 curthread->td_lwp->lwp_ru.ru_majflt++;
854 curthread->td_lwp->lwp_ru.ru_minflt++;
859 * Unlock everything, and return the held page.
861 vm_page_wakeup(fs.m);
862 /*vm_object_deallocate(fs.first_object);*/
863 /*fs.first_object = NULL; */
868 vm_object_drop(fs.first_object);
870 lwkt_reltoken(&map->token);
875 * Fault in the specified (object,offset), dirty the returned page as
876 * needed. If the requested fault_type cannot be done NULL and an
879 * A held (but not busied) page is returned.
884 vm_fault_object_page(vm_object_t object, vm_ooffset_t offset,
885 vm_prot_t fault_type, int fault_flags,
886 int shared, int *errorp)
889 vm_pindex_t first_pindex;
890 struct faultstate fs;
891 struct vm_map_entry entry;
893 ASSERT_LWKT_TOKEN_HELD(vm_object_token(object));
894 bzero(&entry, sizeof(entry));
895 entry.object.vm_object = object;
896 entry.maptype = VM_MAPTYPE_NORMAL;
897 entry.protection = entry.max_protection = fault_type;
900 fs.fault_flags = fault_flags;
902 KKASSERT((fault_flags & VM_FAULT_WIRE_MASK) == 0);
906 fs.first_object = object;
907 first_pindex = OFF_TO_IDX(offset);
909 fs.first_prot = fault_type;
912 /*fs.map_generation = 0; unused */
915 * Make a reference to this object to prevent its disposal while we
916 * are messing with it. Once we have the reference, the map is free
917 * to be diddled. Since objects reference their shadows (and copies),
918 * they will stay around as well.
920 * The reference should also prevent an unexpected collapse of the
921 * parent that might move pages from the current object into the
922 * parent unexpectedly, resulting in corruption.
924 * Bump the paging-in-progress count to prevent size changes (e.g.
925 * truncation operations) during I/O. This must be done after
926 * obtaining the vnode lock in order to avoid possible deadlocks.
928 fs.vp = vnode_pager_lock(fs.first_object);
930 fs.lookup_still_valid = TRUE;
932 fs.object = fs.first_object; /* so unlock_and_deallocate works */
935 /* XXX future - ability to operate on VM object using vpagetable */
936 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
937 result = vm_fault_vpagetable(&fs, &first_pindex,
938 fs.entry->aux.master_pde,
940 if (result == KERN_TRY_AGAIN)
942 if (result != KERN_SUCCESS) {
950 * Now we have the actual (object, pindex), fault in the page. If
951 * vm_fault_object() fails it will unlock and deallocate the FS
952 * data. If it succeeds everything remains locked and fs->object
953 * will have an additinal PIP count if it is not equal to
956 result = vm_fault_object(&fs, first_pindex, fault_type, 0);
958 if (result == KERN_TRY_AGAIN)
960 if (result != KERN_SUCCESS) {
965 if ((fault_type & VM_PROT_WRITE) && (fs.prot & VM_PROT_WRITE) == 0) {
966 *errorp = KERN_PROTECTION_FAILURE;
967 unlock_and_deallocate(&fs);
972 * On success vm_fault_object() does not unlock or deallocate, so we
973 * do it here. Note that the returned fs.m will be busied.
978 * Return a held page. We are not doing any pmap manipulation so do
979 * not set PG_MAPPED. However, adjust the page flags according to
980 * the fault type because the caller may not use a managed pmapping
981 * (so we don't want to lose the fact that the page will be dirtied
982 * if a write fault was specified).
985 vm_page_activate(fs.m);
986 if ((fault_type & VM_PROT_WRITE) || (fault_flags & VM_FAULT_DIRTY))
988 if (fault_flags & VM_FAULT_UNSWAP)
989 swap_pager_unswapped(fs.m);
992 * Indicate that the page was accessed.
994 vm_page_flag_set(fs.m, PG_REFERENCED);
996 if (curthread->td_lwp) {
998 curthread->td_lwp->lwp_ru.ru_majflt++;
1000 curthread->td_lwp->lwp_ru.ru_minflt++;
1005 * Unlock everything, and return the held page.
1007 vm_page_wakeup(fs.m);
1008 /*vm_object_deallocate(fs.first_object);*/
1009 /*fs.first_object = NULL; */
1016 * Translate the virtual page number (first_pindex) that is relative
1017 * to the address space into a logical page number that is relative to the
1018 * backing object. Use the virtual page table pointed to by (vpte).
1020 * This implements an N-level page table. Any level can terminate the
1021 * scan by setting VPTE_PS. A linear mapping is accomplished by setting
1022 * VPTE_PS in the master page directory entry set via mcontrol(MADV_SETMAP).
1026 vm_fault_vpagetable(struct faultstate *fs, vm_pindex_t *pindex,
1027 vpte_t vpte, int fault_type, int allow_nofault)
1030 struct lwbuf lwb_cache;
1031 int vshift = VPTE_FRAME_END - PAGE_SHIFT; /* index bits remaining */
1032 int result = KERN_SUCCESS;
1035 ASSERT_LWKT_TOKEN_HELD(vm_object_token(fs->first_object));
1038 * We cannot proceed if the vpte is not valid, not readable
1039 * for a read fault, or not writable for a write fault.
1041 if ((vpte & VPTE_V) == 0) {
1042 unlock_and_deallocate(fs);
1043 return (KERN_FAILURE);
1045 if ((fault_type & VM_PROT_READ) && (vpte & VPTE_R) == 0) {
1046 unlock_and_deallocate(fs);
1047 return (KERN_FAILURE);
1049 if ((fault_type & VM_PROT_WRITE) && (vpte & VPTE_W) == 0) {
1050 unlock_and_deallocate(fs);
1051 return (KERN_FAILURE);
1053 if ((vpte & VPTE_PS) || vshift == 0)
1055 KKASSERT(vshift >= VPTE_PAGE_BITS);
1058 * Get the page table page. Nominally we only read the page
1059 * table, but since we are actively setting VPTE_M and VPTE_A,
1060 * tell vm_fault_object() that we are writing it.
1062 * There is currently no real need to optimize this.
1064 result = vm_fault_object(fs, (vpte & VPTE_FRAME) >> PAGE_SHIFT,
1065 VM_PROT_READ|VM_PROT_WRITE,
1067 if (result != KERN_SUCCESS)
1071 * Process the returned fs.m and look up the page table
1072 * entry in the page table page.
1074 vshift -= VPTE_PAGE_BITS;
1075 lwb = lwbuf_alloc(fs->m, &lwb_cache);
1076 ptep = ((vpte_t *)lwbuf_kva(lwb) +
1077 ((*pindex >> vshift) & VPTE_PAGE_MASK));
1081 * Page table write-back. If the vpte is valid for the
1082 * requested operation, do a write-back to the page table.
1084 * XXX VPTE_M is not set properly for page directory pages.
1085 * It doesn't get set in the page directory if the page table
1086 * is modified during a read access.
1088 vm_page_activate(fs->m);
1089 if ((fault_type & VM_PROT_WRITE) && (vpte & VPTE_V) &&
1091 if ((vpte & (VPTE_M|VPTE_A)) != (VPTE_M|VPTE_A)) {
1092 atomic_set_long(ptep, VPTE_M | VPTE_A);
1093 vm_page_dirty(fs->m);
1096 if ((fault_type & VM_PROT_READ) && (vpte & VPTE_V) &&
1098 if ((vpte & VPTE_A) == 0) {
1099 atomic_set_long(ptep, VPTE_A);
1100 vm_page_dirty(fs->m);
1104 vm_page_flag_set(fs->m, PG_REFERENCED);
1105 vm_page_wakeup(fs->m);
1107 cleanup_successful_fault(fs);
1110 * Combine remaining address bits with the vpte.
1112 /* JG how many bits from each? */
1113 *pindex = ((vpte & VPTE_FRAME) >> PAGE_SHIFT) +
1114 (*pindex & ((1L << vshift) - 1));
1115 return (KERN_SUCCESS);
1120 * This is the core of the vm_fault code.
1122 * Do all operations required to fault-in (fs.first_object, pindex). Run
1123 * through the shadow chain as necessary and do required COW or virtual
1124 * copy operations. The caller has already fully resolved the vm_map_entry
1125 * and, if appropriate, has created a copy-on-write layer. All we need to
1126 * do is iterate the object chain.
1128 * On failure (fs) is unlocked and deallocated and the caller may return or
1129 * retry depending on the failure code. On success (fs) is NOT unlocked or
1130 * deallocated, fs.m will contained a resolved, busied page, and fs.object
1131 * will have an additional PIP count if it is not equal to fs.first_object.
1133 * fs->first_object must be held on call.
1137 vm_fault_object(struct faultstate *fs, vm_pindex_t first_pindex,
1138 vm_prot_t fault_type, int allow_nofault)
1140 vm_object_t next_object;
1144 ASSERT_LWKT_TOKEN_HELD(vm_object_token(fs->first_object));
1145 fs->prot = fs->first_prot;
1146 fs->object = fs->first_object;
1147 pindex = first_pindex;
1149 vm_object_chain_acquire(fs->first_object);
1150 vm_object_pip_add(fs->first_object, 1);
1153 * If a read fault occurs we try to make the page writable if
1154 * possible. There are three cases where we cannot make the
1155 * page mapping writable:
1157 * (1) The mapping is read-only or the VM object is read-only,
1158 * fs->prot above will simply not have VM_PROT_WRITE set.
1160 * (2) If the mapping is a virtual page table we need to be able
1161 * to detect writes so we can set VPTE_M in the virtual page
1164 * (3) If the VM page is read-only or copy-on-write, upgrading would
1165 * just result in an unnecessary COW fault.
1167 * VM_PROT_VPAGED is set if faulting via a virtual page table and
1168 * causes adjustments to the 'M'odify bit to also turn off write
1169 * access to force a re-fault.
1171 if (fs->entry->maptype == VM_MAPTYPE_VPAGETABLE) {
1172 if ((fault_type & VM_PROT_WRITE) == 0)
1173 fs->prot &= ~VM_PROT_WRITE;
1176 /* vm_object_hold(fs->object); implied b/c object == first_object */
1180 * The entire backing chain from first_object to object
1181 * inclusive is chainlocked.
1183 * If the object is dead, we stop here
1185 * vm_shared_fault (fs->shared != 0) case: nothing special.
1187 if (fs->object->flags & OBJ_DEAD) {
1188 vm_object_pip_wakeup(fs->first_object);
1189 vm_object_chain_release_all(fs->first_object,
1191 if (fs->object != fs->first_object)
1192 vm_object_drop(fs->object);
1193 unlock_and_deallocate(fs);
1194 return (KERN_PROTECTION_FAILURE);
1198 * See if the page is resident. Wait/Retry if the page is
1199 * busy (lots of stuff may have changed so we can't continue
1202 * We can theoretically allow the soft-busy case on a read
1203 * fault if the page is marked valid, but since such
1204 * pages are typically already pmap'd, putting that
1205 * special case in might be more effort then it is
1206 * worth. We cannot under any circumstances mess
1207 * around with a vm_page_t->busy page except, perhaps,
1210 * vm_shared_fault (fs->shared != 0) case:
1211 * error nothing special
1212 * fs->m relock excl if I/O needed
1215 fs->m = vm_page_lookup_busy_try(fs->object, pindex,
1218 vm_object_pip_wakeup(fs->first_object);
1219 vm_object_chain_release_all(fs->first_object,
1221 if (fs->object != fs->first_object)
1222 vm_object_drop(fs->object);
1224 vm_page_sleep_busy(fs->m, TRUE, "vmpfw");
1225 mycpu->gd_cnt.v_intrans++;
1226 /*vm_object_deallocate(fs->first_object);*/
1227 /*fs->first_object = NULL;*/
1229 return (KERN_TRY_AGAIN);
1233 * The page is busied for us.
1235 * If reactivating a page from PQ_CACHE we may have
1238 int queue = fs->m->queue;
1239 vm_page_unqueue_nowakeup(fs->m);
1241 if ((queue - fs->m->pc) == PQ_CACHE &&
1242 vm_page_count_severe()) {
1243 vm_page_activate(fs->m);
1244 vm_page_wakeup(fs->m);
1246 vm_object_pip_wakeup(fs->first_object);
1247 vm_object_chain_release_all(fs->first_object,
1249 if (fs->object != fs->first_object)
1250 vm_object_drop(fs->object);
1251 unlock_and_deallocate(fs);
1252 if (allow_nofault == 0 ||
1253 (curthread->td_flags & TDF_NOFAULT) == 0) {
1256 return (KERN_TRY_AGAIN);
1260 * If it still isn't completely valid (readable),
1261 * or if a read-ahead-mark is set on the VM page,
1262 * jump to readrest, else we found the page and
1265 * We can release the spl once we have marked the
1268 if (fs->m->object != &kernel_object) {
1269 if ((fs->m->valid & VM_PAGE_BITS_ALL) !=
1272 vm_object_drop(fs->object);
1273 vm_object_hold(fs->object);
1278 if (fs->m->flags & PG_RAM) {
1281 vm_page_flag_clear(fs->m, PG_RAM);
1283 vm_object_drop(fs->object);
1284 vm_object_hold(fs->object);
1290 break; /* break to PAGE HAS BEEN FOUND */
1294 vm_object_drop(fs->object);
1295 vm_object_hold(fs->object);
1300 * Page is not resident, If this is the search termination
1301 * or the pager might contain the page, allocate a new page.
1303 if (TRYPAGER(fs) || fs->object == fs->first_object) {
1305 * If the page is beyond the object size we fail
1307 if (pindex >= fs->object->size) {
1308 vm_object_pip_wakeup(fs->first_object);
1309 vm_object_chain_release_all(fs->first_object,
1311 if (fs->object != fs->first_object)
1312 vm_object_drop(fs->object);
1313 unlock_and_deallocate(fs);
1314 return (KERN_PROTECTION_FAILURE);
1318 * Allocate a new page for this object/offset pair.
1320 * It is possible for the allocation to race, so
1324 if (!vm_page_count_severe()) {
1325 fs->m = vm_page_alloc(fs->object, pindex,
1326 ((fs->vp || fs->object->backing_object) ?
1327 VM_ALLOC_NULL_OK | VM_ALLOC_NORMAL :
1328 VM_ALLOC_NULL_OK | VM_ALLOC_NORMAL |
1329 VM_ALLOC_USE_GD | VM_ALLOC_ZERO));
1331 if (fs->m == NULL) {
1332 vm_object_pip_wakeup(fs->first_object);
1333 vm_object_chain_release_all(fs->first_object,
1335 if (fs->object != fs->first_object)
1336 vm_object_drop(fs->object);
1337 unlock_and_deallocate(fs);
1338 if (allow_nofault == 0 ||
1339 (curthread->td_flags & TDF_NOFAULT) == 0) {
1342 return (KERN_TRY_AGAIN);
1346 * Fall through to readrest. We have a new page which
1347 * will have to be paged (since m->valid will be 0).
1353 * We have found an invalid or partially valid page, a
1354 * page with a read-ahead mark which might be partially or
1355 * fully valid (and maybe dirty too), or we have allocated
1358 * Attempt to fault-in the page if there is a chance that the
1359 * pager has it, and potentially fault in additional pages
1362 * If TRYPAGER is true then fs.m will be non-NULL and busied
1368 u_char behavior = vm_map_entry_behavior(fs->entry);
1370 if (behavior == MAP_ENTRY_BEHAV_RANDOM)
1377 * If sequential access is detected then attempt
1378 * to deactivate/cache pages behind the scan to
1379 * prevent resource hogging.
1381 * Use of PG_RAM to detect sequential access
1382 * also simulates multi-zone sequential access
1383 * detection for free.
1385 * NOTE: Partially valid dirty pages cannot be
1386 * deactivated without causing NFS picemeal
1389 if ((fs->first_object->type != OBJT_DEVICE) &&
1390 (fs->first_object->type != OBJT_MGTDEVICE) &&
1391 (behavior == MAP_ENTRY_BEHAV_SEQUENTIAL ||
1392 (behavior != MAP_ENTRY_BEHAV_RANDOM &&
1393 (fs->m->flags & PG_RAM)))
1395 vm_pindex_t scan_pindex;
1396 int scan_count = 16;
1398 if (first_pindex < 16) {
1402 scan_pindex = first_pindex - 16;
1403 if (scan_pindex < 16)
1404 scan_count = scan_pindex;
1409 while (scan_count) {
1412 mt = vm_page_lookup(fs->first_object,
1416 if (vm_page_busy_try(mt, TRUE))
1419 if (mt->valid != VM_PAGE_BITS_ALL) {
1424 (PG_FICTITIOUS | PG_UNMANAGED |
1432 vm_page_test_dirty(mt);
1436 vm_page_deactivate(mt);
1451 * Avoid deadlocking against the map when doing I/O.
1452 * fs.object and the page is PG_BUSY'd.
1454 * NOTE: Once unlocked, fs->entry can become stale
1455 * so this will NULL it out.
1457 * NOTE: fs->entry is invalid until we relock the
1458 * map and verify that the timestamp has not
1464 * Acquire the page data. We still hold a ref on
1465 * fs.object and the page has been PG_BUSY's.
1467 * The pager may replace the page (for example, in
1468 * order to enter a fictitious page into the
1469 * object). If it does so it is responsible for
1470 * cleaning up the passed page and properly setting
1471 * the new page PG_BUSY.
1473 * If we got here through a PG_RAM read-ahead
1474 * mark the page may be partially dirty and thus
1475 * not freeable. Don't bother checking to see
1476 * if the pager has the page because we can't free
1477 * it anyway. We have to depend on the get_page
1478 * operation filling in any gaps whether there is
1479 * backing store or not.
1481 rv = vm_pager_get_page(fs->object, &fs->m, seqaccess);
1483 if (rv == VM_PAGER_OK) {
1485 * Relookup in case pager changed page. Pager
1486 * is responsible for disposition of old page
1489 * XXX other code segments do relookups too.
1490 * It's a bad abstraction that needs to be
1493 fs->m = vm_page_lookup(fs->object, pindex);
1494 if (fs->m == NULL) {
1495 vm_object_pip_wakeup(fs->first_object);
1496 vm_object_chain_release_all(
1497 fs->first_object, fs->object);
1498 if (fs->object != fs->first_object)
1499 vm_object_drop(fs->object);
1500 unlock_and_deallocate(fs);
1501 return (KERN_TRY_AGAIN);
1505 break; /* break to PAGE HAS BEEN FOUND */
1509 * Remove the bogus page (which does not exist at this
1510 * object/offset); before doing so, we must get back
1511 * our object lock to preserve our invariant.
1513 * Also wake up any other process that may want to bring
1516 * If this is the top-level object, we must leave the
1517 * busy page to prevent another process from rushing
1518 * past us, and inserting the page in that object at
1519 * the same time that we are.
1521 if (rv == VM_PAGER_ERROR) {
1523 kprintf("vm_fault: pager read error, "
1528 kprintf("vm_fault: pager read error, "
1536 * Data outside the range of the pager or an I/O error
1538 * The page may have been wired during the pagein,
1539 * e.g. by the buffer cache, and cannot simply be
1540 * freed. Call vnode_pager_freepage() to deal with it.
1543 * XXX - the check for kernel_map is a kludge to work
1544 * around having the machine panic on a kernel space
1545 * fault w/ I/O error.
1547 if (((fs->map != &kernel_map) &&
1548 (rv == VM_PAGER_ERROR)) || (rv == VM_PAGER_BAD)) {
1549 vnode_pager_freepage(fs->m);
1551 vm_object_pip_wakeup(fs->first_object);
1552 vm_object_chain_release_all(fs->first_object,
1554 if (fs->object != fs->first_object)
1555 vm_object_drop(fs->object);
1556 unlock_and_deallocate(fs);
1557 if (rv == VM_PAGER_ERROR)
1558 return (KERN_FAILURE);
1560 return (KERN_PROTECTION_FAILURE);
1563 if (fs->object != fs->first_object) {
1564 vnode_pager_freepage(fs->m);
1567 * XXX - we cannot just fall out at this
1568 * point, m has been freed and is invalid!
1574 * We get here if the object has a default pager (or unwiring)
1575 * or the pager doesn't have the page.
1577 if (fs->object == fs->first_object)
1578 fs->first_m = fs->m;
1581 * Move on to the next object. The chain lock should prevent
1582 * the backing_object from getting ripped out from under us.
1584 * vm_shared_fault case:
1586 * If the next object is the last object and
1587 * vnode-backed (thus possibly shared), we can try a
1588 * shared object lock. There is no 'chain' for this
1589 * last object if vnode-backed (otherwise we would
1590 * need an exclusive lock).
1592 * fs->shared mode is very fragile and only works
1593 * under certain specific conditions, and is only
1594 * handled for those conditions in our loop. Essentially
1595 * it is designed only to be able to 'dip into' the
1596 * vnode's object and extract an already-cached page.
1599 if ((next_object = fs->object->backing_object) != NULL) {
1600 fs->shared = vm_object_hold_maybe_shared(next_object);
1601 vm_object_chain_acquire(next_object);
1602 KKASSERT(next_object == fs->object->backing_object);
1603 pindex += OFF_TO_IDX(fs->object->backing_object_offset);
1606 if (next_object == NULL) {
1608 * If there's no object left, fill the page in the top
1609 * object with zeros.
1611 if (fs->object != fs->first_object) {
1612 if (fs->first_object->backing_object !=
1614 vm_object_hold(fs->first_object->backing_object);
1616 vm_object_chain_release_all(
1617 fs->first_object->backing_object,
1619 if (fs->first_object->backing_object !=
1621 vm_object_drop(fs->first_object->backing_object);
1623 vm_object_pip_wakeup(fs->object);
1624 vm_object_drop(fs->object);
1625 fs->object = fs->first_object;
1626 pindex = first_pindex;
1627 fs->m = fs->first_m;
1632 * Zero the page if necessary and mark it valid.
1634 if ((fs->m->flags & PG_ZERO) == 0) {
1635 vm_page_zero_fill(fs->m);
1638 pmap_page_assertzero(VM_PAGE_TO_PHYS(fs->m));
1640 vm_page_flag_clear(fs->m, PG_ZERO);
1641 mycpu->gd_cnt.v_ozfod++;
1643 mycpu->gd_cnt.v_zfod++;
1644 fs->m->valid = VM_PAGE_BITS_ALL;
1645 break; /* break to PAGE HAS BEEN FOUND */
1647 if (fs->object != fs->first_object) {
1648 vm_object_pip_wakeup(fs->object);
1649 vm_object_lock_swap();
1650 vm_object_drop(fs->object);
1652 KASSERT(fs->object != next_object,
1653 ("object loop %p", next_object));
1654 fs->object = next_object;
1655 vm_object_pip_add(fs->object, 1);
1659 * PAGE HAS BEEN FOUND. [Loop invariant still holds -- the object lock
1662 * object still held.
1664 * If the page is being written, but isn't already owned by the
1665 * top-level object, we have to copy it into a new page owned by the
1668 KASSERT((fs->m->flags & PG_BUSY) != 0,
1669 ("vm_fault: not busy after main loop"));
1671 if (fs->object != fs->first_object) {
1673 * We only really need to copy if we want to write it.
1675 if (fault_type & VM_PROT_WRITE) {
1677 * This allows pages to be virtually copied from a
1678 * backing_object into the first_object, where the
1679 * backing object has no other refs to it, and cannot
1680 * gain any more refs. Instead of a bcopy, we just
1681 * move the page from the backing object to the
1682 * first object. Note that we must mark the page
1683 * dirty in the first object so that it will go out
1684 * to swap when needed.
1688 * Map, if present, has not changed
1691 fs->map_generation == fs->map->timestamp) &&
1693 * Only one shadow object
1695 (fs->object->shadow_count == 1) &&
1697 * No COW refs, except us
1699 (fs->object->ref_count == 1) &&
1701 * No one else can look this object up
1703 (fs->object->handle == NULL) &&
1705 * No other ways to look the object up
1707 ((fs->object->type == OBJT_DEFAULT) ||
1708 (fs->object->type == OBJT_SWAP)) &&
1710 * We don't chase down the shadow chain
1712 (fs->object == fs->first_object->backing_object) &&
1715 * grab the lock if we need to
1717 (fs->lookup_still_valid ||
1719 lockmgr(&fs->map->lock, LK_EXCLUSIVE|LK_NOWAIT) == 0)
1722 * (first_m) and (m) are both busied. We have
1723 * move (m) into (first_m)'s object/pindex
1724 * in an atomic fashion, then free (first_m).
1726 * first_object is held so second remove
1727 * followed by the rename should wind
1728 * up being atomic. vm_page_free() might
1729 * block so we don't do it until after the
1732 fs->lookup_still_valid = 1;
1733 vm_page_protect(fs->first_m, VM_PROT_NONE);
1734 vm_page_remove(fs->first_m);
1735 vm_page_rename(fs->m, fs->first_object,
1737 vm_page_free(fs->first_m);
1738 fs->first_m = fs->m;
1740 mycpu->gd_cnt.v_cow_optim++;
1743 * Oh, well, lets copy it.
1745 * Why are we unmapping the original page
1746 * here? Well, in short, not all accessors
1747 * of user memory go through the pmap. The
1748 * procfs code doesn't have access user memory
1749 * via a local pmap, so vm_fault_page*()
1750 * can't call pmap_enter(). And the umtx*()
1751 * code may modify the COW'd page via a DMAP
1752 * or kernel mapping and not via the pmap,
1753 * leaving the original page still mapped
1754 * read-only into the pmap.
1756 * So we have to remove the page from at
1757 * least the current pmap if it is in it.
1758 * Just remove it from all pmaps.
1760 vm_page_copy(fs->m, fs->first_m);
1761 vm_page_protect(fs->m, VM_PROT_NONE);
1762 vm_page_event(fs->m, VMEVENT_COW);
1767 * We no longer need the old page or object.
1773 * We intend to revert to first_object, undo the
1774 * chain lock through to that.
1776 if (fs->first_object->backing_object != fs->object)
1777 vm_object_hold(fs->first_object->backing_object);
1778 vm_object_chain_release_all(
1779 fs->first_object->backing_object,
1781 if (fs->first_object->backing_object != fs->object)
1782 vm_object_drop(fs->first_object->backing_object);
1785 * fs->object != fs->first_object due to above
1788 vm_object_pip_wakeup(fs->object);
1789 vm_object_drop(fs->object);
1792 * Only use the new page below...
1795 mycpu->gd_cnt.v_cow_faults++;
1796 fs->m = fs->first_m;
1797 fs->object = fs->first_object;
1798 pindex = first_pindex;
1801 * If it wasn't a write fault avoid having to copy
1802 * the page by mapping it read-only.
1804 fs->prot &= ~VM_PROT_WRITE;
1809 * Relock the map if necessary, then check the generation count.
1810 * relock_map() will update fs->timestamp to account for the
1811 * relocking if necessary.
1813 * If the count has changed after relocking then all sorts of
1814 * crap may have happened and we have to retry.
1816 * NOTE: The relock_map() can fail due to a deadlock against
1817 * the vm_page we are holding BUSY.
1819 if (fs->lookup_still_valid == FALSE && fs->map) {
1820 if (relock_map(fs) ||
1821 fs->map->timestamp != fs->map_generation) {
1823 vm_object_pip_wakeup(fs->first_object);
1824 vm_object_chain_release_all(fs->first_object,
1826 if (fs->object != fs->first_object)
1827 vm_object_drop(fs->object);
1828 unlock_and_deallocate(fs);
1829 return (KERN_TRY_AGAIN);
1834 * If the fault is a write, we know that this page is being
1835 * written NOW so dirty it explicitly to save on pmap_is_modified()
1838 * If this is a NOSYNC mmap we do not want to set PG_NOSYNC
1839 * if the page is already dirty to prevent data written with
1840 * the expectation of being synced from not being synced.
1841 * Likewise if this entry does not request NOSYNC then make
1842 * sure the page isn't marked NOSYNC. Applications sharing
1843 * data should use the same flags to avoid ping ponging.
1845 * Also tell the backing pager, if any, that it should remove
1846 * any swap backing since the page is now dirty.
1848 vm_page_activate(fs->m);
1849 if (fs->prot & VM_PROT_WRITE) {
1850 vm_object_set_writeable_dirty(fs->m->object);
1851 vm_set_nosync(fs->m, fs->entry);
1852 if (fs->fault_flags & VM_FAULT_DIRTY) {
1853 vm_page_dirty(fs->m);
1854 swap_pager_unswapped(fs->m);
1858 vm_object_pip_wakeup(fs->first_object);
1859 vm_object_chain_release_all(fs->first_object, fs->object);
1860 if (fs->object != fs->first_object)
1861 vm_object_drop(fs->object);
1864 * Page had better still be busy. We are still locked up and
1865 * fs->object will have another PIP reference if it is not equal
1866 * to fs->first_object.
1868 KASSERT(fs->m->flags & PG_BUSY,
1869 ("vm_fault: page %p not busy!", fs->m));
1872 * Sanity check: page must be completely valid or it is not fit to
1873 * map into user space. vm_pager_get_pages() ensures this.
1875 if (fs->m->valid != VM_PAGE_BITS_ALL) {
1876 vm_page_zero_invalid(fs->m, TRUE);
1877 kprintf("Warning: page %p partially invalid on fault\n", fs->m);
1879 vm_page_flag_clear(fs->m, PG_ZERO);
1881 return (KERN_SUCCESS);
1885 * Wire down a range of virtual addresses in a map. The entry in question
1886 * should be marked in-transition and the map must be locked. We must
1887 * release the map temporarily while faulting-in the page to avoid a
1888 * deadlock. Note that the entry may be clipped while we are blocked but
1889 * will never be freed.
1894 vm_fault_wire(vm_map_t map, vm_map_entry_t entry, boolean_t user_wire)
1896 boolean_t fictitious;
1905 lwkt_gettoken(&map->token);
1907 pmap = vm_map_pmap(map);
1908 start = entry->start;
1910 fictitious = entry->object.vm_object &&
1911 (entry->object.vm_object->type == OBJT_DEVICE ||
1912 entry->object.vm_object->type == OBJT_MGTDEVICE);
1913 if (entry->eflags & MAP_ENTRY_KSTACK)
1919 * We simulate a fault to get the page and enter it in the physical
1922 for (va = start; va < end; va += PAGE_SIZE) {
1924 rv = vm_fault(map, va, VM_PROT_READ,
1925 VM_FAULT_USER_WIRE);
1927 rv = vm_fault(map, va, VM_PROT_READ|VM_PROT_WRITE,
1928 VM_FAULT_CHANGE_WIRING);
1931 while (va > start) {
1933 if ((pa = pmap_extract(pmap, va)) == 0)
1935 pmap_change_wiring(pmap, va, FALSE, entry);
1937 m = PHYS_TO_VM_PAGE(pa);
1938 vm_page_busy_wait(m, FALSE, "vmwrpg");
1939 vm_page_unwire(m, 1);
1949 lwkt_reltoken(&map->token);
1954 * Unwire a range of virtual addresses in a map. The map should be
1958 vm_fault_unwire(vm_map_t map, vm_map_entry_t entry)
1960 boolean_t fictitious;
1968 lwkt_gettoken(&map->token);
1970 pmap = vm_map_pmap(map);
1971 start = entry->start;
1973 fictitious = entry->object.vm_object &&
1974 (entry->object.vm_object->type == OBJT_DEVICE);
1975 if (entry->eflags & MAP_ENTRY_KSTACK)
1979 * Since the pages are wired down, we must be able to get their
1980 * mappings from the physical map system.
1982 for (va = start; va < end; va += PAGE_SIZE) {
1983 pa = pmap_extract(pmap, va);
1985 pmap_change_wiring(pmap, va, FALSE, entry);
1987 m = PHYS_TO_VM_PAGE(pa);
1988 vm_page_busy_wait(m, FALSE, "vmwupg");
1989 vm_page_unwire(m, 1);
1994 lwkt_reltoken(&map->token);
1998 * Copy all of the pages from a wired-down map entry to another.
2000 * The source and destination maps must be locked for write.
2001 * The source and destination maps token must be held
2002 * The source map entry must be wired down (or be a sharing map
2003 * entry corresponding to a main map entry that is wired down).
2005 * No other requirements.
2007 * XXX do segment optimization
2010 vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
2011 vm_map_entry_t dst_entry, vm_map_entry_t src_entry)
2013 vm_object_t dst_object;
2014 vm_object_t src_object;
2015 vm_ooffset_t dst_offset;
2016 vm_ooffset_t src_offset;
2022 src_object = src_entry->object.vm_object;
2023 src_offset = src_entry->offset;
2026 * Create the top-level object for the destination entry. (Doesn't
2027 * actually shadow anything - we copy the pages directly.)
2029 vm_map_entry_allocate_object(dst_entry);
2030 dst_object = dst_entry->object.vm_object;
2032 prot = dst_entry->max_protection;
2035 * Loop through all of the pages in the entry's range, copying each
2036 * one from the source object (it should be there) to the destination
2039 vm_object_hold(src_object);
2040 vm_object_hold(dst_object);
2041 for (vaddr = dst_entry->start, dst_offset = 0;
2042 vaddr < dst_entry->end;
2043 vaddr += PAGE_SIZE, dst_offset += PAGE_SIZE) {
2046 * Allocate a page in the destination object
2049 dst_m = vm_page_alloc(dst_object,
2050 OFF_TO_IDX(dst_offset),
2052 if (dst_m == NULL) {
2055 } while (dst_m == NULL);
2058 * Find the page in the source object, and copy it in.
2059 * (Because the source is wired down, the page will be in
2062 src_m = vm_page_lookup(src_object,
2063 OFF_TO_IDX(dst_offset + src_offset));
2065 panic("vm_fault_copy_wired: page missing");
2067 vm_page_copy(src_m, dst_m);
2068 vm_page_event(src_m, VMEVENT_COW);
2071 * Enter it in the pmap...
2074 vm_page_flag_clear(dst_m, PG_ZERO);
2075 pmap_enter(dst_map->pmap, vaddr, dst_m, prot, FALSE, dst_entry);
2078 * Mark it no longer busy, and put it on the active list.
2080 vm_page_activate(dst_m);
2081 vm_page_wakeup(dst_m);
2083 vm_object_drop(dst_object);
2084 vm_object_drop(src_object);
2090 * This routine checks around the requested page for other pages that
2091 * might be able to be faulted in. This routine brackets the viable
2092 * pages for the pages to be paged in.
2095 * m, rbehind, rahead
2098 * marray (array of vm_page_t), reqpage (index of requested page)
2101 * number of pages in marray
2104 vm_fault_additional_pages(vm_page_t m, int rbehind, int rahead,
2105 vm_page_t *marray, int *reqpage)
2109 vm_pindex_t pindex, startpindex, endpindex, tpindex;
2111 int cbehind, cahead;
2117 * we don't fault-ahead for device pager
2119 if ((object->type == OBJT_DEVICE) ||
2120 (object->type == OBJT_MGTDEVICE)) {
2127 * if the requested page is not available, then give up now
2129 if (!vm_pager_has_page(object, pindex, &cbehind, &cahead)) {
2130 *reqpage = 0; /* not used by caller, fix compiler warn */
2134 if ((cbehind == 0) && (cahead == 0)) {
2140 if (rahead > cahead) {
2144 if (rbehind > cbehind) {
2149 * Do not do any readahead if we have insufficient free memory.
2151 * XXX code was broken disabled before and has instability
2152 * with this conditonal fixed, so shortcut for now.
2154 if (burst_fault == 0 || vm_page_count_severe()) {
2161 * scan backward for the read behind pages -- in memory
2163 * Assume that if the page is not found an interrupt will not
2164 * create it. Theoretically interrupts can only remove (busy)
2165 * pages, not create new associations.
2168 if (rbehind > pindex) {
2172 startpindex = pindex - rbehind;
2175 vm_object_hold(object);
2176 for (tpindex = pindex; tpindex > startpindex; --tpindex) {
2177 if (vm_page_lookup(object, tpindex - 1))
2182 while (tpindex < pindex) {
2183 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_SYSTEM |
2186 for (j = 0; j < i; j++) {
2187 vm_page_free(marray[j]);
2189 vm_object_drop(object);
2198 vm_object_drop(object);
2204 * Assign requested page
2211 * Scan forwards for read-ahead pages
2213 tpindex = pindex + 1;
2214 endpindex = tpindex + rahead;
2215 if (endpindex > object->size)
2216 endpindex = object->size;
2218 vm_object_hold(object);
2219 while (tpindex < endpindex) {
2220 if (vm_page_lookup(object, tpindex))
2222 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_SYSTEM |
2230 vm_object_drop(object);
2238 * vm_prefault() provides a quick way of clustering pagefaults into a
2239 * processes address space. It is a "cousin" of pmap_object_init_pt,
2240 * except it runs at page fault time instead of mmap time.
2242 * vm.fast_fault Enables pre-faulting zero-fill pages
2244 * vm.prefault_pages Number of pages (1/2 negative, 1/2 positive) to
2245 * prefault. Scan stops in either direction when
2246 * a page is found to already exist.
2248 * This code used to be per-platform pmap_prefault(). It is now
2249 * machine-independent and enhanced to also pre-fault zero-fill pages
2250 * (see vm.fast_fault) as well as make them writable, which greatly
2251 * reduces the number of page faults programs incur.
2253 * Application performance when pre-faulting zero-fill pages is heavily
2254 * dependent on the application. Very tiny applications like /bin/echo
2255 * lose a little performance while applications of any appreciable size
2256 * gain performance. Prefaulting multiple pages also reduces SMP
2257 * congestion and can improve SMP performance significantly.
2259 * NOTE! prot may allow writing but this only applies to the top level
2260 * object. If we wind up mapping a page extracted from a backing
2261 * object we have to make sure it is read-only.
2263 * NOTE! The caller has already handled any COW operations on the
2264 * vm_map_entry via the normal fault code. Do NOT call this
2265 * shortcut unless the normal fault code has run on this entry.
2267 * The related map must be locked.
2268 * No other requirements.
2270 static int vm_prefault_pages = 8;
2271 SYSCTL_INT(_vm, OID_AUTO, prefault_pages, CTLFLAG_RW, &vm_prefault_pages, 0,
2272 "Maximum number of pages to pre-fault");
2273 static int vm_fast_fault = 1;
2274 SYSCTL_INT(_vm, OID_AUTO, fast_fault, CTLFLAG_RW, &vm_fast_fault, 0,
2275 "Burst fault zero-fill regions");
2278 * Set PG_NOSYNC if the map entry indicates so, but only if the page
2279 * is not already dirty by other means. This will prevent passive
2280 * filesystem syncing as well as 'sync' from writing out the page.
2283 vm_set_nosync(vm_page_t m, vm_map_entry_t entry)
2285 if (entry->eflags & MAP_ENTRY_NOSYNC) {
2287 vm_page_flag_set(m, PG_NOSYNC);
2289 vm_page_flag_clear(m, PG_NOSYNC);
2294 vm_prefault(pmap_t pmap, vm_offset_t addra, vm_map_entry_t entry, int prot,
2310 * Get stable max count value, disabled if set to 0
2312 maxpages = vm_prefault_pages;
2318 * We do not currently prefault mappings that use virtual page
2319 * tables. We do not prefault foreign pmaps.
2321 if (entry->maptype == VM_MAPTYPE_VPAGETABLE)
2323 lp = curthread->td_lwp;
2324 if (lp == NULL || (pmap != vmspace_pmap(lp->lwp_vmspace)))
2328 * Limit pre-fault count to 1024 pages.
2330 if (maxpages > 1024)
2333 object = entry->object.vm_object;
2334 KKASSERT(object != NULL);
2335 KKASSERT(object == entry->object.vm_object);
2336 vm_object_hold(object);
2337 vm_object_chain_acquire(object);
2341 for (i = 0; i < maxpages; ++i) {
2342 vm_object_t lobject;
2343 vm_object_t nobject;
2348 * This can eat a lot of time on a heavily contended
2349 * machine so yield on the tick if needed.
2355 * Calculate the page to pre-fault, stopping the scan in
2356 * each direction separately if the limit is reached.
2361 addr = addra - ((i + 1) >> 1) * PAGE_SIZE;
2365 addr = addra + ((i + 2) >> 1) * PAGE_SIZE;
2367 if (addr < entry->start) {
2373 if (addr >= entry->end) {
2381 * Skip pages already mapped, and stop scanning in that
2382 * direction. When the scan terminates in both directions
2385 if (pmap_prefault_ok(pmap, addr) == 0) {
2396 * Follow the VM object chain to obtain the page to be mapped
2399 * If we reach the terminal object without finding a page
2400 * and we determine it would be advantageous, then allocate
2401 * a zero-fill page for the base object. The base object
2402 * is guaranteed to be OBJT_DEFAULT for this case.
2404 * In order to not have to check the pager via *haspage*()
2405 * we stop if any non-default object is encountered. e.g.
2406 * a vnode or swap object would stop the loop.
2408 index = ((addr - entry->start) + entry->offset) >> PAGE_SHIFT;
2413 KKASSERT(lobject == entry->object.vm_object);
2414 /*vm_object_hold(lobject); implied */
2416 while ((m = vm_page_lookup_busy_try(lobject, pindex,
2417 TRUE, &error)) == NULL) {
2418 if (lobject->type != OBJT_DEFAULT)
2420 if (lobject->backing_object == NULL) {
2421 if (vm_fast_fault == 0)
2423 if ((prot & VM_PROT_WRITE) == 0 ||
2424 vm_page_count_min(0)) {
2429 * NOTE: Allocated from base object
2431 m = vm_page_alloc(object, index,
2440 /* lobject = object .. not needed */
2443 if (lobject->backing_object_offset & PAGE_MASK)
2445 nobject = lobject->backing_object;
2446 vm_object_hold(nobject);
2447 KKASSERT(nobject == lobject->backing_object);
2448 pindex += lobject->backing_object_offset >> PAGE_SHIFT;
2449 if (lobject != object) {
2450 vm_object_lock_swap();
2451 vm_object_drop(lobject);
2454 pprot &= ~VM_PROT_WRITE;
2455 vm_object_chain_acquire(lobject);
2459 * NOTE: A non-NULL (m) will be associated with lobject if
2460 * it was found there, otherwise it is probably a
2461 * zero-fill page associated with the base object.
2463 * Give-up if no page is available.
2466 if (lobject != object) {
2467 if (object->backing_object != lobject)
2468 vm_object_hold(object->backing_object);
2469 vm_object_chain_release_all(
2470 object->backing_object, lobject);
2471 if (object->backing_object != lobject)
2472 vm_object_drop(object->backing_object);
2473 vm_object_drop(lobject);
2479 * The object must be marked dirty if we are mapping a
2480 * writable page. m->object is either lobject or object,
2481 * both of which are still held. Do this before we
2482 * potentially drop the object.
2484 if (pprot & VM_PROT_WRITE)
2485 vm_object_set_writeable_dirty(m->object);
2488 * Do not conditionalize on PG_RAM. If pages are present in
2489 * the VM system we assume optimal caching. If caching is
2490 * not optimal the I/O gravy train will be restarted when we
2491 * hit an unavailable page. We do not want to try to restart
2492 * the gravy train now because we really don't know how much
2493 * of the object has been cached. The cost for restarting
2494 * the gravy train should be low (since accesses will likely
2495 * be I/O bound anyway).
2497 if (lobject != object) {
2498 if (object->backing_object != lobject)
2499 vm_object_hold(object->backing_object);
2500 vm_object_chain_release_all(object->backing_object,
2502 if (object->backing_object != lobject)
2503 vm_object_drop(object->backing_object);
2504 vm_object_drop(lobject);
2508 * Enter the page into the pmap if appropriate. If we had
2509 * allocated the page we have to place it on a queue. If not
2510 * we just have to make sure it isn't on the cache queue
2511 * (pages on the cache queue are not allowed to be mapped).
2515 * Page must be zerod.
2517 if ((m->flags & PG_ZERO) == 0) {
2518 vm_page_zero_fill(m);
2521 pmap_page_assertzero(
2522 VM_PAGE_TO_PHYS(m));
2524 vm_page_flag_clear(m, PG_ZERO);
2525 mycpu->gd_cnt.v_ozfod++;
2527 mycpu->gd_cnt.v_zfod++;
2528 m->valid = VM_PAGE_BITS_ALL;
2531 * Handle dirty page case
2533 if (pprot & VM_PROT_WRITE)
2534 vm_set_nosync(m, entry);
2535 pmap_enter(pmap, addr, m, pprot, 0, entry);
2536 mycpu->gd_cnt.v_vm_faults++;
2537 if (curthread->td_lwp)
2538 ++curthread->td_lwp->lwp_ru.ru_minflt;
2539 vm_page_deactivate(m);
2540 if (pprot & VM_PROT_WRITE) {
2541 /*vm_object_set_writeable_dirty(m->object);*/
2542 vm_set_nosync(m, entry);
2543 if (fault_flags & VM_FAULT_DIRTY) {
2546 swap_pager_unswapped(m);
2551 /* couldn't busy page, no wakeup */
2553 ((m->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) &&
2554 (m->flags & PG_FICTITIOUS) == 0) {
2556 * A fully valid page not undergoing soft I/O can
2557 * be immediately entered into the pmap.
2559 if ((m->queue - m->pc) == PQ_CACHE)
2560 vm_page_deactivate(m);
2561 if (pprot & VM_PROT_WRITE) {
2562 /*vm_object_set_writeable_dirty(m->object);*/
2563 vm_set_nosync(m, entry);
2564 if (fault_flags & VM_FAULT_DIRTY) {
2567 swap_pager_unswapped(m);
2570 if (pprot & VM_PROT_WRITE)
2571 vm_set_nosync(m, entry);
2572 pmap_enter(pmap, addr, m, pprot, 0, entry);
2573 mycpu->gd_cnt.v_vm_faults++;
2574 if (curthread->td_lwp)
2575 ++curthread->td_lwp->lwp_ru.ru_minflt;
2581 vm_object_chain_release(object);
2582 vm_object_drop(object);
2586 vm_prefault_quick(pmap_t pmap, vm_offset_t addra,
2587 vm_map_entry_t entry, int prot, int fault_flags)
2600 * Get stable max count value, disabled if set to 0
2602 maxpages = vm_prefault_pages;
2608 * We do not currently prefault mappings that use virtual page
2609 * tables. We do not prefault foreign pmaps.
2611 if (entry->maptype == VM_MAPTYPE_VPAGETABLE)
2613 lp = curthread->td_lwp;
2614 if (lp == NULL || (pmap != vmspace_pmap(lp->lwp_vmspace)))
2618 * Limit pre-fault count to 1024 pages.
2620 if (maxpages > 1024)
2623 object = entry->object.vm_object;
2624 ASSERT_LWKT_TOKEN_HELD(vm_object_token(object));
2625 KKASSERT(object->backing_object == NULL);
2629 for (i = 0; i < maxpages; ++i) {
2633 * Calculate the page to pre-fault, stopping the scan in
2634 * each direction separately if the limit is reached.
2639 addr = addra - ((i + 1) >> 1) * PAGE_SIZE;
2643 addr = addra + ((i + 2) >> 1) * PAGE_SIZE;
2645 if (addr < entry->start) {
2651 if (addr >= entry->end) {
2659 * Skip pages already mapped, and stop scanning in that
2660 * direction. When the scan terminates in both directions
2663 if (pmap_prefault_ok(pmap, addr) == 0) {
2674 * Follow the VM object chain to obtain the page to be mapped
2675 * into the pmap. This version of the prefault code only
2676 * works with terminal objects.
2678 * WARNING! We cannot call swap_pager_unswapped() with a
2681 pindex = ((addr - entry->start) + entry->offset) >> PAGE_SHIFT;
2683 m = vm_page_lookup_busy_try(object, pindex, TRUE, &error);
2684 if (m == NULL || error)
2687 if (((m->valid & VM_PAGE_BITS_ALL) == VM_PAGE_BITS_ALL) &&
2688 (m->flags & PG_FICTITIOUS) == 0 &&
2689 ((m->flags & PG_SWAPPED) == 0 ||
2690 (prot & VM_PROT_WRITE) == 0 ||
2691 (fault_flags & VM_FAULT_DIRTY) == 0)) {
2693 * A fully valid page not undergoing soft I/O can
2694 * be immediately entered into the pmap.
2696 if ((m->queue - m->pc) == PQ_CACHE)
2697 vm_page_deactivate(m);
2698 if (prot & VM_PROT_WRITE) {
2699 vm_object_set_writeable_dirty(m->object);
2700 vm_set_nosync(m, entry);
2701 if (fault_flags & VM_FAULT_DIRTY) {
2704 swap_pager_unswapped(m);
2707 pmap_enter(pmap, addr, m, prot, 0, entry);
2708 mycpu->gd_cnt.v_vm_faults++;
2709 if (curthread->td_lwp)
2710 ++curthread->td_lwp->lwp_ru.ru_minflt;