git: 6d86bdf1c423 - main - vm_pageout: shrink pageout array

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Fri, 02 Aug 2024 02:38:14 UTC
The branch main has been updated by dougm:

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

commit 6d86bdf1c423e162cecd9b7c516b211461d1932b
Author:     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-08-02 02:36:44 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-08-02 02:36:44 +0000

    vm_pageout: shrink pageout array
    
    The array passed to vm_pageout_flush, and constructed in a middle-out
    fashion, can never use array element zero. Shrink the array by one,
    and reduce indices by one, to save that bit of stack space. In the
    vm_object version, make the accounting look more like the pageout
    version.
    
    Reported by:    alc
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D46208
---
 sys/vm/vm_object.c  | 17 +++++++++--------
 sys/vm/vm_pageout.c |  6 +++---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index be21081255c2..7b3950b6f3bc 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -1115,13 +1115,14 @@ static int
 vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags,
     int flags, boolean_t *allclean, boolean_t *eio)
 {
-	vm_page_t ma[2 * vm_pageout_page_count], tp;
-	int count, mreq, runlen;
+	vm_page_t ma[2 * vm_pageout_page_count - 1], tp;
+	int base, count, runlen;
 
 	vm_page_lock_assert(p, MA_NOTOWNED);
 	vm_page_assert_xbusied(p);
 	VM_OBJECT_ASSERT_WLOCKED(object);
-	ma[vm_pageout_page_count] = p;
+	base = nitems(ma) / 2;
+	ma[base] = p;
 	for (count = 1, tp = p; count < vm_pageout_page_count; count++) {
 		tp = vm_page_next(tp);
 		if (tp == NULL || vm_page_tryxbusy(tp) == 0)
@@ -1130,10 +1131,10 @@ vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags,
 			vm_page_xunbusy(tp);
 			break;
 		}
-		ma[vm_pageout_page_count + count] = tp;
+		ma[base + count] = tp;
 	}
 
-	for (mreq = 0, tp = p; count < vm_pageout_page_count; count++, mreq++) {
+	for (tp = p; count < vm_pageout_page_count; count++) {
 		tp = vm_page_prev(tp);
 		if (tp == NULL || vm_page_tryxbusy(tp) == 0)
 			break;
@@ -1141,11 +1142,11 @@ vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags,
 			vm_page_xunbusy(tp);
 			break;
 		}
-		ma[vm_pageout_page_count - 1 - mreq] = tp;
+		ma[--base] = tp;
 	}
 
-	vm_pageout_flush(&ma[vm_pageout_page_count - mreq], count, pagerflags,
-	    mreq, &runlen, eio);
+	vm_pageout_flush(&ma[base], count, pagerflags, nitems(ma) / 2 - base,
+	    &runlen, eio);
 	return (runlen);
 }
 
diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c
index e848d68739ca..8ad4bf4d3ab4 100644
--- a/sys/vm/vm_pageout.c
+++ b/sys/vm/vm_pageout.c
@@ -348,7 +348,7 @@ static int
 vm_pageout_cluster(vm_page_t m)
 {
 	vm_object_t object;
-	vm_page_t mc[2 * vm_pageout_page_count], p, pb, ps;
+	vm_page_t mc[2 * vm_pageout_page_count - 1], p, pb, ps;
 	vm_pindex_t pindex;
 	int ib, is, page_base, pageout_count;
 
@@ -358,9 +358,9 @@ vm_pageout_cluster(vm_page_t m)
 
 	vm_page_assert_xbusied(m);
 
-	mc[vm_pageout_page_count] = pb = ps = m;
 	pageout_count = 1;
-	page_base = vm_pageout_page_count;
+	page_base = nitems(mc) / 2;
+	mc[page_base] = pb = ps = m;
 	ib = 1;
 	is = 1;