2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1994 John S. Dyson
6 * Copyright (c) 1994 David Greenman
10 * This code is derived from software contributed to Berkeley by
11 * The Mach Operating System project at Carnegie-Mellon University.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * from: @(#)vm_fault.c 8.4 (Berkeley) 1/12/94
44 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
45 * All rights reserved.
47 * Authors: Avadis Tevanian, Jr., Michael Wayne Young
49 * Permission to use, copy, modify and distribute this software and
50 * its documentation is hereby granted, provided that both the copyright
51 * notice and this permission notice appear in all copies of the
52 * software, derivative works or modified versions, and any portions
53 * thereof, and that both notices appear in supporting documentation.
55 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
56 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
57 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
59 * Carnegie Mellon requests users of this software to return to
61 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
62 * School of Computer Science
63 * Carnegie Mellon University
64 * Pittsburgh PA 15213-3890
66 * any improvements or extensions that they make and grant Carnegie the
67 * rights to redistribute these changes.
69 * $FreeBSD: src/sys/vm/vm_fault.c,v 1.108.2.8 2002/02/26 05:49:27 silby Exp $
70 * $DragonFly: src/sys/vm/vm_fault.c,v 1.47 2008/07/01 02:02:56 dillon Exp $
74 * Page fault handling module.
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/kernel.h>
81 #include <sys/vnode.h>
82 #include <sys/resourcevar.h>
83 #include <sys/vmmeter.h>
84 #include <sys/vkernel.h>
85 #include <sys/sfbuf.h>
87 #include <sys/sysctl.h>
90 #include <vm/vm_param.h>
92 #include <vm/vm_map.h>
93 #include <vm/vm_object.h>
94 #include <vm/vm_page.h>
95 #include <vm/vm_pageout.h>
96 #include <vm/vm_kern.h>
97 #include <vm/vm_pager.h>
98 #include <vm/vnode_pager.h>
99 #include <vm/vm_extern.h>
101 #include <sys/thread2.h>
102 #include <vm/vm_page2.h>
104 #define VM_FAULT_READ_AHEAD 8
105 #define VM_FAULT_READ_BEHIND 7
106 #define VM_FAULT_READ (VM_FAULT_READ_AHEAD+VM_FAULT_READ_BEHIND+1)
114 vm_object_t first_object;
115 vm_prot_t first_prot;
117 vm_map_entry_t entry;
118 int lookup_still_valid;
127 static int burst_fault = 1;
128 SYSCTL_INT(_vm, OID_AUTO, burst_fault, CTLFLAG_RW, &burst_fault, 0, "");
129 static int debug_cluster = 0;
130 SYSCTL_INT(_vm, OID_AUTO, debug_cluster, CTLFLAG_RW, &debug_cluster, 0, "");
132 static int vm_fault_object(struct faultstate *, vm_pindex_t, vm_prot_t);
133 static int vm_fault_vpagetable(struct faultstate *, vm_pindex_t *, vpte_t, int);
134 static int vm_fault_additional_pages (vm_page_t, int, int, vm_page_t *, int *);
135 static int vm_fault_ratelimit(struct vmspace *);
138 release_page(struct faultstate *fs)
140 vm_page_deactivate(fs->m);
141 vm_page_wakeup(fs->m);
146 unlock_map(struct faultstate *fs)
148 if (fs->lookup_still_valid && fs->map) {
149 vm_map_lookup_done(fs->map, fs->entry, 0);
150 fs->lookup_still_valid = FALSE;
155 * Clean up after a successful call to vm_fault_object() so another call
156 * to vm_fault_object() can be made.
159 _cleanup_successful_fault(struct faultstate *fs, int relock)
161 if (fs->object != fs->first_object) {
162 vm_page_free(fs->first_m);
163 vm_object_pip_wakeup(fs->object);
166 fs->object = fs->first_object;
167 if (relock && fs->lookup_still_valid == FALSE) {
169 vm_map_lock_read(fs->map);
170 fs->lookup_still_valid = TRUE;
175 _unlock_things(struct faultstate *fs, int dealloc)
177 vm_object_pip_wakeup(fs->first_object);
178 _cleanup_successful_fault(fs, 0);
180 vm_object_deallocate(fs->first_object);
181 fs->first_object = NULL;
184 if (fs->vp != NULL) {
190 #define unlock_things(fs) _unlock_things(fs, 0)
191 #define unlock_and_deallocate(fs) _unlock_things(fs, 1)
192 #define cleanup_successful_fault(fs) _cleanup_successful_fault(fs, 1)
197 * Determine if the pager for the current object *might* contain the page.
199 * We only need to try the pager if this is not a default object (default
200 * objects are zero-fill and have no real pager), and if we are not taking
201 * a wiring fault or if the FS entry is wired.
203 #define TRYPAGER(fs) \
204 (fs->object->type != OBJT_DEFAULT && \
205 (((fs->fault_flags & VM_FAULT_WIRE_MASK) == 0) || fs->wired))
210 * Handle a page fault occuring at the given address, requiring the given
211 * permissions, in the map specified. If successful, the page is inserted
212 * into the associated physical map.
214 * NOTE: The given address should be truncated to the proper page address.
216 * KERN_SUCCESS is returned if the page fault is handled; otherwise,
217 * a standard error specifying why the fault is fatal is returned.
219 * The map in question must be referenced, and remains so.
220 * The caller may hold no locks.
223 vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags)
226 vm_pindex_t first_pindex;
227 struct faultstate fs;
229 mycpu->gd_cnt.v_vm_faults++;
233 fs.fault_flags = fault_flags;
237 * Find the vm_map_entry representing the backing store and resolve
238 * the top level object and page index. This may have the side
239 * effect of executing a copy-on-write on the map entry and/or
240 * creating a shadow object, but will not COW any actual VM pages.
242 * On success fs.map is left read-locked and various other fields
243 * are initialized but not otherwise referenced or locked.
245 * NOTE! vm_map_lookup will try to upgrade the fault_type to
246 * VM_FAULT_WRITE if the map entry is a virtual page table and also
247 * writable, so we can set the 'A'accessed bit in the virtual page
251 result = vm_map_lookup(&fs.map, vaddr, fault_type,
252 &fs.entry, &fs.first_object,
253 &first_pindex, &fs.first_prot, &fs.wired);
256 * If the lookup failed or the map protections are incompatible,
257 * the fault generally fails. However, if the caller is trying
258 * to do a user wiring we have more work to do.
260 if (result != KERN_SUCCESS) {
261 if (result != KERN_PROTECTION_FAILURE)
263 if ((fs.fault_flags & VM_FAULT_WIRE_MASK) != VM_FAULT_USER_WIRE)
267 * If we are user-wiring a r/w segment, and it is COW, then
268 * we need to do the COW operation. Note that we don't
269 * currently COW RO sections now, because it is NOT desirable
270 * to COW .text. We simply keep .text from ever being COW'ed
271 * and take the heat that one cannot debug wired .text sections.
273 result = vm_map_lookup(&fs.map, vaddr,
274 VM_PROT_READ|VM_PROT_WRITE|
275 VM_PROT_OVERRIDE_WRITE,
276 &fs.entry, &fs.first_object,
277 &first_pindex, &fs.first_prot,
279 if (result != KERN_SUCCESS)
283 * If we don't COW now, on a user wire, the user will never
284 * be able to write to the mapping. If we don't make this
285 * restriction, the bookkeeping would be nearly impossible.
287 if ((fs.entry->protection & VM_PROT_WRITE) == 0)
288 fs.entry->max_protection &= ~VM_PROT_WRITE;
292 * fs.map is read-locked
294 * Misc checks. Save the map generation number to detect races.
296 fs.map_generation = fs.map->timestamp;
298 if (fs.entry->eflags & MAP_ENTRY_NOFAULT) {
299 panic("vm_fault: fault on nofault entry, addr: %lx",
304 * A system map entry may return a NULL object. No object means
305 * no pager means an unrecoverable kernel fault.
307 if (fs.first_object == NULL) {
308 panic("vm_fault: unrecoverable fault at %p in entry %p",
309 (void *)vaddr, fs.entry);
313 * Make a reference to this object to prevent its disposal while we
314 * are messing with it. Once we have the reference, the map is free
315 * to be diddled. Since objects reference their shadows (and copies),
316 * they will stay around as well.
318 * Bump the paging-in-progress count to prevent size changes (e.g.
319 * truncation operations) during I/O. This must be done after
320 * obtaining the vnode lock in order to avoid possible deadlocks.
322 vm_object_reference(fs.first_object);
323 fs.vp = vnode_pager_lock(fs.first_object);
324 vm_object_pip_add(fs.first_object, 1);
326 fs.lookup_still_valid = TRUE;
328 fs.object = fs.first_object; /* so unlock_and_deallocate works */
331 * If the entry is wired we cannot change the page protection.
334 fault_type = fs.first_prot;
337 * The page we want is at (first_object, first_pindex), but if the
338 * vm_map_entry is VM_MAPTYPE_VPAGETABLE we have to traverse the
339 * page table to figure out the actual pindex.
341 * NOTE! DEVELOPMENT IN PROGRESS, THIS IS AN INITIAL IMPLEMENTATION
344 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
345 result = vm_fault_vpagetable(&fs, &first_pindex,
346 fs.entry->aux.master_pde,
348 if (result == KERN_TRY_AGAIN)
350 if (result != KERN_SUCCESS)
355 * Now we have the actual (object, pindex), fault in the page. If
356 * vm_fault_object() fails it will unlock and deallocate the FS
357 * data. If it succeeds everything remains locked and fs->object
358 * will have an additinal PIP count if it is not equal to
361 * vm_fault_object will set fs->prot for the pmap operation. It is
362 * allowed to set VM_PROT_WRITE if fault_type == VM_PROT_READ if the
363 * page can be safely written. However, it will force a read-only
364 * mapping for a read fault if the memory is managed by a virtual
367 result = vm_fault_object(&fs, first_pindex, fault_type);
369 if (result == KERN_TRY_AGAIN)
371 if (result != KERN_SUCCESS)
375 * On success vm_fault_object() does not unlock or deallocate, and fs.m
376 * will contain a busied page.
378 * Enter the page into the pmap and do pmap-related adjustments.
381 pmap_enter(fs.map->pmap, vaddr, fs.m, fs.prot, fs.wired);
383 if (((fs.fault_flags & VM_FAULT_WIRE_MASK) == 0) && (fs.wired == 0)) {
384 pmap_prefault(fs.map->pmap, vaddr, fs.entry);
387 vm_page_flag_clear(fs.m, PG_ZERO);
388 vm_page_flag_set(fs.m, PG_REFERENCED);
391 * If the page is not wired down, then put it where the pageout daemon
394 if (fs.fault_flags & VM_FAULT_WIRE_MASK) {
398 vm_page_unwire(fs.m, 1);
400 vm_page_activate(fs.m);
403 if (curthread->td_lwp) {
405 curthread->td_lwp->lwp_ru.ru_majflt++;
407 curthread->td_lwp->lwp_ru.ru_minflt++;
412 * Unlock everything, and return
414 vm_page_wakeup(fs.m);
415 vm_object_deallocate(fs.first_object);
417 return (KERN_SUCCESS);
421 * Fault in the specified virtual address in the current process map,
422 * returning a held VM page or NULL. See vm_fault_page() for more
426 vm_fault_page_quick(vm_offset_t va, vm_prot_t fault_type, int *errorp)
428 struct lwp *lp = curthread->td_lwp;
431 m = vm_fault_page(&lp->lwp_vmspace->vm_map, va,
432 fault_type, VM_FAULT_NORMAL, errorp);
437 * Fault in the specified virtual address in the specified map, doing all
438 * necessary manipulation of the object store and all necessary I/O. Return
439 * a held VM page or NULL, and set *errorp. The related pmap is not
442 * The returned page will be properly dirtied if VM_PROT_WRITE was specified,
443 * and marked PG_REFERENCED as well.
445 * If the page cannot be faulted writable and VM_PROT_WRITE was specified, an
446 * error will be returned.
449 vm_fault_page(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type,
450 int fault_flags, int *errorp)
452 vm_pindex_t first_pindex;
453 struct faultstate fs;
455 vm_prot_t orig_fault_type = fault_type;
457 mycpu->gd_cnt.v_vm_faults++;
461 fs.fault_flags = fault_flags;
462 KKASSERT((fault_flags & VM_FAULT_WIRE_MASK) == 0);
466 * Find the vm_map_entry representing the backing store and resolve
467 * the top level object and page index. This may have the side
468 * effect of executing a copy-on-write on the map entry and/or
469 * creating a shadow object, but will not COW any actual VM pages.
471 * On success fs.map is left read-locked and various other fields
472 * are initialized but not otherwise referenced or locked.
474 * NOTE! vm_map_lookup will upgrade the fault_type to VM_FAULT_WRITE
475 * if the map entry is a virtual page table and also writable,
476 * so we can set the 'A'accessed bit in the virtual page table entry.
479 result = vm_map_lookup(&fs.map, vaddr, fault_type,
480 &fs.entry, &fs.first_object,
481 &first_pindex, &fs.first_prot, &fs.wired);
483 if (result != KERN_SUCCESS) {
489 * fs.map is read-locked
491 * Misc checks. Save the map generation number to detect races.
493 fs.map_generation = fs.map->timestamp;
495 if (fs.entry->eflags & MAP_ENTRY_NOFAULT) {
496 panic("vm_fault: fault on nofault entry, addr: %lx",
501 * A system map entry may return a NULL object. No object means
502 * no pager means an unrecoverable kernel fault.
504 if (fs.first_object == NULL) {
505 panic("vm_fault: unrecoverable fault at %p in entry %p",
506 (void *)vaddr, fs.entry);
510 * Make a reference to this object to prevent its disposal while we
511 * are messing with it. Once we have the reference, the map is free
512 * to be diddled. Since objects reference their shadows (and copies),
513 * they will stay around as well.
515 * Bump the paging-in-progress count to prevent size changes (e.g.
516 * truncation operations) during I/O. This must be done after
517 * obtaining the vnode lock in order to avoid possible deadlocks.
519 vm_object_reference(fs.first_object);
520 fs.vp = vnode_pager_lock(fs.first_object);
521 vm_object_pip_add(fs.first_object, 1);
523 fs.lookup_still_valid = TRUE;
525 fs.object = fs.first_object; /* so unlock_and_deallocate works */
528 * If the entry is wired we cannot change the page protection.
531 fault_type = fs.first_prot;
534 * The page we want is at (first_object, first_pindex), but if the
535 * vm_map_entry is VM_MAPTYPE_VPAGETABLE we have to traverse the
536 * page table to figure out the actual pindex.
538 * NOTE! DEVELOPMENT IN PROGRESS, THIS IS AN INITIAL IMPLEMENTATION
541 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
542 result = vm_fault_vpagetable(&fs, &first_pindex,
543 fs.entry->aux.master_pde,
545 if (result == KERN_TRY_AGAIN)
547 if (result != KERN_SUCCESS) {
554 * Now we have the actual (object, pindex), fault in the page. If
555 * vm_fault_object() fails it will unlock and deallocate the FS
556 * data. If it succeeds everything remains locked and fs->object
557 * will have an additinal PIP count if it is not equal to
560 result = vm_fault_object(&fs, first_pindex, fault_type);
562 if (result == KERN_TRY_AGAIN)
564 if (result != KERN_SUCCESS) {
569 if ((orig_fault_type & VM_PROT_WRITE) &&
570 (fs.prot & VM_PROT_WRITE) == 0) {
571 *errorp = KERN_PROTECTION_FAILURE;
572 unlock_and_deallocate(&fs);
577 * On success vm_fault_object() does not unlock or deallocate, and fs.m
578 * will contain a busied page.
583 * Return a held page. We are not doing any pmap manipulation so do
584 * not set PG_MAPPED. However, adjust the page flags according to
585 * the fault type because the caller may not use a managed pmapping
586 * (so we don't want to lose the fact that the page will be dirtied
587 * if a write fault was specified).
590 vm_page_flag_clear(fs.m, PG_ZERO);
591 if (fault_type & VM_PROT_WRITE)
595 * Update the pmap. We really only have to do this if a COW
596 * occured to replace the read-only page with the new page. For
597 * now just do it unconditionally. XXX
599 pmap_enter(fs.map->pmap, vaddr, fs.m, fs.prot, fs.wired);
600 vm_page_flag_set(fs.m, PG_REFERENCED);
603 * Unbusy the page by activating it. It remains held and will not
606 vm_page_activate(fs.m);
608 if (curthread->td_lwp) {
610 curthread->td_lwp->lwp_ru.ru_majflt++;
612 curthread->td_lwp->lwp_ru.ru_minflt++;
617 * Unlock everything, and return the held page.
619 vm_page_wakeup(fs.m);
620 vm_object_deallocate(fs.first_object);
627 * Fault in the specified (object,offset), dirty the returned page as
628 * needed. If the requested fault_type cannot be done NULL and an
632 vm_fault_object_page(vm_object_t object, vm_ooffset_t offset,
633 vm_prot_t fault_type, int fault_flags, int *errorp)
636 vm_pindex_t first_pindex;
637 struct faultstate fs;
638 struct vm_map_entry entry;
640 bzero(&entry, sizeof(entry));
641 entry.object.vm_object = object;
642 entry.maptype = VM_MAPTYPE_NORMAL;
643 entry.protection = entry.max_protection = fault_type;
647 fs.fault_flags = fault_flags;
649 KKASSERT((fault_flags & VM_FAULT_WIRE_MASK) == 0);
653 fs.first_object = object;
654 first_pindex = OFF_TO_IDX(offset);
656 fs.first_prot = fault_type;
658 /*fs.map_generation = 0; unused */
661 * Make a reference to this object to prevent its disposal while we
662 * are messing with it. Once we have the reference, the map is free
663 * to be diddled. Since objects reference their shadows (and copies),
664 * they will stay around as well.
666 * Bump the paging-in-progress count to prevent size changes (e.g.
667 * truncation operations) during I/O. This must be done after
668 * obtaining the vnode lock in order to avoid possible deadlocks.
670 vm_object_reference(fs.first_object);
671 fs.vp = vnode_pager_lock(fs.first_object);
672 vm_object_pip_add(fs.first_object, 1);
674 fs.lookup_still_valid = TRUE;
676 fs.object = fs.first_object; /* so unlock_and_deallocate works */
679 /* XXX future - ability to operate on VM object using vpagetable */
680 if (fs.entry->maptype == VM_MAPTYPE_VPAGETABLE) {
681 result = vm_fault_vpagetable(&fs, &first_pindex,
682 fs.entry->aux.master_pde,
684 if (result == KERN_TRY_AGAIN)
686 if (result != KERN_SUCCESS) {
694 * Now we have the actual (object, pindex), fault in the page. If
695 * vm_fault_object() fails it will unlock and deallocate the FS
696 * data. If it succeeds everything remains locked and fs->object
697 * will have an additinal PIP count if it is not equal to
700 result = vm_fault_object(&fs, first_pindex, fault_type);
702 if (result == KERN_TRY_AGAIN)
704 if (result != KERN_SUCCESS) {
709 if ((fault_type & VM_PROT_WRITE) && (fs.prot & VM_PROT_WRITE) == 0) {
710 *errorp = KERN_PROTECTION_FAILURE;
711 unlock_and_deallocate(&fs);
716 * On success vm_fault_object() does not unlock or deallocate, and fs.m
717 * will contain a busied page.
722 * Return a held page. We are not doing any pmap manipulation so do
723 * not set PG_MAPPED. However, adjust the page flags according to
724 * the fault type because the caller may not use a managed pmapping
725 * (so we don't want to lose the fact that the page will be dirtied
726 * if a write fault was specified).
729 vm_page_flag_clear(fs.m, PG_ZERO);
730 if (fault_type & VM_PROT_WRITE)
734 * Indicate that the page was accessed.
736 vm_page_flag_set(fs.m, PG_REFERENCED);
739 * Unbusy the page by activating it. It remains held and will not
742 vm_page_activate(fs.m);
744 if (curthread->td_lwp) {
746 mycpu->gd_cnt.v_vm_faults++;
747 curthread->td_lwp->lwp_ru.ru_majflt++;
749 curthread->td_lwp->lwp_ru.ru_minflt++;
754 * Unlock everything, and return the held page.
756 vm_page_wakeup(fs.m);
757 vm_object_deallocate(fs.first_object);
764 * Translate the virtual page number (first_pindex) that is relative
765 * to the address space into a logical page number that is relative to the
766 * backing object. Use the virtual page table pointed to by (vpte).
768 * This implements an N-level page table. Any level can terminate the
769 * scan by setting VPTE_PS. A linear mapping is accomplished by setting
770 * VPTE_PS in the master page directory entry set via mcontrol(MADV_SETMAP).
774 vm_fault_vpagetable(struct faultstate *fs, vm_pindex_t *pindex,
775 vpte_t vpte, int fault_type)
778 int vshift = 32 - PAGE_SHIFT; /* page index bits remaining */
779 int result = KERN_SUCCESS;
784 * We cannot proceed if the vpte is not valid, not readable
785 * for a read fault, or not writable for a write fault.
787 if ((vpte & VPTE_V) == 0) {
788 unlock_and_deallocate(fs);
789 return (KERN_FAILURE);
791 if ((fault_type & VM_PROT_READ) && (vpte & VPTE_R) == 0) {
792 unlock_and_deallocate(fs);
793 return (KERN_FAILURE);
795 if ((fault_type & VM_PROT_WRITE) && (vpte & VPTE_W) == 0) {
796 unlock_and_deallocate(fs);
797 return (KERN_FAILURE);
799 if ((vpte & VPTE_PS) || vshift == 0)
801 KKASSERT(vshift >= VPTE_PAGE_BITS);
804 * Get the page table page. Nominally we only read the page
805 * table, but since we are actively setting VPTE_M and VPTE_A,
806 * tell vm_fault_object() that we are writing it.
808 * There is currently no real need to optimize this.
810 result = vm_fault_object(fs, vpte >> PAGE_SHIFT,
811 VM_PROT_READ|VM_PROT_WRITE);
812 if (result != KERN_SUCCESS)
816 * Process the returned fs.m and look up the page table
817 * entry in the page table page.
819 vshift -= VPTE_PAGE_BITS;
820 sf = sf_buf_alloc(fs->m, SFB_CPUPRIVATE);
821 ptep = ((vpte_t *)sf_buf_kva(sf) +
822 ((*pindex >> vshift) & VPTE_PAGE_MASK));
826 * Page table write-back. If the vpte is valid for the
827 * requested operation, do a write-back to the page table.
829 * XXX VPTE_M is not set properly for page directory pages.
830 * It doesn't get set in the page directory if the page table
831 * is modified during a read access.
833 if ((fault_type & VM_PROT_WRITE) && (vpte & VPTE_V) &&
835 if ((vpte & (VPTE_M|VPTE_A)) != (VPTE_M|VPTE_A)) {
836 atomic_set_int(ptep, VPTE_M|VPTE_A);
837 vm_page_dirty(fs->m);
840 if ((fault_type & VM_PROT_READ) && (vpte & VPTE_V) &&
842 if ((vpte & VPTE_A) == 0) {
843 atomic_set_int(ptep, VPTE_A);
844 vm_page_dirty(fs->m);
848 vm_page_flag_set(fs->m, PG_REFERENCED);
849 vm_page_activate(fs->m);
850 vm_page_wakeup(fs->m);
851 cleanup_successful_fault(fs);
854 * Combine remaining address bits with the vpte.
856 *pindex = (vpte >> PAGE_SHIFT) +
857 (*pindex & ((1 << vshift) - 1));
858 return (KERN_SUCCESS);
863 * Do all operations required to fault-in (fs.first_object, pindex). Run
864 * through the shadow chain as necessary and do required COW or virtual
865 * copy operations. The caller has already fully resolved the vm_map_entry
866 * and, if appropriate, has created a copy-on-write layer. All we need to
867 * do is iterate the object chain.
869 * On failure (fs) is unlocked and deallocated and the caller may return or
870 * retry depending on the failure code. On success (fs) is NOT unlocked or
871 * deallocated, fs.m will contained a resolved, busied page, and fs.object
872 * will have an additional PIP count if it is not equal to fs.first_object.
876 vm_fault_object(struct faultstate *fs,
877 vm_pindex_t first_pindex, vm_prot_t fault_type)
879 vm_object_t next_object;
880 vm_page_t marray[VM_FAULT_READ];
884 fs->prot = fs->first_prot;
885 fs->object = fs->first_object;
886 pindex = first_pindex;
889 * If a read fault occurs we try to make the page writable if
890 * possible. There are three cases where we cannot make the
891 * page mapping writable:
893 * (1) The mapping is read-only or the VM object is read-only,
894 * fs->prot above will simply not have VM_PROT_WRITE set.
896 * (2) If the mapping is a virtual page table we need to be able
897 * to detect writes so we can set VPTE_M in the virtual page
900 * (3) If the VM page is read-only or copy-on-write, upgrading would
901 * just result in an unnecessary COW fault.
903 * VM_PROT_VPAGED is set if faulting via a virtual page table and
904 * causes adjustments to the 'M'odify bit to also turn off write
905 * access to force a re-fault.
907 if (fs->entry->maptype == VM_MAPTYPE_VPAGETABLE) {
908 if ((fault_type & VM_PROT_WRITE) == 0)
909 fs->prot &= ~VM_PROT_WRITE;
914 * If the object is dead, we stop here
916 if (fs->object->flags & OBJ_DEAD) {
917 unlock_and_deallocate(fs);
918 return (KERN_PROTECTION_FAILURE);
922 * See if page is resident. spl protection is required
923 * to avoid an interrupt unbusy/free race against our
924 * lookup. We must hold the protection through a page
925 * allocation or busy.
928 fs->m = vm_page_lookup(fs->object, pindex);
932 * Wait/Retry if the page is busy. We have to do this
933 * if the page is busy via either PG_BUSY or
934 * vm_page_t->busy because the vm_pager may be using
935 * vm_page_t->busy for pageouts ( and even pageins if
936 * it is the vnode pager ), and we could end up trying
937 * to pagein and pageout the same page simultaneously.
939 * We can theoretically allow the busy case on a read
940 * fault if the page is marked valid, but since such
941 * pages are typically already pmap'd, putting that
942 * special case in might be more effort then it is
943 * worth. We cannot under any circumstances mess
944 * around with a vm_page_t->busy page except, perhaps,
947 if ((fs->m->flags & PG_BUSY) || fs->m->busy) {
949 vm_page_sleep_busy(fs->m, TRUE, "vmpfw");
950 mycpu->gd_cnt.v_intrans++;
951 vm_object_deallocate(fs->first_object);
952 fs->first_object = NULL;
954 return (KERN_TRY_AGAIN);
958 * If reactivating a page from PQ_CACHE we may have
961 queue = fs->m->queue;
962 vm_page_unqueue_nowakeup(fs->m);
964 if ((queue - fs->m->pc) == PQ_CACHE &&
965 vm_page_count_severe()) {
966 vm_page_activate(fs->m);
967 unlock_and_deallocate(fs);
970 return (KERN_TRY_AGAIN);
974 * Mark page busy for other processes, and the
975 * pagedaemon. If it still isn't completely valid
976 * (readable), or if a read-ahead-mark is set on
977 * the VM page, jump to readrest, else we found the
978 * page and can return.
980 * We can release the spl once we have marked the
986 if (fs->m->object != &kernel_object) {
987 if ((fs->m->valid & VM_PAGE_BITS_ALL) !=
991 if (fs->m->flags & PG_RAM) {
994 vm_page_flag_clear(fs->m, PG_RAM);
998 break; /* break to PAGE HAS BEEN FOUND */
1002 * Page is not resident, If this is the search termination
1003 * or the pager might contain the page, allocate a new page.
1005 * NOTE: We are still in a critical section.
1007 if (TRYPAGER(fs) || fs->object == fs->first_object) {
1009 * If the page is beyond the object size we fail
1011 if (pindex >= fs->object->size) {
1013 unlock_and_deallocate(fs);
1014 return (KERN_PROTECTION_FAILURE);
1020 if (fs->didlimit == 0 && curproc != NULL) {
1023 limticks = vm_fault_ratelimit(curproc->p_vmspace);
1026 unlock_and_deallocate(fs);
1027 tsleep(curproc, 0, "vmrate", limticks);
1029 return (KERN_TRY_AGAIN);
1034 * Allocate a new page for this object/offset pair.
1037 if (!vm_page_count_severe()) {
1038 fs->m = vm_page_alloc(fs->object, pindex,
1039 (fs->vp || fs->object->backing_object) ? VM_ALLOC_NORMAL : VM_ALLOC_NORMAL | VM_ALLOC_ZERO);
1041 if (fs->m == NULL) {
1043 unlock_and_deallocate(fs);
1045 return (KERN_TRY_AGAIN);
1052 * We have found a valid page or we have allocated a new page.
1053 * The page thus may not be valid or may not be entirely
1054 * valid. Even if entirely valid we may have hit a read-ahead
1055 * mark and desire to keep the pipeline going.
1057 * Attempt to fault-in the page if there is a chance that the
1058 * pager has it, and potentially fault in additional pages
1061 * We are NOT in splvm here and if TRYPAGER is true then
1062 * fs.m will be non-NULL and will be PG_BUSY for us.
1069 u_char behavior = vm_map_entry_behavior(fs->entry);
1071 if (behavior == MAP_ENTRY_BEHAV_RANDOM) {
1076 KKASSERT(behind >= 0);
1077 if (behind > VM_FAULT_READ_BEHIND)
1078 behind = VM_FAULT_READ_BEHIND;
1080 ahead = fs->object->size - pindex;
1083 if (ahead > VM_FAULT_READ_AHEAD)
1084 ahead = VM_FAULT_READ_AHEAD;
1087 if ((fs->first_object->type != OBJT_DEVICE) &&
1088 (behavior == MAP_ENTRY_BEHAV_SEQUENTIAL ||
1089 (behavior != MAP_ENTRY_BEHAV_RANDOM &&
1090 pindex >= fs->entry->lastr &&
1091 pindex < fs->entry->lastr + VM_FAULT_READ))
1093 vm_pindex_t firstpindex, tmppindex;
1095 if (first_pindex < 2 * VM_FAULT_READ)
1098 firstpindex = first_pindex - 2 * VM_FAULT_READ;
1101 * note: partially valid pages cannot be
1102 * included in the lookahead - NFS piecemeal
1103 * writes will barf on it badly.
1105 * spl protection is required to avoid races
1106 * between the lookup and an interrupt
1107 * unbusy/free sequence occuring prior to
1111 for (tmppindex = first_pindex - 1;
1112 tmppindex >= firstpindex;
1117 mt = vm_page_lookup(fs->first_object, tmppindex);
1118 if (mt == NULL || (mt->valid != VM_PAGE_BITS_ALL))
1121 (mt->flags & (PG_BUSY | PG_FICTITIOUS | PG_UNMANAGED)) ||
1126 vm_page_test_dirty(mt);
1129 vm_page_protect(mt, VM_PROT_NONE);
1130 vm_page_deactivate(mt);
1143 * now we find out if any other pages should be paged
1144 * in at this time this routine checks to see if the
1145 * pages surrounding this fault reside in the same
1146 * object as the page for this fault. If they do,
1147 * then they are faulted in also into the object. The
1148 * array "marray" returned contains an array of
1149 * vm_page_t structs where one of them is the
1150 * vm_page_t passed to the routine. The reqpage
1151 * return value is the index into the marray for the
1152 * vm_page_t passed to the routine.
1154 * fs.m plus the additional pages are PG_BUSY'd.
1156 faultcount = vm_fault_additional_pages(
1157 fs->m, behind, ahead, marray, &reqpage);
1160 * update lastr imperfectly (we do not know how much
1161 * getpages will actually read), but good enough.
1163 fs->entry->lastr = pindex + faultcount - behind;
1166 * Call the pager to retrieve the data, if any, after
1167 * releasing the lock on the map. We hold a ref on
1168 * fs.object and the pages are PG_BUSY'd.
1173 rv = vm_pager_get_pages(fs->object, marray,
1174 faultcount, reqpage);
1179 if (rv == VM_PAGER_OK) {
1181 * Found the page. Leave it busy while we play
1186 * Relookup in case pager changed page. Pager
1187 * is responsible for disposition of old page
1190 * XXX other code segments do relookups too.
1191 * It's a bad abstraction that needs to be
1194 fs->m = vm_page_lookup(fs->object, pindex);
1195 if (fs->m == NULL) {
1196 unlock_and_deallocate(fs);
1197 return (KERN_TRY_AGAIN);
1201 break; /* break to PAGE HAS BEEN FOUND */
1205 * Remove the bogus page (which does not exist at this
1206 * object/offset); before doing so, we must get back
1207 * our object lock to preserve our invariant.
1209 * Also wake up any other process that may want to bring
1212 * If this is the top-level object, we must leave the
1213 * busy page to prevent another process from rushing
1214 * past us, and inserting the page in that object at
1215 * the same time that we are.
1217 if (rv == VM_PAGER_ERROR) {
1219 kprintf("vm_fault: pager read error, pid %d (%s)\n", curproc->p_pid, curproc->p_comm);
1221 kprintf("vm_fault: pager read error, thread %p (%s)\n", curthread, curproc->p_comm);
1224 * Data outside the range of the pager or an I/O error
1226 * The page may have been wired during the pagein,
1227 * e.g. by the buffer cache, and cannot simply be
1228 * freed. Call vnode_pager_freepag() to deal with it.
1231 * XXX - the check for kernel_map is a kludge to work
1232 * around having the machine panic on a kernel space
1233 * fault w/ I/O error.
1235 if (((fs->map != &kernel_map) && (rv == VM_PAGER_ERROR)) ||
1236 (rv == VM_PAGER_BAD)) {
1237 vnode_pager_freepage(fs->m);
1239 unlock_and_deallocate(fs);
1240 if (rv == VM_PAGER_ERROR)
1241 return (KERN_FAILURE);
1243 return (KERN_PROTECTION_FAILURE);
1246 if (fs->object != fs->first_object) {
1247 vnode_pager_freepage(fs->m);
1250 * XXX - we cannot just fall out at this
1251 * point, m has been freed and is invalid!
1257 * We get here if the object has a default pager (or unwiring)
1258 * or the pager doesn't have the page.
1260 if (fs->object == fs->first_object)
1261 fs->first_m = fs->m;
1264 * Move on to the next object. Lock the next object before
1265 * unlocking the current one.
1267 pindex += OFF_TO_IDX(fs->object->backing_object_offset);
1268 next_object = fs->object->backing_object;
1269 if (next_object == NULL) {
1271 * If there's no object left, fill the page in the top
1272 * object with zeros.
1274 if (fs->object != fs->first_object) {
1275 vm_object_pip_wakeup(fs->object);
1277 fs->object = fs->first_object;
1278 pindex = first_pindex;
1279 fs->m = fs->first_m;
1284 * Zero the page if necessary and mark it valid.
1286 if ((fs->m->flags & PG_ZERO) == 0) {
1287 vm_page_zero_fill(fs->m);
1289 mycpu->gd_cnt.v_ozfod++;
1291 mycpu->gd_cnt.v_zfod++;
1292 fs->m->valid = VM_PAGE_BITS_ALL;
1293 break; /* break to PAGE HAS BEEN FOUND */
1295 if (fs->object != fs->first_object) {
1296 vm_object_pip_wakeup(fs->object);
1298 KASSERT(fs->object != next_object, ("object loop %p", next_object));
1299 fs->object = next_object;
1300 vm_object_pip_add(fs->object, 1);
1304 KASSERT((fs->m->flags & PG_BUSY) != 0,
1305 ("vm_fault: not busy after main loop"));
1308 * PAGE HAS BEEN FOUND. [Loop invariant still holds -- the object lock
1313 * If the page is being written, but isn't already owned by the
1314 * top-level object, we have to copy it into a new page owned by the
1317 if (fs->object != fs->first_object) {
1319 * We only really need to copy if we want to write it.
1321 if (fault_type & VM_PROT_WRITE) {
1323 * This allows pages to be virtually copied from a
1324 * backing_object into the first_object, where the
1325 * backing object has no other refs to it, and cannot
1326 * gain any more refs. Instead of a bcopy, we just
1327 * move the page from the backing object to the
1328 * first object. Note that we must mark the page
1329 * dirty in the first object so that it will go out
1330 * to swap when needed.
1334 * Map, if present, has not changed
1337 fs->map_generation == fs->map->timestamp) &&
1339 * Only one shadow object
1341 (fs->object->shadow_count == 1) &&
1343 * No COW refs, except us
1345 (fs->object->ref_count == 1) &&
1347 * No one else can look this object up
1349 (fs->object->handle == NULL) &&
1351 * No other ways to look the object up
1353 ((fs->object->type == OBJT_DEFAULT) ||
1354 (fs->object->type == OBJT_SWAP)) &&
1356 * We don't chase down the shadow chain
1358 (fs->object == fs->first_object->backing_object) &&
1361 * grab the lock if we need to
1363 (fs->lookup_still_valid ||
1365 lockmgr(&fs->map->lock, LK_EXCLUSIVE|LK_NOWAIT) == 0)
1368 fs->lookup_still_valid = 1;
1370 * get rid of the unnecessary page
1372 vm_page_protect(fs->first_m, VM_PROT_NONE);
1373 vm_page_free(fs->first_m);
1377 * grab the page and put it into the
1378 * process'es object. The page is
1379 * automatically made dirty.
1381 vm_page_rename(fs->m, fs->first_object, first_pindex);
1382 fs->first_m = fs->m;
1383 vm_page_busy(fs->first_m);
1385 mycpu->gd_cnt.v_cow_optim++;
1388 * Oh, well, lets copy it.
1390 vm_page_copy(fs->m, fs->first_m);
1391 vm_page_event(fs->m, VMEVENT_COW);
1396 * We no longer need the old page or object.
1402 * fs->object != fs->first_object due to above
1405 vm_object_pip_wakeup(fs->object);
1408 * Only use the new page below...
1411 mycpu->gd_cnt.v_cow_faults++;
1412 fs->m = fs->first_m;
1413 fs->object = fs->first_object;
1414 pindex = first_pindex;
1417 * If it wasn't a write fault avoid having to copy
1418 * the page by mapping it read-only.
1420 fs->prot &= ~VM_PROT_WRITE;
1425 * We may have had to unlock a map to do I/O. If we did then
1426 * lookup_still_valid will be FALSE. If the map generation count
1427 * also changed then all sorts of things could have happened while
1428 * we were doing the I/O and we need to retry.
1431 if (!fs->lookup_still_valid &&
1433 (fs->map->timestamp != fs->map_generation)) {
1435 unlock_and_deallocate(fs);
1436 return (KERN_TRY_AGAIN);
1440 * If the fault is a write, we know that this page is being
1441 * written NOW so dirty it explicitly to save on pmap_is_modified()
1444 * If this is a NOSYNC mmap we do not want to set PG_NOSYNC
1445 * if the page is already dirty to prevent data written with
1446 * the expectation of being synced from not being synced.
1447 * Likewise if this entry does not request NOSYNC then make
1448 * sure the page isn't marked NOSYNC. Applications sharing
1449 * data should use the same flags to avoid ping ponging.
1451 * Also tell the backing pager, if any, that it should remove
1452 * any swap backing since the page is now dirty.
1454 if (fs->prot & VM_PROT_WRITE) {
1455 vm_object_set_writeable_dirty(fs->m->object);
1456 if (fs->entry->eflags & MAP_ENTRY_NOSYNC) {
1457 if (fs->m->dirty == 0)
1458 vm_page_flag_set(fs->m, PG_NOSYNC);
1460 vm_page_flag_clear(fs->m, PG_NOSYNC);
1462 if (fs->fault_flags & VM_FAULT_DIRTY) {
1464 vm_page_dirty(fs->m);
1465 vm_pager_page_unswapped(fs->m);
1471 * Page had better still be busy. We are still locked up and
1472 * fs->object will have another PIP reference if it is not equal
1473 * to fs->first_object.
1475 KASSERT(fs->m->flags & PG_BUSY,
1476 ("vm_fault: page %p not busy!", fs->m));
1479 * Sanity check: page must be completely valid or it is not fit to
1480 * map into user space. vm_pager_get_pages() ensures this.
1482 if (fs->m->valid != VM_PAGE_BITS_ALL) {
1483 vm_page_zero_invalid(fs->m, TRUE);
1484 kprintf("Warning: page %p partially invalid on fault\n", fs->m);
1487 return (KERN_SUCCESS);
1491 * Wire down a range of virtual addresses in a map. The entry in question
1492 * should be marked in-transition and the map must be locked. We must
1493 * release the map temporarily while faulting-in the page to avoid a
1494 * deadlock. Note that the entry may be clipped while we are blocked but
1495 * will never be freed.
1498 vm_fault_wire(vm_map_t map, vm_map_entry_t entry, boolean_t user_wire)
1500 boolean_t fictitious;
1508 pmap = vm_map_pmap(map);
1509 start = entry->start;
1511 fictitious = entry->object.vm_object &&
1512 (entry->object.vm_object->type == OBJT_DEVICE);
1518 * We simulate a fault to get the page and enter it in the physical
1521 for (va = start; va < end; va += PAGE_SIZE) {
1523 rv = vm_fault(map, va, VM_PROT_READ,
1524 VM_FAULT_USER_WIRE);
1526 rv = vm_fault(map, va, VM_PROT_READ|VM_PROT_WRITE,
1527 VM_FAULT_CHANGE_WIRING);
1530 while (va > start) {
1532 if ((pa = pmap_extract(pmap, va)) == 0)
1534 pmap_change_wiring(pmap, va, FALSE);
1536 vm_page_unwire(PHYS_TO_VM_PAGE(pa), 1);
1543 return (KERN_SUCCESS);
1547 * Unwire a range of virtual addresses in a map. The map should be
1551 vm_fault_unwire(vm_map_t map, vm_map_entry_t entry)
1553 boolean_t fictitious;
1560 pmap = vm_map_pmap(map);
1561 start = entry->start;
1563 fictitious = entry->object.vm_object &&
1564 (entry->object.vm_object->type == OBJT_DEVICE);
1567 * Since the pages are wired down, we must be able to get their
1568 * mappings from the physical map system.
1570 for (va = start; va < end; va += PAGE_SIZE) {
1571 pa = pmap_extract(pmap, va);
1573 pmap_change_wiring(pmap, va, FALSE);
1575 vm_page_unwire(PHYS_TO_VM_PAGE(pa), 1);
1581 * Reduce the rate at which memory is allocated to a process based
1582 * on the perceived load on the VM system. As the load increases
1583 * the allocation burst rate goes down and the delay increases.
1585 * Rate limiting does not apply when faulting active or inactive
1586 * pages. When faulting 'cache' pages, rate limiting only applies
1587 * if the system currently has a severe page deficit.
1589 * XXX vm_pagesupply should be increased when a page is freed.
1591 * We sleep up to 1/10 of a second.
1594 vm_fault_ratelimit(struct vmspace *vmspace)
1596 if (vm_load_enable == 0)
1598 if (vmspace->vm_pagesupply > 0) {
1599 --vmspace->vm_pagesupply;
1603 if (vm_load_debug) {
1604 kprintf("load %-4d give %d pgs, wait %d, pid %-5d (%s)\n",
1606 (1000 - vm_load ) / 10, vm_load * hz / 10000,
1607 curproc->p_pid, curproc->p_comm);
1610 vmspace->vm_pagesupply = (1000 - vm_load) / 10;
1611 return(vm_load * hz / 10000);
1616 * vm_fault_copy_entry
1618 * Copy all of the pages from a wired-down map entry to another.
1620 * In/out conditions:
1621 * The source and destination maps must be locked for write.
1622 * The source map entry must be wired down (or be a sharing map
1623 * entry corresponding to a main map entry that is wired down).
1627 vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
1628 vm_map_entry_t dst_entry, vm_map_entry_t src_entry)
1630 vm_object_t dst_object;
1631 vm_object_t src_object;
1632 vm_ooffset_t dst_offset;
1633 vm_ooffset_t src_offset;
1643 src_object = src_entry->object.vm_object;
1644 src_offset = src_entry->offset;
1647 * Create the top-level object for the destination entry. (Doesn't
1648 * actually shadow anything - we copy the pages directly.)
1650 vm_map_entry_allocate_object(dst_entry);
1651 dst_object = dst_entry->object.vm_object;
1653 prot = dst_entry->max_protection;
1656 * Loop through all of the pages in the entry's range, copying each
1657 * one from the source object (it should be there) to the destination
1660 for (vaddr = dst_entry->start, dst_offset = 0;
1661 vaddr < dst_entry->end;
1662 vaddr += PAGE_SIZE, dst_offset += PAGE_SIZE) {
1665 * Allocate a page in the destination object
1668 dst_m = vm_page_alloc(dst_object,
1669 OFF_TO_IDX(dst_offset), VM_ALLOC_NORMAL);
1670 if (dst_m == NULL) {
1673 } while (dst_m == NULL);
1676 * Find the page in the source object, and copy it in.
1677 * (Because the source is wired down, the page will be in
1680 src_m = vm_page_lookup(src_object,
1681 OFF_TO_IDX(dst_offset + src_offset));
1683 panic("vm_fault_copy_wired: page missing");
1685 vm_page_copy(src_m, dst_m);
1686 vm_page_event(src_m, VMEVENT_COW);
1689 * Enter it in the pmap...
1692 vm_page_flag_clear(dst_m, PG_ZERO);
1693 pmap_enter(dst_map->pmap, vaddr, dst_m, prot, FALSE);
1696 * Mark it no longer busy, and put it on the active list.
1698 vm_page_activate(dst_m);
1699 vm_page_wakeup(dst_m);
1705 * This routine checks around the requested page for other pages that
1706 * might be able to be faulted in. This routine brackets the viable
1707 * pages for the pages to be paged in.
1710 * m, rbehind, rahead
1713 * marray (array of vm_page_t), reqpage (index of requested page)
1716 * number of pages in marray
1719 vm_fault_additional_pages(vm_page_t m, int rbehind, int rahead,
1720 vm_page_t *marray, int *reqpage)
1724 vm_pindex_t pindex, startpindex, endpindex, tpindex;
1726 int cbehind, cahead;
1732 * we don't fault-ahead for device pager
1734 if (object->type == OBJT_DEVICE) {
1741 * if the requested page is not available, then give up now
1743 if (!vm_pager_has_page(object, pindex, &cbehind, &cahead)) {
1744 *reqpage = 0; /* not used by caller, fix compiler warn */
1748 if ((cbehind == 0) && (cahead == 0)) {
1754 if (rahead > cahead) {
1758 if (rbehind > cbehind) {
1763 * Do not do any readahead if we have insufficient free memory.
1765 * XXX code was broken disabled before and has instability
1766 * with this conditonal fixed, so shortcut for now.
1768 if (burst_fault == 0 || vm_page_count_severe()) {
1775 * scan backward for the read behind pages -- in memory
1777 * Assume that if the page is not found an interrupt will not
1778 * create it. Theoretically interrupts can only remove (busy)
1779 * pages, not create new associations.
1782 if (rbehind > pindex) {
1786 startpindex = pindex - rbehind;
1790 for (tpindex = pindex; tpindex > startpindex; --tpindex) {
1791 if (vm_page_lookup(object, tpindex - 1))
1796 while (tpindex < pindex) {
1797 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_SYSTEM);
1800 for (j = 0; j < i; j++) {
1801 vm_page_free(marray[j]);
1817 * Assign requested page
1824 * Scan forwards for read-ahead pages
1826 tpindex = pindex + 1;
1827 endpindex = tpindex + rahead;
1828 if (endpindex > object->size)
1829 endpindex = object->size;
1832 while (tpindex < endpindex) {
1833 if (vm_page_lookup(object, tpindex))
1835 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_SYSTEM);