git: 9ff38b3d881c - stable/14 - vfs: be less eager to call uma_reclaim(UMA_RECLAIM_DRAIN)

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Fri, 13 Oct 2023 23:43:10 UTC
The branch stable/14 has been updated by mjg:

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

commit 9ff38b3d881ce910803500fe3460f8283c96b4b2
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-10-10 16:15:53 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-10-13 23:41:46 +0000

    vfs: be less eager to call uma_reclaim(UMA_RECLAIM_DRAIN)
    
    In face of vnode shortage the count very easily can go few units above
    the limit before going back down.
    
    Calling uma_reclaim results in massive amount of work which in this case
    is not warranted.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit 1bf55a739e754765fa2dc15ab6481fe411084be3)
---
 sys/kern/vfs_subr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index e37f8697efa2..e7e612254ba2 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1674,7 +1674,12 @@ vnlru_proc(void)
 		target = target / 10 + 1;
 		done = vlrureclaim(reclaim_nc_src, trigger, target);
 		mtx_unlock(&vnode_list_mtx);
-		if (onumvnodes > desiredvnodes && numvnodes <= desiredvnodes)
+		/*
+		 * Total number of vnodes can transiently go slightly above the
+		 * limit (see vn_alloc_hard), no need to call uma_reclaim if
+		 * this happens.
+		 */
+		if (onumvnodes + 1000 > desiredvnodes && numvnodes <= desiredvnodes)
 			uma_reclaim(UMA_RECLAIM_DRAIN);
 		if (done == 0) {
 			if (force == 0 || force == 1) {