From b3cec803eaa4ae3495f9844f93c1f0cadc1b2d6a Mon Sep 17 00:00:00 2001 From: Doug Moore Date: Sat, 27 Jul 2024 16:11:53 -0500 Subject: [PATCH] vm_fault: avoid vm_page_next() Where vm_fault calls vm_page_next, replace it with a use of TAILQ_NEXT and a KASSERT. This avoids needless computation in a NODEBUG kernel and makes the error checking clearer in a GENERIC kernel. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D46168 --- sys/vm/vm_fault.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index df686f3e46dc92..6e0415b30600f8 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -485,7 +485,9 @@ vm_fault_populate_cleanup(vm_object_t object, vm_pindex_t first, VM_OBJECT_ASSERT_WLOCKED(object); MPASS(first <= last); for (pidx = first, m = vm_page_lookup(object, pidx); - pidx <= last; pidx++, m = vm_page_next(m)) { + pidx <= last; pidx++, m = TAILQ_NEXT(m, listq)) { + KASSERT(m != NULL && m->pindex == pidx, + ("%s: pindex mismatch", __func__)); vm_fault_populate_check_page(m); vm_page_deactivate(m); vm_page_xunbusy(m); @@ -623,9 +625,10 @@ vm_fault_populate(struct faultstate *fs) } for (pidx = pager_first, m = vm_page_lookup(fs->first_object, pidx); pidx <= pager_last; - pidx += npages, m = vm_page_next(&m[npages - 1])) { + pidx += npages, m = TAILQ_NEXT(&m[npages - 1], listq)) { vaddr = fs->entry->start + IDX_TO_OFF(pidx) - fs->entry->offset; - + KASSERT(m != NULL && m->pindex == pidx, + ("%s: pindex mismatch", __func__)); psind = m->psind; while (psind > 0 && ((vaddr & (pagesizes[psind] - 1)) != 0 || pidx + OFF_TO_IDX(pagesizes[psind]) - 1 > pager_last ||