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 * $Id: vm_fault.c,v 1.87 1998/08/24 08:39:37 dfr Exp $
73 * Page fault handling module.
76 #include <sys/param.h>
77 #include <sys/systm.h>
79 #include <sys/vnode.h>
80 #include <sys/resourcevar.h>
81 #include <sys/vmmeter.h>
84 #include <vm/vm_param.h>
85 #include <vm/vm_prot.h>
88 #include <vm/vm_map.h>
89 #include <vm/vm_object.h>
90 #include <vm/vm_page.h>
91 #include <vm/vm_pageout.h>
92 #include <vm/vm_kern.h>
93 #include <vm/vm_pager.h>
94 #include <vm/vnode_pager.h>
95 #include <vm/vm_extern.h>
97 static int vm_fault_additional_pages __P((vm_page_t, int,
98 int, vm_page_t *, int *));
100 #define VM_FAULT_READ_AHEAD 8
101 #define VM_FAULT_READ_BEHIND 7
102 #define VM_FAULT_READ (VM_FAULT_READ_AHEAD+VM_FAULT_READ_BEHIND+1)
109 vm_object_t first_object;
110 vm_pindex_t first_pindex;
112 vm_map_entry_t entry;
113 int lookup_still_valid;
118 release_page(struct faultstate *fs)
120 vm_page_wakeup(fs->m);
121 vm_page_deactivate(fs->m);
126 unlock_map(struct faultstate *fs)
128 if (fs->lookup_still_valid) {
129 vm_map_lookup_done(fs->map, fs->entry);
130 fs->lookup_still_valid = FALSE;
135 _unlock_things(struct faultstate *fs, int dealloc)
137 vm_object_pip_wakeup(fs->object);
138 if (fs->object != fs->first_object) {
139 vm_page_free(fs->first_m);
140 vm_object_pip_wakeup(fs->first_object);
144 vm_object_deallocate(fs->first_object);
147 if (fs->vp != NULL) {
153 #define unlock_things(fs) _unlock_things(fs, 0)
154 #define unlock_and_deallocate(fs) _unlock_things(fs, 1)
159 * Handle a page fault occuring at the given address,
160 * requiring the given permissions, in the map specified.
161 * If successful, the page is inserted into the
162 * associated physical map.
164 * NOTE: the given address should be truncated to the
165 * proper page address.
167 * KERN_SUCCESS is returned if the page fault is handled; otherwise,
168 * a standard error specifying why the fault is fatal is returned.
171 * The map in question must be referenced, and remains so.
172 * Caller may hold no locks.
175 vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags)
182 vm_object_t next_object;
183 vm_page_t marray[VM_FAULT_READ];
186 struct proc *p = curproc; /* XXX */
187 struct faultstate fs;
189 cnt.v_vm_faults++; /* needs lock XXX */
196 * Find the backing store object and offset into it to begin the
199 if ((result = vm_map_lookup(&fs.map, vaddr,
200 fault_type, &fs.entry, &fs.first_object,
201 &fs.first_pindex, &prot, &wired)) != KERN_SUCCESS) {
202 if ((result != KERN_PROTECTION_FAILURE) ||
203 ((fault_flags & VM_FAULT_WIRE_MASK) != VM_FAULT_USER_WIRE)) {
208 * If we are user-wiring a r/w segment, and it is COW, then
209 * we need to do the COW operation. Note that we don't COW
210 * currently RO sections now, because it is NOT desirable
211 * to COW .text. We simply keep .text from ever being COW'ed
212 * and take the heat that one cannot debug wired .text sections.
214 result = vm_map_lookup(&fs.map, vaddr,
215 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_OVERRIDE_WRITE,
216 &fs.entry, &fs.first_object, &fs.first_pindex, &prot, &wired);
217 if (result != KERN_SUCCESS) {
222 * If we don't COW now, on a user wire, the user will never
223 * be able to write to the mapping. If we don't make this
224 * restriction, the bookkeeping would be nearly impossible.
226 if ((fs.entry->protection & VM_PROT_WRITE) == 0)
227 fs.entry->max_protection &= ~VM_PROT_WRITE;
230 map_generation = fs.map->timestamp;
232 if (fs.entry->eflags & MAP_ENTRY_NOFAULT) {
233 panic("vm_fault: fault on nofault entry, addr: %lx",
238 * Make a reference to this object to prevent its disposal while we
239 * are messing with it. Once we have the reference, the map is free
240 * to be diddled. Since objects reference their shadows (and copies),
241 * they will stay around as well.
243 vm_object_reference(fs.first_object);
244 vm_object_pip_add(fs.first_object, 1);
246 fs.vp = vnode_pager_lock(fs.first_object);
247 if ((fault_type & VM_PROT_WRITE) &&
248 (fs.first_object->type == OBJT_VNODE)) {
249 vm_freeze_copyopts(fs.first_object,
250 fs.first_pindex, fs.first_pindex + 1);
253 fs.lookup_still_valid = TRUE;
261 * Search for the page at object/offset.
264 fs.object = fs.first_object;
265 fs.pindex = fs.first_pindex;
268 * See whether this page is resident
272 if (fs.object->flags & OBJ_DEAD) {
273 unlock_and_deallocate(&fs);
274 return (KERN_PROTECTION_FAILURE);
277 fs.m = vm_page_lookup(fs.object, fs.pindex);
281 * If the page is being brought in, wait for it and
284 if ((fs.m->flags & PG_BUSY) ||
286 (fs.m->valid & VM_PAGE_BITS_ALL) != VM_PAGE_BITS_ALL)) {
291 if ((fs.m->flags & PG_BUSY) ||
293 (fs.m->valid & VM_PAGE_BITS_ALL) != VM_PAGE_BITS_ALL)) {
294 vm_page_flag_set(fs.m, PG_WANTED | PG_REFERENCED);
296 tsleep(fs.m, PSWP, "vmpfw", 0);
299 vm_object_deallocate(fs.first_object);
304 vm_page_unqueue_nowakeup(fs.m);
307 * Mark page busy for other processes, and the pagedaemon.
309 if (((queue - fs.m->pc) == PQ_CACHE) &&
310 (cnt.v_free_count + cnt.v_cache_count) < cnt.v_free_min) {
311 vm_page_activate(fs.m);
312 unlock_and_deallocate(&fs);
318 if (((fs.m->valid & VM_PAGE_BITS_ALL) != VM_PAGE_BITS_ALL) &&
319 fs.m->object != kernel_object && fs.m->object != kmem_object) {
325 if (((fs.object->type != OBJT_DEFAULT) &&
326 (((fault_flags & VM_FAULT_WIRE_MASK) == 0) || wired))
327 || (fs.object == fs.first_object)) {
329 if (fs.pindex >= fs.object->size) {
330 unlock_and_deallocate(&fs);
331 return (KERN_PROTECTION_FAILURE);
335 * Allocate a new page for this object/offset pair.
337 fs.m = vm_page_alloc(fs.object, fs.pindex,
338 (fs.vp || fs.object->backing_object)? VM_ALLOC_NORMAL: VM_ALLOC_ZERO);
341 unlock_and_deallocate(&fs);
348 if (fs.object->type != OBJT_DEFAULT &&
349 (((fault_flags & VM_FAULT_WIRE_MASK) == 0) || wired)) {
354 if (fs.first_object->behavior == OBJ_RANDOM) {
358 behind = (vaddr - fs.entry->start) >> PAGE_SHIFT;
359 if (behind > VM_FAULT_READ_BEHIND)
360 behind = VM_FAULT_READ_BEHIND;
362 ahead = ((fs.entry->end - vaddr) >> PAGE_SHIFT) - 1;
363 if (ahead > VM_FAULT_READ_AHEAD)
364 ahead = VM_FAULT_READ_AHEAD;
367 if ((fs.first_object->type != OBJT_DEVICE) &&
368 (fs.first_object->behavior == OBJ_SEQUENTIAL)) {
369 vm_pindex_t firstpindex, tmppindex;
370 if (fs.first_pindex <
371 2*(VM_FAULT_READ_BEHIND + VM_FAULT_READ_AHEAD + 1))
374 firstpindex = fs.first_pindex -
375 2*(VM_FAULT_READ_BEHIND + VM_FAULT_READ_AHEAD + 1);
377 for(tmppindex = fs.first_pindex - 1;
378 tmppindex >= firstpindex;
381 mt = vm_page_lookup( fs.first_object, tmppindex);
382 if (mt == NULL || (mt->valid != VM_PAGE_BITS_ALL))
385 (mt->flags & (PG_BUSY | PG_FICTITIOUS)) ||
390 vm_page_test_dirty(mt);
392 vm_page_protect(mt, VM_PROT_NONE);
393 vm_page_deactivate(mt);
404 * now we find out if any other pages should be paged
405 * in at this time this routine checks to see if the
406 * pages surrounding this fault reside in the same
407 * object as the page for this fault. If they do,
408 * then they are faulted in also into the object. The
409 * array "marray" returned contains an array of
410 * vm_page_t structs where one of them is the
411 * vm_page_t passed to the routine. The reqpage
412 * return value is the index into the marray for the
413 * vm_page_t passed to the routine.
415 faultcount = vm_fault_additional_pages(
416 fs.m, behind, ahead, marray, &reqpage);
419 * Call the pager to retrieve the data, if any, after
420 * releasing the lock on the map.
425 vm_pager_get_pages(fs.object, marray, faultcount,
426 reqpage) : VM_PAGER_FAIL;
428 if (rv == VM_PAGER_OK) {
430 * Found the page. Leave it busy while we play
435 * Relookup in case pager changed page. Pager
436 * is responsible for disposition of old page
439 fs.m = vm_page_lookup(fs.object, fs.pindex);
441 unlock_and_deallocate(&fs);
449 * Remove the bogus page (which does not exist at this
450 * object/offset); before doing so, we must get back
451 * our object lock to preserve our invariant.
453 * Also wake up any other process that may want to bring
456 * If this is the top-level object, we must leave the
457 * busy page to prevent another process from rushing
458 * past us, and inserting the page in that object at
459 * the same time that we are.
462 if (rv == VM_PAGER_ERROR)
463 printf("vm_fault: pager read error, pid %d (%s)\n",
464 curproc->p_pid, curproc->p_comm);
466 * Data outside the range of the pager or an I/O error
469 * XXX - the check for kernel_map is a kludge to work
470 * around having the machine panic on a kernel space
471 * fault w/ I/O error.
473 if (((fs.map != kernel_map) && (rv == VM_PAGER_ERROR)) ||
474 (rv == VM_PAGER_BAD)) {
477 unlock_and_deallocate(&fs);
478 return ((rv == VM_PAGER_ERROR) ? KERN_FAILURE : KERN_PROTECTION_FAILURE);
480 if (fs.object != fs.first_object) {
484 * XXX - we cannot just fall out at this
485 * point, m has been freed and is invalid!
490 * We get here if the object has default pager (or unwiring) or the
491 * pager doesn't have the page.
493 if (fs.object == fs.first_object)
497 * Move on to the next object. Lock the next object before
498 * unlocking the current one.
501 fs.pindex += OFF_TO_IDX(fs.object->backing_object_offset);
502 next_object = fs.object->backing_object;
503 if (next_object == NULL) {
505 * If there's no object left, fill the page in the top
508 if (fs.object != fs.first_object) {
509 vm_object_pip_wakeup(fs.object);
511 fs.object = fs.first_object;
512 fs.pindex = fs.first_pindex;
517 if ((fs.m->flags & PG_ZERO) == 0) {
518 vm_page_zero_fill(fs.m);
524 if (fs.object != fs.first_object) {
525 vm_object_pip_wakeup(fs.object);
527 fs.object = next_object;
528 vm_object_pip_add(fs.object, 1);
532 #if defined(DIAGNOSTIC)
533 if ((fs.m->flags & PG_BUSY) == 0)
534 panic("vm_fault: not busy after main loop");
538 * PAGE HAS BEEN FOUND. [Loop invariant still holds -- the object lock
542 old_m = fs.m; /* save page that would be copied */
545 * If the page is being written, but isn't already owned by the
546 * top-level object, we have to copy it into a new page owned by the
550 if (fs.object != fs.first_object) {
552 * We only really need to copy if we want to write it.
555 if (fault_type & VM_PROT_WRITE) {
558 * This allows pages to be virtually copied from a backing_object
559 * into the first_object, where the backing object has no other
560 * refs to it, and cannot gain any more refs. Instead of a
561 * bcopy, we just move the page from the backing object to the
562 * first object. Note that we must mark the page dirty in the
563 * first object so that it will go out to swap when needed.
565 if (map_generation == fs.map->timestamp &&
567 * Only one shadow object
569 (fs.object->shadow_count == 1) &&
571 * No COW refs, except us
573 (fs.object->ref_count == 1) &&
575 * Noone else can look this object up
577 (fs.object->handle == NULL) &&
579 * No other ways to look the object up
581 ((fs.object->type == OBJT_DEFAULT) ||
582 (fs.object->type == OBJT_SWAP)) &&
584 * We don't chase down the shadow chain
586 (fs.object == fs.first_object->backing_object) &&
589 * grab the lock if we need to
591 (fs.lookup_still_valid ||
592 (((fs.entry->eflags & MAP_ENTRY_IS_A_MAP) == 0) &&
593 lockmgr(&fs.map->lock,
594 LK_EXCLUSIVE|LK_NOWAIT, (void *)0, curproc) == 0))) {
596 fs.lookup_still_valid = 1;
598 * get rid of the unnecessary page
600 vm_page_protect(fs.first_m, VM_PROT_NONE);
601 vm_page_free(fs.first_m);
605 * grab the page and put it into the process'es object
607 vm_page_rename(fs.m, fs.first_object, fs.first_pindex);
609 fs.first_m->dirty = VM_PAGE_BITS_ALL;
610 vm_page_busy(fs.first_m);
615 * Oh, well, lets copy it.
617 vm_page_copy(fs.m, fs.first_m);
622 * We no longer need the old page or object.
627 vm_object_pip_wakeup(fs.object);
629 * Only use the new page below...
634 fs.object = fs.first_object;
635 fs.pindex = fs.first_pindex;
638 prot &= ~VM_PROT_WRITE;
643 * We must verify that the maps have not changed since our last
647 if (!fs.lookup_still_valid &&
648 (fs.map->timestamp != map_generation)) {
649 vm_object_t retry_object;
650 vm_pindex_t retry_pindex;
651 vm_prot_t retry_prot;
654 * Since map entries may be pageable, make sure we can take a
655 * page fault on them.
659 * To avoid trying to write_lock the map while another process
660 * has it read_locked (in vm_map_pageable), we do not try for
661 * write permission. If the page is still writable, we will
662 * get write permission. If it is not, or has been marked
663 * needs_copy, we enter the mapping without write permission,
664 * and will merely take another fault.
666 result = vm_map_lookup(&fs.map, vaddr, fault_type & ~VM_PROT_WRITE,
667 &fs.entry, &retry_object, &retry_pindex, &retry_prot, &wired);
668 map_generation = fs.map->timestamp;
671 * If we don't need the page any longer, put it on the active
672 * list (the easiest thing to do here). If no one needs it,
673 * pageout will grab it eventually.
676 if (result != KERN_SUCCESS) {
678 unlock_and_deallocate(&fs);
681 fs.lookup_still_valid = TRUE;
683 if ((retry_object != fs.first_object) ||
684 (retry_pindex != fs.first_pindex)) {
686 unlock_and_deallocate(&fs);
690 * Check whether the protection has changed or the object has
691 * been copied while we left the map unlocked. Changing from
692 * read to write permission is OK - we leave the page
693 * write-protected, and catch the write fault. Changing from
694 * write to read permission means that we can't mark the page
695 * write-enabled after all.
701 * Put this page into the physical map. We had to do the unlock above
702 * because pmap_enter may cause other faults. We don't put the page
703 * back on the active queue until later so that the page-out daemon
704 * won't find us (yet).
707 if (prot & VM_PROT_WRITE) {
708 vm_page_flag_set(fs.m, PG_WRITEABLE);
709 vm_object_set_flag(fs.m->object,
710 OBJ_WRITEABLE|OBJ_MIGHTBEDIRTY);
712 * If the fault is a write, we know that this page is being
713 * written NOW. This will save on the pmap_is_modified() calls
716 if (fault_flags & VM_FAULT_DIRTY) {
717 fs.m->dirty = VM_PAGE_BITS_ALL;
722 fs.m->valid = VM_PAGE_BITS_ALL;
723 vm_page_flag_clear(fs.m, PG_ZERO);
725 pmap_enter(fs.map->pmap, vaddr, VM_PAGE_TO_PHYS(fs.m), prot, wired);
726 if (((fault_flags & VM_FAULT_WIRE_MASK) == 0) && (wired == 0)) {
727 pmap_prefault(fs.map->pmap, vaddr, fs.entry);
730 vm_page_flag_set(fs.m, PG_MAPPED|PG_REFERENCED);
731 if (fault_flags & VM_FAULT_HOLD)
735 * If the page is not wired down, then put it where the pageout daemon
738 if (fault_flags & VM_FAULT_WIRE_MASK) {
742 vm_page_unwire(fs.m);
744 vm_page_activate(fs.m);
747 if (curproc && (curproc->p_flag & P_INMEM) && curproc->p_stats) {
749 curproc->p_stats->p_ru.ru_majflt++;
751 curproc->p_stats->p_ru.ru_minflt++;
756 * Unlock everything, and return
759 vm_page_wakeup(fs.m);
760 vm_object_deallocate(fs.first_object);
762 return (KERN_SUCCESS);
769 * Wire down a range of virtual addresses in a map.
772 vm_fault_wire(map, start, end)
774 vm_offset_t start, end;
777 register vm_offset_t va;
778 register pmap_t pmap;
781 pmap = vm_map_pmap(map);
784 * Inform the physical mapping system that the range of addresses may
785 * not fault, so that page tables and such can be locked down as well.
788 pmap_pageable(pmap, start, end, FALSE);
791 * We simulate a fault to get the page and enter it in the physical
795 for (va = start; va < end; va += PAGE_SIZE) {
796 rv = vm_fault(map, va, VM_PROT_READ|VM_PROT_WRITE,
797 VM_FAULT_CHANGE_WIRING);
800 vm_fault_unwire(map, start, va);
804 return (KERN_SUCCESS);
808 * vm_fault_user_wire:
810 * Wire down a range of virtual addresses in a map. This
811 * is for user mode though, so we only ask for read access
812 * on currently read only sections.
815 vm_fault_user_wire(map, start, end)
817 vm_offset_t start, end;
820 register vm_offset_t va;
821 register pmap_t pmap;
824 pmap = vm_map_pmap(map);
827 * Inform the physical mapping system that the range of addresses may
828 * not fault, so that page tables and such can be locked down as well.
831 pmap_pageable(pmap, start, end, FALSE);
834 * We simulate a fault to get the page and enter it in the physical
837 for (va = start; va < end; va += PAGE_SIZE) {
838 rv = vm_fault(map, va, VM_PROT_READ, VM_FAULT_USER_WIRE);
841 vm_fault_unwire(map, start, va);
845 return (KERN_SUCCESS);
852 * Unwire a range of virtual addresses in a map.
855 vm_fault_unwire(map, start, end)
857 vm_offset_t start, end;
860 register vm_offset_t va, pa;
861 register pmap_t pmap;
863 pmap = vm_map_pmap(map);
866 * Since the pages are wired down, we must be able to get their
867 * mappings from the physical map system.
870 for (va = start; va < end; va += PAGE_SIZE) {
871 pa = pmap_extract(pmap, va);
872 if (pa != (vm_offset_t) 0) {
873 pmap_change_wiring(pmap, va, FALSE);
874 vm_page_unwire(PHYS_TO_VM_PAGE(pa));
879 * Inform the physical mapping system that the range of addresses may
880 * fault, so that page tables and such may be unwired themselves.
883 pmap_pageable(pmap, start, end, TRUE);
889 * vm_fault_copy_entry
891 * Copy all of the pages from a wired-down map entry to another.
894 * The source and destination maps must be locked for write.
895 * The source map entry must be wired down (or be a sharing map
896 * entry corresponding to a main map entry that is wired down).
900 vm_fault_copy_entry(dst_map, src_map, dst_entry, src_entry)
903 vm_map_entry_t dst_entry;
904 vm_map_entry_t src_entry;
906 vm_object_t dst_object;
907 vm_object_t src_object;
908 vm_ooffset_t dst_offset;
909 vm_ooffset_t src_offset;
919 src_object = src_entry->object.vm_object;
920 src_offset = src_entry->offset;
923 * Create the top-level object for the destination entry. (Doesn't
924 * actually shadow anything - we copy the pages directly.)
926 dst_object = vm_object_allocate(OBJT_DEFAULT,
927 (vm_size_t) OFF_TO_IDX(dst_entry->end - dst_entry->start));
929 dst_entry->object.vm_object = dst_object;
930 dst_entry->offset = 0;
932 prot = dst_entry->max_protection;
935 * Loop through all of the pages in the entry's range, copying each
936 * one from the source object (it should be there) to the destination
939 for (vaddr = dst_entry->start, dst_offset = 0;
940 vaddr < dst_entry->end;
941 vaddr += PAGE_SIZE, dst_offset += PAGE_SIZE) {
944 * Allocate a page in the destination object
947 dst_m = vm_page_alloc(dst_object,
948 OFF_TO_IDX(dst_offset), VM_ALLOC_NORMAL);
952 } while (dst_m == NULL);
955 * Find the page in the source object, and copy it in.
956 * (Because the source is wired down, the page will be in
959 src_m = vm_page_lookup(src_object,
960 OFF_TO_IDX(dst_offset + src_offset));
962 panic("vm_fault_copy_wired: page missing");
964 vm_page_copy(src_m, dst_m);
967 * Enter it in the pmap...
970 vm_page_flag_clear(dst_m, PG_ZERO);
971 pmap_enter(dst_map->pmap, vaddr, VM_PAGE_TO_PHYS(dst_m),
973 vm_page_flag_set(dst_m, PG_WRITEABLE|PG_MAPPED);
976 * Mark it no longer busy, and put it on the active list.
978 vm_page_activate(dst_m);
979 vm_page_wakeup(dst_m);
985 * This routine checks around the requested page for other pages that
986 * might be able to be faulted in. This routine brackets the viable
987 * pages for the pages to be paged in.
993 * marray (array of vm_page_t), reqpage (index of requested page)
996 * number of pages in marray
999 vm_fault_additional_pages(m, rbehind, rahead, marray, reqpage)
1008 vm_pindex_t pindex, startpindex, endpindex, tpindex;
1010 int cbehind, cahead;
1016 * we don't fault-ahead for device pager
1018 if (object->type == OBJT_DEVICE) {
1025 * if the requested page is not available, then give up now
1028 if (!vm_pager_has_page(object,
1029 OFF_TO_IDX(object->paging_offset) + pindex, &cbehind, &cahead)) {
1033 if ((cbehind == 0) && (cahead == 0)) {
1039 if (rahead > cahead) {
1043 if (rbehind > cbehind) {
1048 * try to do any readahead that we might have free pages for.
1050 if ((rahead + rbehind) >
1051 ((cnt.v_free_count + cnt.v_cache_count) - cnt.v_free_reserved)) {
1052 pagedaemon_wakeup();
1059 * scan backward for the read behind pages -- in memory
1062 if (rbehind > pindex) {
1066 startpindex = pindex - rbehind;
1069 for ( tpindex = pindex - 1; tpindex >= startpindex; tpindex -= 1) {
1070 if (vm_page_lookup( object, tpindex)) {
1071 startpindex = tpindex + 1;
1078 for(i = 0, tpindex = startpindex; tpindex < pindex; i++, tpindex++) {
1080 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_NORMAL);
1082 for (j = 0; j < i; j++) {
1083 vm_page_free(marray[j]);
1098 /* page offset of the required page */
1101 tpindex = pindex + 1;
1105 * scan forward for the read ahead pages
1107 endpindex = tpindex + rahead;
1108 if (endpindex > object->size)
1109 endpindex = object->size;
1111 for( ; tpindex < endpindex; i++, tpindex++) {
1113 if (vm_page_lookup(object, tpindex)) {
1117 rtm = vm_page_alloc(object, tpindex, VM_ALLOC_NORMAL);
1125 /* return number of bytes of pages */