git: 3455c738ac23 - main - nfsd: Reduce callouts rate.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Sun, 09 Jan 2022 18:14:28 UTC
The branch main has been updated by mav:

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

commit 3455c738ac23f723dc516ce5acd02ed24ff9f5df
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-01-09 18:09:29 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-01-09 18:14:23 +0000

    nfsd: Reduce callouts rate.
    
    Before this callouts were scheduled twice a seconds even if nfsd was
    never used.  This reduces the rate to ~1Hz and only after nfsd first
    started.
    
    MFC after:      2 weeks
---
 sys/fs/nfs/nfs_commonport.c     | 25 -------------------------
 sys/fs/nfs/nfs_commonsubs.c     |  1 -
 sys/fs/nfs/nfs_var.h            |  1 -
 sys/fs/nfs/nfsport.h            |  6 ------
 sys/fs/nfsserver/nfs_nfsdport.c | 16 +++++++++++++---
 5 files changed, 13 insertions(+), 36 deletions(-)

diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c
index cd44698343d7..2bb89d8ef264 100644
--- a/sys/fs/nfs/nfs_commonport.c
+++ b/sys/fs/nfs/nfs_commonport.c
@@ -67,12 +67,10 @@ struct nfsstatsv1 nfsstatsv1;
 int nfs_numnfscbd = 0;
 int nfscl_debuglevel = 0;
 char nfsv4_callbackaddr[INET6_ADDRSTRLEN];
-struct callout newnfsd_callout;
 int nfsrv_lughashsize = 100;
 struct mtx nfsrv_dslock_mtx;
 struct nfsdevicehead nfsrv_devidhead;
 volatile int nfsrv_devidcnt = 0;
-void (*nfsd_call_servertimer)(void) = NULL;
 void (*ncl_call_invalcaches)(struct vnode *) = NULL;
 vop_advlock_t *nfs_advlock_p = NULL;
 vop_reclaim_t *nfs_reclaim_p = NULL;
@@ -399,27 +397,6 @@ newnfs_getcred(void)
 	return (cred);
 }
 
-/*
- * Nfs timer routine
- * Call the nfsd's timer function once/sec.
- */
-void
-newnfs_timer(void *arg)
-{
-	static time_t lasttime = 0;
-	/*
-	 * Call the server timer, if set up.
-	 * The argument indicates if it is the next second and therefore
-	 * leases should be checked.
-	 */
-	if (lasttime != NFSD_MONOSEC) {
-		lasttime = NFSD_MONOSEC;
-		if (nfsd_call_servertimer != NULL)
-			(*nfsd_call_servertimer)();
-	}
-	callout_reset(&newnfsd_callout, nfscl_ticks, newnfs_timer, NULL);
-}
-
 /*
  * Sleep for a short period of time unless errval == NFSERR_GRACE, where
  * the sleep should be for 5 seconds.
@@ -895,7 +872,6 @@ nfscommon_modevent(module_t mod, int type, void *data)
 		    MTX_DEF);
 		mtx_init(&nfsrv_dslock_mtx, "nfs4ds", NULL, MTX_DEF);
 		TAILQ_INIT(&nfsrv_devidhead);
-		callout_init(&newnfsd_callout, 1);
 		newnfs_init();
 		nfsd_call_nfscommon = nfssvc_nfscommon;
 		loaded = 1;
@@ -909,7 +885,6 @@ nfscommon_modevent(module_t mod, int type, void *data)
 		}
 
 		nfsd_call_nfscommon = NULL;
-		callout_drain(&newnfsd_callout);
 		/* Clean out the name<-->id cache. */
 		nfsrv_cleanusergroup();
 		/* and get rid of the mutexes */
diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c
index d2124d1f3c0a..cdf3f4830e31 100644
--- a/sys/fs/nfs/nfs_commonsubs.c
+++ b/sys/fs/nfs/nfs_commonsubs.c
@@ -930,7 +930,6 @@ newnfs_init(void)
 	 * Initialize reply list and start timer
 	 */
 	TAILQ_INIT(&nfsd_reqq);
-	NFS_TIMERINIT;
 }
 
 /*
diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h
index b2a44e6e16f2..d41c1853cb1f 100644
--- a/sys/fs/nfs/nfs_var.h
+++ b/sys/fs/nfs/nfs_var.h
@@ -431,7 +431,6 @@ int nfs_catnap(int, int, const char *);
 struct nfsreferral *nfsv4root_getreferral(vnode_t, vnode_t, u_int32_t);
 int nfsvno_pathconf(vnode_t, int, long *, struct ucred *, NFSPROC_T *);
 int nfsrv_atroot(vnode_t, uint64_t *);
-void newnfs_timer(void *);
 int nfs_supportsnfsv4acls(vnode_t);
 
 /* nfs_commonacl.c */
diff --git a/sys/fs/nfs/nfsport.h b/sys/fs/nfs/nfsport.h
index e099cf6e46f0..8ac4bc54a5f2 100644
--- a/sys/fs/nfs/nfsport.h
+++ b/sys/fs/nfs/nfsport.h
@@ -776,12 +776,6 @@ void nfsrvd_rcv(struct socket *, void *, int);
 #define	NFSCNHASH(c, v)
 #define	NCHNAMLEN	9999999
 
-/*
- * These macros are defined to initialize and set the timer routine.
- */
-#define	NFS_TIMERINIT \
-	newnfs_timer(NULL)
-
 /*
  * Handle SMP stuff:
  */
diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index 50d679397f7b..6f9e1326928e 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 
 #include <fs/nfs/nfsport.h>
 #include <security/mac/mac_framework.h>
+#include <sys/callout.h>
 #include <sys/filio.h>
 #include <sys/hash.h>
 #include <sys/sysctl.h>
@@ -60,7 +61,6 @@ extern int nfsrv_useacl;
 extern int newnfs_numnfsd;
 extern struct mount nfsv4root_mnt;
 extern struct nfsrv_stablefirst nfsrv_stablefirst;
-extern void (*nfsd_call_servertimer)(void);
 extern SVCPOOL	*nfsrvd_pool;
 extern struct nfsv4lock nfsd_suspend_lock;
 extern struct nfsclienthashhead *nfsclienthash;
@@ -97,6 +97,7 @@ static char nfsd_master_comm[MAXCOMLEN + 1];
 static struct timeval nfsd_master_start;
 static uint32_t nfsv4_sysid = 0;
 static fhandle_t zerofh;
+struct callout nfsd_callout;
 
 static int nfssvc_srvcall(struct thread *, struct nfssvc_args *,
     struct ucred *);
@@ -3530,6 +3531,14 @@ nfsd_mntinit(void)
 	nfsv4root_mnt.mnt_lazyvnodelistsize = 0;
 }
 
+static void
+nfsd_timer(void *arg)
+{
+
+	nfsrv_servertimer();
+	callout_reset_sbt(&nfsd_callout, SBT_1S, SBT_1S, nfsd_timer, NULL, 0);
+}
+
 /*
  * Get a vnode for a file handle, without checking exports, etc.
  */
@@ -3771,6 +3780,7 @@ nfssvc_nfsd(struct thread *td, struct nfssvc_args *uap)
 			nfsdarg.mdspathlen = 0;
 			nfsdarg.mirrorcnt = 1;
 		}
+		nfsd_timer(NULL);
 		error = nfsrvd_nfsd(td, &nfsdarg);
 		free(nfsdarg.addr, M_TEMP);
 		free(nfsdarg.dnshost, M_TEMP);
@@ -7033,6 +7043,7 @@ nfsd_modevent(module_t mod, int type, void *data)
 		mtx_init(&nfsrv_dontlistlock_mtx, "nfs4dnl", NULL, MTX_DEF);
 		mtx_init(&nfsrv_recalllock_mtx, "nfs4rec", NULL, MTX_DEF);
 		lockinit(&nfsv4root_mnt.mnt_explock, PVFS, "explock", 0, 0);
+		callout_init(&nfsd_callout, 1);
 		nfsrvd_initcache();
 		nfsd_init();
 		NFSD_LOCK();
@@ -7043,7 +7054,6 @@ nfsd_modevent(module_t mod, int type, void *data)
 		vn_deleg_ops.vndeleg_recall = nfsd_recalldelegation;
 		vn_deleg_ops.vndeleg_disable = nfsd_disabledelegation;
 #endif
-		nfsd_call_servertimer = nfsrv_servertimer;
 		nfsd_call_nfsd = nfssvc_nfsd;
 		loaded = 1;
 		break;
@@ -7058,8 +7068,8 @@ nfsd_modevent(module_t mod, int type, void *data)
 		vn_deleg_ops.vndeleg_recall = NULL;
 		vn_deleg_ops.vndeleg_disable = NULL;
 #endif
-		nfsd_call_servertimer = NULL;
 		nfsd_call_nfsd = NULL;
+		callout_drain(&nfsd_callout);
 
 		/* Clean out all NFSv4 state. */
 		nfsrv_throwawayallstate(curthread);