Lines Matching +full:is +full:- +full:wired

1 /*-
2 * SPDX-License-Identifier: (BSD-4-Clause AND MIT-CMU)
12 * This code is derived from software contributed to Berkeley by
13 * The Mach Operating System project at Carnegie-Mellon University.
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
50 * its documentation is hereby granted, provided that both the copyright
55 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
64 * Pittsburgh PA 15213-3890
125 boolean_t wired; member
141 /* Top-level map object. */
218 VM_OBJECT_ASSERT_WLOCKED(m->object); in vm_fault_page_free()
228 * Return true if a vm_pager_get_pages() call is needed in order to check
238 return ((object->flags & OBJ_SWAP) == 0 || in vm_fault_object_needs_getpages()
239 !pctrie_is_empty(&object->un_pager.swp.swp_blks)); in vm_fault_object_needs_getpages()
246 if (fs->lookup_still_valid) { in vm_fault_unlock_map()
247 vm_map_lookup_done(fs->map, fs->entry); in vm_fault_unlock_map()
248 fs->lookup_still_valid = false; in vm_fault_unlock_map()
256 if (fs->vp != NULL) { in vm_fault_unlock_vp()
257 vput(fs->vp); in vm_fault_unlock_vp()
258 fs->vp = NULL; in vm_fault_unlock_vp()
266 vm_fault_page_release(&fs->m_cow); in vm_fault_deallocate()
267 vm_fault_page_release(&fs->m); in vm_fault_deallocate()
268 vm_object_pip_wakeup(fs->object); in vm_fault_deallocate()
269 if (fs->object != fs->first_object) { in vm_fault_deallocate()
270 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_deallocate()
271 vm_fault_page_free(&fs->first_m); in vm_fault_deallocate()
272 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_deallocate()
273 vm_object_pip_wakeup(fs->first_object); in vm_fault_deallocate()
275 vm_object_deallocate(fs->first_object); in vm_fault_deallocate()
284 VM_OBJECT_UNLOCK(fs->object); in vm_fault_unlock_and_deallocate()
293 if (((fs->prot & VM_PROT_WRITE) == 0 && in vm_fault_dirty()
294 (fs->fault_flags & VM_FAULT_DIRTY) == 0) || in vm_fault_dirty()
295 (m->oflags & VPO_UNMANAGED) != 0) in vm_fault_dirty()
300 need_dirty = ((fs->fault_type & VM_PROT_WRITE) != 0 && in vm_fault_dirty()
301 (fs->fault_flags & VM_FAULT_WIRE) == 0) || in vm_fault_dirty()
302 (fs->fault_flags & VM_FAULT_DIRTY) != 0; in vm_fault_dirty()
304 vm_object_set_writeable_dirty(m->object); in vm_fault_dirty()
307 * If the fault is a write, we know that this page is being in vm_fault_dirty()
311 * Also, since the page is now dirty, we can possibly tell in vm_fault_dirty()
316 * If this is a NOSYNC mmap we do not want to set PGA_NOSYNC in vm_fault_dirty()
317 * if the page is already dirty to prevent data written with in vm_fault_dirty()
323 if ((fs->entry->eflags & MAP_ENTRY_NOSYNC) != 0) in vm_fault_dirty()
345 MPASS(fs->vp == NULL); in vm_fault_soft_fast()
348 * If we fail, vast majority of the time it is because the page is not in vm_fault_soft_fast()
354 m = vm_page_lookup_unlocked(fs->first_object, fs->first_pindex); in vm_fault_soft_fast()
356 ((fs->prot & VM_PROT_WRITE) != 0 && vm_page_busied(m))) { in vm_fault_soft_fast()
357 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_soft_fast()
361 vaddr = fs->vaddr; in vm_fault_soft_fast()
363 VM_OBJECT_RLOCK(fs->first_object); in vm_fault_soft_fast()
366 * Now that we stabilized the state, revalidate the page is in the shape in vm_fault_soft_fast()
370 if (m->object != fs->first_object || m->pindex != fs->first_pindex) in vm_fault_soft_fast()
373 vm_object_busy(fs->first_object); in vm_fault_soft_fast()
376 ((fs->prot & VM_PROT_WRITE) != 0 && vm_page_busied(m))) in vm_fault_soft_fast()
382 if ((m->flags & PG_FICTITIOUS) == 0 && in vm_fault_soft_fast()
384 psind = m_super->psind; in vm_fault_soft_fast()
388 if ((fs->prot & VM_PROT_WRITE) != 0) { in vm_fault_soft_fast()
396 if ((fs->first_object->flags & OBJ_UNMANAGED) == 0) in vm_fault_soft_fast()
399 while (rounddown2(vaddr, pagesizes[psind]) < fs->entry->start || in vm_fault_soft_fast()
400 roundup2(vaddr + 1, pagesizes[psind]) > fs->entry->end || in vm_fault_soft_fast()
401 (vaddr & (pagesizes[psind] - 1)) != in vm_fault_soft_fast()
402 (VM_PAGE_TO_PHYS(m) & (pagesizes[psind] - 1)) || in vm_fault_soft_fast()
404 !pmap_ps_enabled(fs->map->pmap)) { in vm_fault_soft_fast()
405 psind--; in vm_fault_soft_fast()
408 m_super += rounddown2(m - m_super, in vm_fault_soft_fast()
410 KASSERT(m_super->psind >= psind, in vm_fault_soft_fast()
411 ("psind %d of m_super %p < %d", m_super->psind, in vm_fault_soft_fast()
419 fs->fault_type |= VM_PROT_WRITE; in vm_fault_soft_fast()
423 if (pmap_enter(fs->map->pmap, vaddr, m_map, fs->prot, fs->fault_type | in vm_fault_soft_fast()
424 PMAP_ENTER_NOSLEEP | (fs->wired ? PMAP_ENTER_WIRED : 0), psind) != in vm_fault_soft_fast()
427 if (fs->m_hold != NULL) { in vm_fault_soft_fast()
428 (*fs->m_hold) = m; in vm_fault_soft_fast()
431 if (psind == 0 && !fs->wired) in vm_fault_soft_fast()
433 VM_OBJECT_RUNLOCK(fs->first_object); in vm_fault_soft_fast()
435 vm_object_unbusy(fs->first_object); in vm_fault_soft_fast()
436 vm_map_lookup_done(fs->map, fs->entry); in vm_fault_soft_fast()
437 curthread->td_ru.ru_minflt++; in vm_fault_soft_fast()
440 vm_object_unbusy(fs->first_object); in vm_fault_soft_fast()
442 if (!VM_OBJECT_TRYUPGRADE(fs->first_object)) { in vm_fault_soft_fast()
443 VM_OBJECT_RUNLOCK(fs->first_object); in vm_fault_soft_fast()
444 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_soft_fast()
453 VM_OBJECT_ASSERT_WLOCKED(fs->first_object); in vm_fault_restore_map_lock()
454 MPASS(blockcount_read(&fs->first_object->paging_in_progress) > 0); in vm_fault_restore_map_lock()
456 if (!vm_map_trylock_read(fs->map)) { in vm_fault_restore_map_lock()
457 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_restore_map_lock()
458 vm_map_lock_read(fs->map); in vm_fault_restore_map_lock()
459 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_restore_map_lock()
461 fs->lookup_still_valid = true; in vm_fault_restore_map_lock()
469 * Check each page to ensure that the pager is obeying the in vm_fault_populate_check_page()
489 KASSERT(m != NULL && m->pindex == pidx, in vm_fault_populate_cleanup()
506 MPASS(fs->object == fs->first_object); in vm_fault_populate()
507 VM_OBJECT_ASSERT_WLOCKED(fs->first_object); in vm_fault_populate()
508 MPASS(blockcount_read(&fs->first_object->paging_in_progress) > 0); in vm_fault_populate()
509 MPASS(fs->first_object->backing_object == NULL); in vm_fault_populate()
510 MPASS(fs->lookup_still_valid); in vm_fault_populate()
512 pager_first = OFF_TO_IDX(fs->entry->offset); in vm_fault_populate()
513 pager_last = pager_first + atop(fs->entry->end - fs->entry->start) - 1; in vm_fault_populate()
522 * There is no guarantee that the method will be called again in vm_fault_populate()
523 * if the current fault is for read, and a future fault is in vm_fault_populate()
527 rv = vm_pager_populate(fs->first_object, fs->first_pindex, in vm_fault_populate()
528 fs->fault_type, fs->entry->max_protection, &pager_first, in vm_fault_populate()
531 VM_OBJECT_ASSERT_WLOCKED(fs->first_object); in vm_fault_populate()
534 * VM_PAGER_BAD is the backdoor for a pager to request in vm_fault_populate()
538 if (fs->map->timestamp != fs->map_generation) in vm_fault_populate()
545 /* Ensure that the driver is obeying the interface. */ in vm_fault_populate()
547 MPASS(fs->first_pindex <= pager_last); in vm_fault_populate()
548 MPASS(fs->first_pindex >= pager_first); in vm_fault_populate()
549 MPASS(pager_last < fs->first_object->size); in vm_fault_populate()
552 bdry_idx = MAP_ENTRY_SPLIT_BOUNDARY_INDEX(fs->entry); in vm_fault_populate()
553 if (fs->map->timestamp != fs->map_generation) { in vm_fault_populate()
555 vm_fault_populate_cleanup(fs->first_object, pager_first, in vm_fault_populate()
558 m = vm_page_lookup(fs->first_object, pager_first); in vm_fault_populate()
559 if (m != fs->m) in vm_fault_populate()
566 * The map is unchanged after our last unlock. Process the fault. in vm_fault_populate()
574 m = vm_page_lookup(fs->first_object, pager_first); in vm_fault_populate()
576 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_populate()
577 vaddr = fs->entry->start + IDX_TO_OFF(pager_first) - in vm_fault_populate()
578 fs->entry->offset; in vm_fault_populate()
580 KASSERT((vaddr & (pagesizes[bdry_idx] - 1)) == 0, in vm_fault_populate()
582 (uintmax_t)fs->entry->start, (uintmax_t)pager_first, in vm_fault_populate()
583 (uintmax_t)fs->entry->offset, (uintmax_t)vaddr)); in vm_fault_populate()
584 KASSERT((VM_PAGE_TO_PHYS(m) & (pagesizes[bdry_idx] - 1)) == 0, in vm_fault_populate()
587 rv = pmap_enter(fs->map->pmap, vaddr, m, fs->prot, in vm_fault_populate()
588 fs->fault_type | (fs->wired ? PMAP_ENTER_WIRED : 0) | in vm_fault_populate()
590 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_populate()
596 if ((fs->fault_flags & VM_FAULT_WIRE) != 0) { in vm_fault_populate()
600 if (fs->m_hold != NULL) { in vm_fault_populate()
601 *fs->m_hold = m + (fs->first_pindex - pager_first); in vm_fault_populate()
602 vm_page_wire(*fs->m_hold); in vm_fault_populate()
608 * The range [pager_first, pager_last] that is given to the in vm_fault_populate()
609 * pager is only a hint. The pager may populate any range in vm_fault_populate()
614 map_first = OFF_TO_IDX(fs->entry->offset); in vm_fault_populate()
616 vm_fault_populate_cleanup(fs->first_object, pager_first, in vm_fault_populate()
617 map_first - 1); in vm_fault_populate()
620 map_last = map_first + atop(fs->entry->end - fs->entry->start) - 1; in vm_fault_populate()
622 vm_fault_populate_cleanup(fs->first_object, map_last + 1, in vm_fault_populate()
626 for (pidx = pager_first, m = vm_page_lookup(fs->first_object, pidx); in vm_fault_populate()
628 pidx += npages, m = TAILQ_NEXT(&m[npages - 1], listq)) { in vm_fault_populate()
629 vaddr = fs->entry->start + IDX_TO_OFF(pidx) - fs->entry->offset; in vm_fault_populate()
630 KASSERT(m != NULL && m->pindex == pidx, in vm_fault_populate()
632 psind = m->psind; in vm_fault_populate()
633 while (psind > 0 && ((vaddr & (pagesizes[psind] - 1)) != 0 || in vm_fault_populate()
634 pidx + OFF_TO_IDX(pagesizes[psind]) - 1 > pager_last || in vm_fault_populate()
635 !pmap_ps_enabled(fs->map->pmap))) in vm_fault_populate()
636 psind--; in vm_fault_populate()
643 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_populate()
644 rv = pmap_enter(fs->map->pmap, vaddr, m, fs->prot, fs->fault_type | in vm_fault_populate()
645 (fs->wired ? PMAP_ENTER_WIRED : 0), psind); in vm_fault_populate()
652 * key. Revert to single-page mappings if this happens. in vm_fault_populate()
658 MPASS(!fs->wired); in vm_fault_populate()
660 rv = pmap_enter(fs->map->pmap, vaddr + ptoa(i), in vm_fault_populate()
661 &m[i], fs->prot, fs->fault_type, 0); in vm_fault_populate()
666 VM_OBJECT_WLOCK(fs->first_object); in vm_fault_populate()
668 if ((fs->fault_flags & VM_FAULT_WIRE) != 0 && in vm_fault_populate()
669 m[i].pindex == fs->first_pindex) in vm_fault_populate()
673 if (fs->m_hold != NULL && in vm_fault_populate()
674 m[i].pindex == fs->first_pindex) { in vm_fault_populate()
675 (*fs->m_hold) = &m[i]; in vm_fault_populate()
682 curthread->td_ru.ru_majflt++; in vm_fault_populate()
702 * If successful, the page is inserted into the
708 * KERN_SUCCESS is returned if the page fault is handled; otherwise,
709 * a standard error specifying why the fault is fatal is returned.
756 * the images without the ABI-tag ELF in vm_fault_trap()
760 curproc->p_osrel >= P_OSREL_SIGSEGV) { in vm_fault_trap()
789 if (fs->object == fs->first_object) in vm_fault_object_ensure_wlocked()
790 VM_OBJECT_ASSERT_WLOCKED(fs->object); in vm_fault_object_ensure_wlocked()
792 if (!fs->can_read_lock) { in vm_fault_object_ensure_wlocked()
793 VM_OBJECT_ASSERT_WLOCKED(fs->object); in vm_fault_object_ensure_wlocked()
797 if (VM_OBJECT_WOWNED(fs->object)) in vm_fault_object_ensure_wlocked()
800 if (VM_OBJECT_TRYUPGRADE(fs->object)) in vm_fault_object_ensure_wlocked()
812 if (fs->object->type != OBJT_VNODE) in vm_fault_lock_vnode()
814 vp = fs->object->handle; in vm_fault_lock_vnode()
815 if (vp == fs->vp) { in vm_fault_lock_vnode()
816 ASSERT_VOP_LOCKED(vp, "saved vnode is not locked"); in vm_fault_lock_vnode()
833 * paging-in-progress count incremented. Otherwise, we could in vm_fault_lock_vnode()
838 fs->vp = vp; in vm_fault_lock_vnode()
849 fs->vp = vp; in vm_fault_lock_vnode()
855 * Calculate the desired readahead. Handle drop-behind.
865 KASSERT(fs->lookup_still_valid, ("map unlocked")); in vm_fault_readahead()
866 era = fs->entry->read_ahead; in vm_fault_readahead()
867 behavior = vm_map_entry_behavior(fs->entry); in vm_fault_readahead()
872 if (fs->vaddr == fs->entry->next_read) in vm_fault_readahead()
873 vm_fault_dontneed(fs, fs->vaddr, nera); in vm_fault_readahead()
874 } else if (fs->vaddr == fs->entry->next_read) { in vm_fault_readahead()
876 * This is a sequential fault. Arithmetically in vm_fault_readahead()
878 * the read-ahead window. The requested in vm_fault_readahead()
879 * number of pages is "# of sequential faults in vm_fault_readahead()
889 vm_fault_dontneed(fs, fs->vaddr, nera); in vm_fault_readahead()
892 * This is a non-sequential fault. in vm_fault_readahead()
901 fs->entry->read_ahead = nera; in vm_fault_readahead()
912 KASSERT(!fs->lookup_still_valid, in vm_fault_lookup()
914 result = vm_map_lookup(&fs->map, fs->vaddr, fs->fault_type | in vm_fault_lookup()
915 VM_PROT_FAULT_LOOKUP, &fs->entry, &fs->first_object, in vm_fault_lookup()
916 &fs->first_pindex, &fs->prot, &fs->wired); in vm_fault_lookup()
922 fs->map_generation = fs->map->timestamp; in vm_fault_lookup()
924 if (fs->entry->eflags & MAP_ENTRY_NOFAULT) { in vm_fault_lookup()
926 __func__, (u_long)fs->vaddr); in vm_fault_lookup()
929 if (fs->entry->eflags & MAP_ENTRY_IN_TRANSITION && in vm_fault_lookup()
930 fs->entry->wiring_thread != curthread) { in vm_fault_lookup()
931 vm_map_unlock_read(fs->map); in vm_fault_lookup()
932 vm_map_lock(fs->map); in vm_fault_lookup()
933 if (vm_map_lookup_entry(fs->map, fs->vaddr, &fs->entry) && in vm_fault_lookup()
934 (fs->entry->eflags & MAP_ENTRY_IN_TRANSITION)) { in vm_fault_lookup()
936 fs->entry->eflags |= MAP_ENTRY_NEEDS_WAKEUP; in vm_fault_lookup()
937 vm_map_unlock_and_wait(fs->map, 0); in vm_fault_lookup()
939 vm_map_unlock(fs->map); in vm_fault_lookup()
943 MPASS((fs->entry->eflags & MAP_ENTRY_GUARD) == 0); in vm_fault_lookup()
945 if (fs->wired) in vm_fault_lookup()
946 fs->fault_type = fs->prot | (fs->fault_type & VM_PROT_COPY); in vm_fault_lookup()
948 KASSERT((fs->fault_flags & VM_FAULT_WIRE) == 0, in vm_fault_lookup()
949 ("!fs->wired && VM_FAULT_WIRE")); in vm_fault_lookup()
950 fs->lookup_still_valid = true; in vm_fault_lookup()
963 if (!vm_map_trylock_read(fs->map)) in vm_fault_relookup()
966 fs->lookup_still_valid = true; in vm_fault_relookup()
967 if (fs->map->timestamp == fs->map_generation) in vm_fault_relookup()
970 result = vm_map_lookup_locked(&fs->map, fs->vaddr, fs->fault_type, in vm_fault_relookup()
971 &fs->entry, &retry_object, &retry_pindex, &retry_prot, in vm_fault_relookup()
972 &fs->wired); in vm_fault_relookup()
982 if (retry_object != fs->first_object || in vm_fault_relookup()
983 retry_pindex != fs->first_pindex) in vm_fault_relookup()
989 * read to write permission is OK - we leave the page in vm_fault_relookup()
990 * write-protected, and catch the write fault. Changing from in vm_fault_relookup()
992 * write-enabled after all. in vm_fault_relookup()
994 fs->prot &= retry_prot; in vm_fault_relookup()
995 fs->fault_type &= retry_prot; in vm_fault_relookup()
996 if (fs->prot == 0) in vm_fault_relookup()
999 /* Reassert because wired may have changed. */ in vm_fault_relookup()
1000 KASSERT(fs->wired || (fs->fault_flags & VM_FAULT_WIRE) == 0, in vm_fault_relookup()
1001 ("!wired && VM_FAULT_WIRE")); in vm_fault_relookup()
1011 KASSERT(fs->object != fs->first_object, in vm_fault_cow()
1027 fs->object->shadow_count == 1 && fs->object->ref_count == 1 && in vm_fault_cow()
1031 fs->object->handle == NULL && (fs->object->flags & OBJ_ANON) != 0 && in vm_fault_cow()
1035 (is_first_object_locked = VM_OBJECT_TRYWLOCK(fs->first_object)) && in vm_fault_cow()
1036 fs->object == fs->first_object->backing_object && in vm_fault_cow()
1037 VM_OBJECT_TRYWLOCK(fs->object)) { in vm_fault_cow()
1039 * Remove but keep xbusy for replace. fs->m is moved into in vm_fault_cow()
1040 * fs->first_object and left busy while fs->first_m is in vm_fault_cow()
1043 vm_page_remove_xbusy(fs->m); in vm_fault_cow()
1044 vm_page_replace(fs->m, fs->first_object, fs->first_pindex, in vm_fault_cow()
1045 fs->first_m); in vm_fault_cow()
1046 vm_page_dirty(fs->m); in vm_fault_cow()
1051 vm_reserv_rename(fs->m, fs->first_object, fs->object, in vm_fault_cow()
1052 OFF_TO_IDX(fs->first_object->backing_object_offset)); in vm_fault_cow()
1054 VM_OBJECT_WUNLOCK(fs->object); in vm_fault_cow()
1055 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_cow()
1056 fs->first_m = fs->m; in vm_fault_cow()
1057 fs->m = NULL; in vm_fault_cow()
1061 VM_OBJECT_WUNLOCK(fs->first_object); in vm_fault_cow()
1065 pmap_copy_page(fs->m, fs->first_m); in vm_fault_cow()
1066 vm_page_valid(fs->first_m); in vm_fault_cow()
1067 if (fs->wired && (fs->fault_flags & VM_FAULT_WIRE) == 0) { in vm_fault_cow()
1068 vm_page_wire(fs->first_m); in vm_fault_cow()
1069 vm_page_unwire(fs->m, PQ_INACTIVE); in vm_fault_cow()
1073 * pmap_enter is complete. in vm_fault_cow()
1075 fs->m_cow = fs->m; in vm_fault_cow()
1076 fs->m = NULL; in vm_fault_cow()
1079 * Typically, the shadow object is either private to this in vm_fault_cow()
1083 * we need to ensure that any pmap-level mappings to the in vm_fault_cow()
1084 * original, copy-on-write page from the backing object are in vm_fault_cow()
1087 * The flag check is racy, but this is tolerable: if in vm_fault_cow()
1088 * OBJ_ONEMAPPING is cleared after the check, the busy state in vm_fault_cow()
1091 * address space. If OBJ_ONEMAPPING is set after the check, in vm_fault_cow()
1095 vm_page_assert_xbusied(fs->m_cow); in vm_fault_cow()
1096 if ((fs->first_object->flags & OBJ_ONEMAPPING) == 0) in vm_fault_cow()
1097 pmap_remove_all(fs->m_cow); in vm_fault_cow()
1100 vm_object_pip_wakeup(fs->object); in vm_fault_cow()
1105 fs->object = fs->first_object; in vm_fault_cow()
1106 fs->pindex = fs->first_pindex; in vm_fault_cow()
1107 fs->m = fs->first_m; in vm_fault_cow()
1109 curthread->td_cow++; in vm_fault_cow()
1117 if (fs->object == fs->first_object || !fs->can_read_lock) in vm_fault_next()
1118 VM_OBJECT_ASSERT_WLOCKED(fs->object); in vm_fault_next()
1120 VM_OBJECT_ASSERT_LOCKED(fs->object); in vm_fault_next()
1126 * the next object. However, if this is the top-level in vm_fault_next()
1132 if (fs->object == fs->first_object) { in vm_fault_next()
1133 fs->first_m = fs->m; in vm_fault_next()
1134 fs->m = NULL; in vm_fault_next()
1135 } else if (fs->m != NULL) { in vm_fault_next()
1137 fs->can_read_lock = false; in vm_fault_next()
1141 vm_fault_page_free(&fs->m); in vm_fault_next()
1148 next_object = fs->object->backing_object; in vm_fault_next()
1151 MPASS(fs->first_m != NULL); in vm_fault_next()
1152 KASSERT(fs->object != next_object, ("object loop %p", next_object)); in vm_fault_next()
1153 if (fs->can_read_lock) in vm_fault_next()
1158 if (fs->object != fs->first_object) in vm_fault_next()
1159 vm_object_pip_wakeup(fs->object); in vm_fault_next()
1160 fs->pindex += OFF_TO_IDX(fs->object->backing_object_offset); in vm_fault_next()
1161 VM_OBJECT_UNLOCK(fs->object); in vm_fault_next()
1162 fs->object = next_object; in vm_fault_next()
1175 if (fs->object != fs->first_object) { in vm_fault_zerofill()
1176 vm_object_pip_wakeup(fs->object); in vm_fault_zerofill()
1177 fs->object = fs->first_object; in vm_fault_zerofill()
1178 fs->pindex = fs->first_pindex; in vm_fault_zerofill()
1180 MPASS(fs->first_m != NULL); in vm_fault_zerofill()
1181 MPASS(fs->m == NULL); in vm_fault_zerofill()
1182 fs->m = fs->first_m; in vm_fault_zerofill()
1183 fs->first_m = NULL; in vm_fault_zerofill()
1188 if ((fs->m->flags & PG_ZERO) == 0) { in vm_fault_zerofill()
1189 pmap_zero_page(fs->m); in vm_fault_zerofill()
1194 vm_page_valid(fs->m); in vm_fault_zerofill()
1209 if (!fs->oom_started) { in vm_fault_allocate_oom()
1210 fs->oom_started = true; in vm_fault_allocate_oom()
1211 getmicrotime(&fs->oom_start_time); in vm_fault_allocate_oom()
1216 timevalsub(&now, &fs->oom_start_time); in vm_fault_allocate_oom()
1223 curproc->p_pid, curproc->p_comm); in vm_fault_allocate_oom()
1225 fs->oom_started = false; in vm_fault_allocate_oom()
1238 if ((fs->object->flags & OBJ_SIZEVNLOCK) != 0) { in vm_fault_allocate()
1245 if (fs->pindex >= fs->object->size) { in vm_fault_allocate()
1250 if (fs->object == fs->first_object && in vm_fault_allocate()
1251 (fs->first_object->flags & OBJ_POPULATE) != 0 && in vm_fault_allocate()
1252 fs->first_object->shadow_count == 0) { in vm_fault_allocate()
1277 * daemon in an attempt to resolve an out-of-memory condition. in vm_fault_allocate()
1279 * The unlocked read of the p_flag is harmless. At worst, the P_KILLED in vm_fault_allocate()
1283 dset = fs->object->domain.dr_policy; in vm_fault_allocate()
1285 dset = curthread->td_domain.dr_policy; in vm_fault_allocate()
1286 if (!vm_page_count_severe_set(&dset->ds_mask) || P_KILLED(curproc)) { in vm_fault_allocate()
1288 vm_object_color(fs->object, atop(fs->vaddr) - fs->pindex); in vm_fault_allocate()
1290 if (!vm_pager_can_alloc_page(fs->object, fs->pindex)) { in vm_fault_allocate()
1294 fs->m = vm_page_alloc(fs->object, fs->pindex, in vm_fault_allocate()
1297 if (fs->m == NULL) { in vm_fault_allocate()
1302 fs->oom_started = false; in vm_fault_allocate()
1308 * Call the pager to retrieve the page if there is a chance
1325 * unlocking the map, using the saved addresses is in vm_fault_getpages()
1328 e_start = fs->entry->start; in vm_fault_getpages()
1329 e_end = fs->entry->end; in vm_fault_getpages()
1330 behavior = vm_map_entry_behavior(fs->entry); in vm_fault_getpages()
1343 if (fs->nera == -1 && !P_KILLED(curproc)) in vm_fault_getpages()
1344 fs->nera = vm_fault_readahead(fs); in vm_fault_getpages()
1358 KASSERT(fs->vp == NULL || !vm_map_is_system(fs->map), in vm_fault_getpages()
1359 ("vm_fault: vnode-backed object mapped by system map")); in vm_fault_getpages()
1365 if (fs->nera == -1 || behavior == MAP_ENTRY_BEHAV_RANDOM || in vm_fault_getpages()
1370 /* Is this a sequential fault? */ in vm_fault_getpages()
1371 if (fs->nera > 0) { in vm_fault_getpages()
1373 ahead = fs->nera; in vm_fault_getpages()
1376 * Request a cluster of pages that is in vm_fault_getpages()
1380 * boundary is more likely to coincide in vm_fault_getpages()
1385 cluster_offset = fs->pindex % VM_FAULT_READ_DEFAULT; in vm_fault_getpages()
1387 atop(fs->vaddr - e_start)); in vm_fault_getpages()
1388 ahead = VM_FAULT_READ_DEFAULT - 1 - cluster_offset; in vm_fault_getpages()
1390 ahead = ulmin(ahead, atop(e_end - fs->vaddr) - 1); in vm_fault_getpages()
1394 rv = vm_pager_get_pages(fs->object, &fs->m, 1, behindp, aheadp); in vm_fault_getpages()
1399 curproc->p_pid, curproc->p_comm); in vm_fault_getpages()
1406 VM_OBJECT_WLOCK(fs->object); in vm_fault_getpages()
1407 vm_fault_page_free(&fs->m); in vm_fault_getpages()
1417 * Wait/Retry if the page is busy. We have to do this if the page is
1419 * read busy for pageouts (and even pageins if it is the vnode pager),
1424 * is marked valid, but since such pages are typically already pmap'd,
1425 * putting that special case in might be more effort then it is worth.
1434 * sleeping so that the page daemon is less in vm_fault_busy_sleep()
1437 vm_page_aflag_set(fs->m, PGA_REFERENCED); in vm_fault_busy_sleep()
1438 if (fs->object != fs->first_object) { in vm_fault_busy_sleep()
1439 vm_fault_page_release(&fs->first_m); in vm_fault_busy_sleep()
1440 vm_object_pip_wakeup(fs->first_object); in vm_fault_busy_sleep()
1442 vm_object_pip_wakeup(fs->object); in vm_fault_busy_sleep()
1444 if (fs->m != vm_page_lookup(fs->object, fs->pindex) || in vm_fault_busy_sleep()
1445 !vm_page_busy_sleep(fs->m, "vmpfw", 0)) in vm_fault_busy_sleep()
1446 VM_OBJECT_UNLOCK(fs->object); in vm_fault_busy_sleep()
1448 vm_object_deallocate(fs->first_object); in vm_fault_busy_sleep()
1452 * Handle page lookup, populate, allocate, page-in for the current
1455 * The object is locked on entry and will remain locked with a return
1465 if (fs->object == fs->first_object || !fs->can_read_lock) in vm_fault_object()
1466 VM_OBJECT_ASSERT_WLOCKED(fs->object); in vm_fault_object()
1468 VM_OBJECT_ASSERT_LOCKED(fs->object); in vm_fault_object()
1471 * If the object is marked for imminent termination, we retry in vm_fault_object()
1475 if ((fs->object->flags & OBJ_DEAD) != 0) { in vm_fault_object()
1476 dead = fs->object->type == OBJT_DEAD; in vm_fault_object()
1485 * See if the page is resident. in vm_fault_object()
1487 fs->m = vm_page_lookup(fs->object, fs->pindex); in vm_fault_object()
1488 if (fs->m != NULL) { in vm_fault_object()
1489 if (!vm_page_tryxbusy(fs->m)) { in vm_fault_object()
1495 * The page is marked busy for other processes and the in vm_fault_object()
1496 * pagedaemon. If it is still completely valid we are in vm_fault_object()
1499 if (vm_page_all_valid(fs->m)) { in vm_fault_object()
1500 VM_OBJECT_UNLOCK(fs->object); in vm_fault_object()
1506 * Page is not resident. If the pager might contain the page in vm_fault_object()
1507 * or this is the beginning of the search, allocate a new in vm_fault_object()
1510 if (fs->m == NULL && (vm_fault_object_needs_getpages(fs->object) || in vm_fault_object()
1511 fs->object == fs->first_object)) { in vm_fault_object()
1513 fs->can_read_lock = false; in vm_fault_object()
1527 if (vm_fault_object_needs_getpages(fs->object)) { in vm_fault_object()
1530 * or found an existing page that is only partially in vm_fault_object()
1534 * page is exclusive busied. The exclusive busy in vm_fault_object()
1536 * the object lock is dropped. in vm_fault_object()
1538 VM_OBJECT_UNLOCK(fs->object); in vm_fault_object()
1541 VM_OBJECT_WLOCK(fs->object); in vm_fault_object()
1560 if ((curthread->td_pflags & TDP_NOFAULTING) != 0) in vm_fault()
1570 fs.nera = -1; in vm_fault()
1590 * Try to avoid lock contention on the top-level object through in vm_fault()
1591 * special-case handling of some types of page faults, specifically, in vm_fault()
1592 * those that are mapping an existing page from the top-level object. in vm_fault()
1597 (fs.entry->eflags & MAP_ENTRY_SPLIT_BOUNDARY_MASK) == 0 && in vm_fault()
1611 * are messing with it. Once we have the reference, the map is free in vm_fault()
1615 * Bump the paging-in-progress count to prevent size changes (e.g. in vm_fault()
1629 if ((fs.entry->eflags & MAP_ENTRY_SPLIT_BOUNDARY_MASK) != 0) { in vm_fault()
1677 * traverse into a backing object or zero fill if none is in vm_fault()
1708 * If the page is being written, but isn't already owned by the in vm_fault()
1709 * top-level object, we have to copy it into a new page owned by the in vm_fault()
1710 * top-level object. in vm_fault()
1719 * We only try to prefault read-only mappings to the in vm_fault()
1720 * neighboring pages when this copy-on-write fault is in vm_fault()
1722 * is typically wasted effort. in vm_fault()
1754 fs.entry->next_read = vaddr + ptoa(ahead) + PAGE_SIZE; in vm_fault()
1757 * Page must be completely valid or it is not fit to in vm_fault()
1772 pmap_enter(fs.map->pmap, vaddr, fs.m, fs.prot, in vm_fault()
1773 fs.fault_type | (fs.wired ? PMAP_ENTER_WIRED : 0), 0); in vm_fault()
1775 fs.wired == 0) in vm_fault()
1781 * If the page is not wired down, then put it where the pageout daemon in vm_fault()
1801 curthread->td_ru.ru_majflt++; in vm_fault()
1803 if (racct_enable && fs.object->type == OBJT_VNODE) { in vm_fault()
1818 curthread->td_ru.ru_minflt++; in vm_fault()
1828 * cross a cluster-size boundary. The cluster size is the greater of the
1831 * When "fs->first_object" is a shadow object, the pages in the backing object
1845 VM_OBJECT_ASSERT_UNLOCKED(fs->object); in vm_fault_dontneed()
1846 first_object = fs->first_object; in vm_fault_dontneed()
1848 if ((first_object->flags & (OBJ_FICTITIOUS | OBJ_UNMANAGED)) == 0) { in vm_fault_dontneed()
1854 if (vaddr - end >= size - PAGE_SIZE - ptoa(ahead) && in vm_fault_dontneed()
1855 (entry = fs->entry)->start < end) { in vm_fault_dontneed()
1856 if (end - entry->start < size) in vm_fault_dontneed()
1857 start = entry->start; in vm_fault_dontneed()
1859 start = end - size; in vm_fault_dontneed()
1860 pmap_advise(fs->map->pmap, start, end, MADV_DONTNEED); in vm_fault_dontneed()
1861 pstart = OFF_TO_IDX(entry->offset) + atop(start - in vm_fault_dontneed()
1862 entry->start); in vm_fault_dontneed()
1864 pend = OFF_TO_IDX(entry->offset) + atop(end - in vm_fault_dontneed()
1865 entry->start); in vm_fault_dontneed()
1866 while ((m = m_next) != NULL && m->pindex < pend) { in vm_fault_dontneed()
1881 * is in the inactive queue is racy; in the in vm_fault_dontneed()
1895 * pagefaults into a processes address space. It is a "cousin"
1912 pmap = fs->map->pmap; in vm_fault_prefault()
1913 if (pmap != vmspace_pmap(curthread->td_proc->p_vmspace)) in vm_fault_prefault()
1916 entry = fs->entry; in vm_fault_prefault()
1919 starta = entry->start; in vm_fault_prefault()
1921 starta = addra - backward * PAGE_SIZE; in vm_fault_prefault()
1922 if (starta < entry->start) in vm_fault_prefault()
1923 starta = entry->start; in vm_fault_prefault()
1925 prot = entry->protection; in vm_fault_prefault()
1931 if ((fs->prot & VM_PROT_WRITE) != 0) in vm_fault_prefault()
1937 * "addra". Specifically, the sequence is "addra - PAGE_SIZE", "addra in vm_fault_prefault()
1938 * + PAGE_SIZE", "addra - 2 * PAGE_SIZE", "addra + 2 * PAGE_SIZE", ... in vm_fault_prefault()
1943 addr = addra + ((i >> 1) + 1) * ((i & 1) == 0 ? -PAGE_SIZE : in vm_fault_prefault()
1948 if (addr < starta || addr >= entry->end) in vm_fault_prefault()
1954 pindex = ((addr - entry->start) + entry->offset) >> PAGE_SHIFT; in vm_fault_prefault()
1955 lobject = entry->object.vm_object; in vm_fault_prefault()
1960 (backing_object = lobject->backing_object) != NULL) { in vm_fault_prefault()
1961 KASSERT((lobject->backing_object_offset & PAGE_MASK) == in vm_fault_prefault()
1963 pindex += lobject->backing_object_offset >> PAGE_SHIFT; in vm_fault_prefault()
1965 if (!obj_locked || lobject != entry->object.vm_object) in vm_fault_prefault()
1970 if (!obj_locked || lobject != entry->object.vm_object) in vm_fault_prefault()
1975 (m->flags & PG_FICTITIOUS) == 0) in vm_fault_prefault()
1977 if (!obj_locked || lobject != entry->object.vm_object) in vm_fault_prefault()
1986 * pages are successfully held, then the number of held pages is returned
1988 * of the pages cannot be held, -1 is returned.
2005 return (-1); in vm_fault_quick_hold_pages()
2007 if (atop(end - addr) > max_count) in vm_fault_quick_hold_pages()
2009 count = atop(end - addr); in vm_fault_quick_hold_pages()
2012 * Most likely, the physical pages are resident in the pmap, so it is in vm_fault_quick_hold_pages()
2017 *mp = pmap_extract_and_hold(map->pmap, va, prot); in vm_fault_quick_hold_pages()
2021 (*mp)->dirty != VM_PAGE_BITS_ALL) { in vm_fault_quick_hold_pages()
2028 * The object lock is not held here. in vm_fault_quick_hold_pages()
2042 * i.e., TDP_NOFAULTING is set, we must not sleep nor in vm_fault_quick_hold_pages()
2050 (curthread->td_pflags & TDP_NOFAULTING) != 0) in vm_fault_quick_hold_pages()
2062 return (-1); in vm_fault_quick_hold_pages()
2070 * underlying pages. When src_entry is equal to dst_entry, function
2071 * implements COW for wired-down map entry. Otherwise, it forks
2072 * wired entry into dst_map.
2076 * The source map entry must be wired down (or be a sharing map
2077 * entry corresponding to a main map entry that is wired down).
2093 KASSERT(upgrade || dst_entry->object.vm_object == NULL, in vm_fault_copy_entry()
2101 * A writeable large page mapping is only created if all of in vm_fault_copy_entry()
2106 access = prot = dst_entry->protection; in vm_fault_copy_entry()
2110 src_object = src_entry->object.vm_object; in vm_fault_copy_entry()
2111 src_pindex = OFF_TO_IDX(src_entry->offset); in vm_fault_copy_entry()
2113 if (upgrade && (dst_entry->eflags & MAP_ENTRY_NEEDS_COPY) == 0) { in vm_fault_copy_entry()
2118 * Create the top-level object for the destination entry. in vm_fault_copy_entry()
2119 * Doesn't actually shadow anything - we copy the pages in vm_fault_copy_entry()
2122 dst_object = vm_object_allocate_anon(atop(dst_entry->end - in vm_fault_copy_entry()
2123 dst_entry->start), NULL, NULL, 0); in vm_fault_copy_entry()
2125 dst_object->flags |= OBJ_COLORED; in vm_fault_copy_entry()
2126 dst_object->pg_color = atop(dst_entry->start); in vm_fault_copy_entry()
2128 dst_object->domain = src_object->domain; in vm_fault_copy_entry()
2129 dst_object->charge = dst_entry->end - dst_entry->start; in vm_fault_copy_entry()
2131 dst_entry->object.vm_object = dst_object; in vm_fault_copy_entry()
2132 dst_entry->offset = 0; in vm_fault_copy_entry()
2133 dst_entry->eflags &= ~MAP_ENTRY_VN_EXEC; in vm_fault_copy_entry()
2138 KASSERT(dst_entry->cred == NULL, in vm_fault_copy_entry()
2140 dst_object->cred = curthread->td_ucred; in vm_fault_copy_entry()
2141 crhold(dst_object->cred); in vm_fault_copy_entry()
2142 *fork_charge += dst_object->charge; in vm_fault_copy_entry()
2143 } else if ((dst_object->flags & OBJ_SWAP) != 0 && in vm_fault_copy_entry()
2144 dst_object->cred == NULL) { in vm_fault_copy_entry()
2145 KASSERT(dst_entry->cred != NULL, ("no cred for entry %p", in vm_fault_copy_entry()
2147 dst_object->cred = dst_entry->cred; in vm_fault_copy_entry()
2148 dst_entry->cred = NULL; in vm_fault_copy_entry()
2154 * destination object. Since the source is wired, those pages in vm_fault_copy_entry()
2155 * must exist. In contrast, the destination is pageable. in vm_fault_copy_entry()
2162 for (vaddr = dst_entry->start, dst_pindex = 0; in vm_fault_copy_entry()
2163 vaddr < dst_entry->end; in vm_fault_copy_entry()
2168 * Because the source is wired down, the page will be in vm_fault_copy_entry()
2176 (backing_object = object->backing_object) != NULL) { in vm_fault_copy_entry()
2178 * Unless the source mapping is read-only or in vm_fault_copy_entry()
2179 * it is presently being upgraded from in vm_fault_copy_entry()
2180 * read-only, the first object in the shadow in vm_fault_copy_entry()
2183 * executed when the source mapping is already in vm_fault_copy_entry()
2186 KASSERT((src_entry->protection & VM_PROT_WRITE) == 0 || in vm_fault_copy_entry()
2191 pindex += OFF_TO_IDX(object->backing_object_offset); in vm_fault_copy_entry()
2219 (object->flags & OBJ_ONEMAPPING) == 0) in vm_fault_copy_entry()
2229 dst_m->dirty = dst_m->valid = src_m->valid; in vm_fault_copy_entry()
2235 if (dst_m->pindex >= dst_object->size) { in vm_fault_copy_entry()
2238 * out of bounds if the object type is in vm_fault_copy_entry()
2247 * Enter it in the pmap. If a wired, copy-on-write in vm_fault_copy_entry()
2248 * mapping is being replaced by a write-enabled in vm_fault_copy_entry()
2255 * all copies of the wired map entry have similar in vm_fault_copy_entry()
2260 pmap_enter(dst_map->pmap, vaddr, dst_m, prot, in vm_fault_copy_entry()
2274 ("dst_m %p is not wired", dst_m)); in vm_fault_copy_entry()
2283 dst_entry->eflags &= ~(MAP_ENTRY_COW | MAP_ENTRY_NEEDS_COPY); in vm_fault_copy_entry()
2289 * Block entry into the machine-independent layer's page fault handler by
2291 * return KERN_PROTECTION_FAILURE. Enable machine-dependent handling of