git: 4e5833d9aeb9 - releng/14.0 - vfs: use vnlru_read_freevnodes for the freevnodes sysctl

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Sun, 24 Sep 2023 21:46:55 UTC
The branch releng/14.0 has been updated by mjg:

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

commit 4e5833d9aeb9c7cb94aa70f40ddc96aecd84bba1
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-09-14 23:53:11 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-09-24 21:45:59 +0000

    vfs: use vnlru_read_freevnodes for the freevnodes sysctl
    
    For a more accurate result.
    
    Approved by:    re (gjb)
    (cherry picked from commit 03bfee175269960c67cab64d761bbb5eb9ac5878)
    (cherry picked from commit 07c081e59232433ce522cfdf37bc4a8afad75330)
---
 sys/kern/vfs_subr.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 84219f3b5c12..823b8005aa4d 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -184,8 +184,6 @@ static struct vnode *vnode_list_reclaim_marker;
  */
 static long wantfreevnodes;
 static long __exclusive_cache_line freevnodes;
-SYSCTL_ULONG(_vfs, OID_AUTO, freevnodes, CTLFLAG_RD,
-    &freevnodes, 0, "Number of \"free\" vnodes");
 static long freevnodes_old;
 
 static counter_u64_t recycles_count;
@@ -350,6 +348,19 @@ SYSCTL_PROC(_kern, KERN_MAXVNODES, maxvnodes,
     CTLTYPE_ULONG | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0, sysctl_maxvnodes,
     "LU", "Target for maximum number of vnodes");
 
+static int
+sysctl_freevnodes(SYSCTL_HANDLER_ARGS)
+{
+	u_long rfreevnodes;
+
+	rfreevnodes = vnlru_read_freevnodes();
+	return (sysctl_handle_long(oidp, &rfreevnodes, 0, req));
+}
+
+SYSCTL_PROC(_vfs, OID_AUTO, freevnodes,
+    CTLTYPE_ULONG | CTLFLAG_MPSAFE | CTLFLAG_RD, NULL, 0, sysctl_freevnodes,
+    "LU", "Number of \"free\" vnodes");
+
 static int
 sysctl_wantfreevnodes(SYSCTL_HANDLER_ARGS)
 {