git: 01211b4be09f - releng/14.0 - vfs: consult freevnodes in vnlru_kick_cond

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Sat, 14 Oct 2023 01:08:52 UTC
The branch releng/14.0 has been updated by mjg:

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

commit 01211b4be09f6e1838da87339ddb3655702d254b
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-10-10 16:19:53 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-10-14 01:07:26 +0000

    vfs: consult freevnodes in vnlru_kick_cond
    
    If the count is high enough there is no point trying to produce more.
    Not going there reduces traffic on the vnode_list mtx.
    
    This further shaves total real time in a test mentioned in:
    74be676d87745eb7 ("vfs: drop one vnode list lock trip during vnlru free
    recycle") -- 20 instances of find each creating 1 million vnodes, while
    total limit is set to 400k.
    
    Time goes down from ~41 to ~35 seconds.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit 23ef25d25d989e7213bc1d3ef32b0f48a9eb2537)
    (cherry picked from commit 5cf1c99d4c425ab196dfa3bafcf3a5f142eab887)
    
    Approved by:    re (gjb)
---
 sys/kern/vfs_subr.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index e7e612254ba2..5e39a149ef36 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1584,6 +1584,9 @@ static void
 vnlru_kick_cond(void)
 {
 
+	if (vnlru_read_freevnodes() > wantfreevnodes)
+		return;
+
 	if (vnlruproc_sig)
 		return;
 	mtx_lock(&vnode_list_mtx);
@@ -1849,9 +1852,8 @@ vn_alloc_hard(struct mount *mp)
 	}
 alloc:
 	mtx_assert(&vnode_list_mtx, MA_NOTOWNED);
-	rnumvnodes = atomic_fetchadd_long(&numvnodes, 1) + 1;
-	if (vnlru_under(rnumvnodes, vlowat))
-		vnlru_kick_cond();
+	atomic_add_long(&numvnodes, 1);
+	vnlru_kick_cond();
 	return (uma_zalloc_smr(vnode_zone, M_WAITOK));
 }