git: c1d12b925b2c - main - vm_page: pass page to iter_remove

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Sun, 08 Dec 2024 20:31:16 UTC
The branch main has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=c1d12b925b2c87d55a86b874e7b7e7a590844eb9

commit c1d12b925b2c87d55a86b874e7b7e7a590844eb9
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-12-08 20:30:22 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-12-08 20:30:22 +0000

    vm_page: pass page to iter_remove
    
    Pass the to-be-freed page to vm_page_iter_remove as a parameter,
    rather than computing it from the iterator parameter, to improve
    performance.
    
    Reviewed by:    alc
    Differential Revision:  https://reviews.freebsd.org/D47730
---
 sys/arm/nvidia/drm2/tegra_bo.c |  2 +-
 sys/vm/device_pager.c          | 10 +++++-----
 sys/vm/vm_object.c             |  8 ++++----
 sys/vm/vm_page.c               |  6 ++----
 sys/vm/vm_page.h               |  2 +-
 sys/vm/vm_pager.h              |  2 +-
 6 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/sys/arm/nvidia/drm2/tegra_bo.c b/sys/arm/nvidia/drm2/tegra_bo.c
index 0b62e78224dc..6d380b95a4a9 100644
--- a/sys/arm/nvidia/drm2/tegra_bo.c
+++ b/sys/arm/nvidia/drm2/tegra_bo.c
@@ -64,7 +64,7 @@ tegra_bo_destruct(struct tegra_bo *bo)
 	for (i = 0; i < bo->npages; i++) {
 		m = vm_page_iter_lookup(&pages, i);
 		vm_page_busy_acquire(m, 0);
-		cdev_mgtdev_pager_free_page(&pages);
+		cdev_mgtdev_pager_free_page(&pages, m);
 		m->flags &= ~PG_FICTITIOUS;
 		vm_page_unwire_noq(m);
 		vm_page_free(m);
diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c
index 55bc948a4c44..24241d118c7a 100644
--- a/sys/vm/device_pager.c
+++ b/sys/vm/device_pager.c
@@ -268,7 +268,7 @@ cdev_pager_free_page(vm_object_t object, vm_page_t m)
 
 		vm_page_iter_init(&pages, object);
 		vm_page_iter_lookup(&pages, m->pindex);
-		cdev_mgtdev_pager_free_page(&pages);
+		cdev_mgtdev_pager_free_page(&pages, m);
 	} else if (object->type == OBJT_DEVICE)
 		dev_pager_free_page(object, m);
 	else
@@ -277,10 +277,10 @@ cdev_pager_free_page(vm_object_t object, vm_page_t m)
 }
 
 void
-cdev_mgtdev_pager_free_page(struct pctrie_iter *pages)
+cdev_mgtdev_pager_free_page(struct pctrie_iter *pages, vm_page_t m)
 {
-	pmap_remove_all(vm_radix_iter_page(pages));
-	vm_page_iter_remove(pages);
+	pmap_remove_all(m);
+	vm_page_iter_remove(pages, m);
 }
 
 void
@@ -298,7 +298,7 @@ retry:
 			pctrie_iter_reset(&pages);
 			goto retry;
 		}
-		cdev_mgtdev_pager_free_page(&pages);
+		cdev_mgtdev_pager_free_page(&pages, m);
 	}
 	VM_OBJECT_WUNLOCK(object);
 }
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index ff95469749b7..a3cfb4d036be 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -1599,7 +1599,7 @@ retry:
 		 * an incomplete fault.  Just remove and ignore.
 		 */
 		if (vm_page_none_valid(m)) {
-			if (vm_page_iter_remove(&pages))
+			if (vm_page_iter_remove(&pages, m))
 				vm_page_free(m);
 			continue;
 		}
@@ -1727,7 +1727,7 @@ vm_object_collapse_scan(vm_object_t object)
 
 			KASSERT(!pmap_page_is_mapped(p),
 			    ("freeing mapped page %p", p));
-			if (vm_page_iter_remove(&pages))
+			if (vm_page_iter_remove(&pages, p))
 				vm_page_free(p);
 			next = vm_radix_iter_step(&pages);
 			continue;
@@ -1736,7 +1736,7 @@ vm_object_collapse_scan(vm_object_t object)
 		if (!vm_page_all_valid(p)) {
 			KASSERT(!pmap_page_is_mapped(p),
 			    ("freeing mapped page %p", p));
-			if (vm_page_iter_remove(&pages))
+			if (vm_page_iter_remove(&pages, p))
 				vm_page_free(p);
 			next = vm_radix_iter_step(&pages);
 			continue;
@@ -1779,7 +1779,7 @@ vm_object_collapse_scan(vm_object_t object)
 			    ("freeing mapped page %p", p));
 			if (pp != NULL)
 				vm_page_xunbusy(pp);
-			if (vm_page_iter_remove(&pages))
+			if (vm_page_iter_remove(&pages, p))
 				vm_page_free(p);
 			next = vm_radix_iter_step(&pages);
 			continue;
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index 8a23f900e987..f351295c1af5 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -1752,16 +1752,14 @@ vm_page_remove(vm_page_t m)
 /*
  *	vm_page_iter_remove:
  *
- *	Remove the current page, as identified by iterator, and remove it from the
+ *	Remove the current page, and use the iterator to remove it from the
  *	radix tree.
  */
 bool
-vm_page_iter_remove(struct pctrie_iter *pages)
+vm_page_iter_remove(struct pctrie_iter *pages, vm_page_t m)
 {
-	vm_page_t m;
 	bool dropped;
 
-	m = vm_radix_iter_page(pages);
 	vm_radix_iter_remove(pages);
 	vm_page_remove_radixdone(m);
 	dropped = (vm_page_drop(m, VPRC_OBJREF) == VPRC_OBJREF);
diff --git a/sys/vm/vm_page.h b/sys/vm/vm_page.h
index 29344eadbf05..744688bf789b 100644
--- a/sys/vm/vm_page.h
+++ b/sys/vm/vm_page.h
@@ -654,7 +654,7 @@ void vm_page_iter_free(struct pctrie_iter *pages, vm_page_t m);
 void vm_page_iter_init(struct pctrie_iter *, vm_object_t);
 void vm_page_iter_limit_init(struct pctrie_iter *, vm_object_t, vm_pindex_t);
 vm_page_t vm_page_iter_lookup(struct pctrie_iter *, vm_pindex_t);
-bool vm_page_iter_remove(struct pctrie_iter *pages);
+bool vm_page_iter_remove(struct pctrie_iter *pages, vm_page_t m);
 bool vm_page_iter_rename(struct pctrie_iter *old_pages, vm_page_t m,
     vm_object_t new_object, vm_pindex_t new_pindex);
 void vm_page_launder(vm_page_t m);
diff --git a/sys/vm/vm_pager.h b/sys/vm/vm_pager.h
index 0958d82d6968..c4a9b5e9dcb9 100644
--- a/sys/vm/vm_pager.h
+++ b/sys/vm/vm_pager.h
@@ -300,7 +300,7 @@ vm_object_t cdev_pager_allocate(void *handle, enum obj_type tp,
     vm_ooffset_t foff, struct ucred *cred);
 vm_object_t cdev_pager_lookup(void *handle);
 void cdev_pager_free_page(vm_object_t object, vm_page_t m);
-void cdev_mgtdev_pager_free_page(struct pctrie_iter *pages);
+void cdev_mgtdev_pager_free_page(struct pctrie_iter *pages, vm_page_t m);
 void cdev_mgtdev_pager_free_pages(vm_object_t object);
 
 struct phys_pager_ops {