All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: "J. Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 04/19] nfsd: make nfsd_stats.th_cnt atomic_t
Date: Tue, 23 Nov 2021 12:29:35 +1100	[thread overview]
Message-ID: <163763097544.7284.7451205698169106567.stgit@noble.brown> (raw)
In-Reply-To: <163763078330.7284.10141477742275086758.stgit@noble.brown>

This allows us to move the updates for th_cnt out of the mutex.
This is a step towards reducing mutex coverage in nfsd().

Signed-off-by: NeilBrown <neilb@suse.de>
---
 fs/nfsd/nfssvc.c |    6 +++---
 fs/nfsd/stats.c  |    2 +-
 fs/nfsd/stats.h  |    4 +---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 5f605e7e8091..fc5899502a83 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -57,7 +57,7 @@ static __be32			nfsd_init_request(struct svc_rqst *,
 /*
  * nfsd_mutex protects nn->nfsd_serv -- both the pointer itself and the members
  * of the svc_serv struct. In particular, ->sv_nrthreads but also to some
- * extent ->sv_temp_socks and ->sv_permsocks. It also protects nfsdstats.th_cnt
+ * extent ->sv_temp_socks and ->sv_permsocks.
  *
  * If (out side the lock) nn->nfsd_serv is non-NULL, then it must point to a
  * properly initialised 'struct svc_serv' with ->sv_nrthreads > 0 (unless
@@ -955,8 +955,8 @@ nfsd(void *vrqstp)
 	allow_signal(SIGINT);
 	allow_signal(SIGQUIT);
 
-	nfsdstats.th_cnt++;
 	mutex_unlock(&nfsd_mutex);
+	atomic_inc(&nfsdstats.th_cnt);
 
 	set_freezable();
 
@@ -983,8 +983,8 @@ nfsd(void *vrqstp)
 	/* Clear signals before calling svc_exit_thread() */
 	flush_signals(current);
 
+	atomic_dec(&nfsdstats.th_cnt);
 	mutex_lock(&nfsd_mutex);
-	nfsdstats.th_cnt --;
 
 out:
 	/* Take an extra ref so that the svc_put in svc_exit_thread()
diff --git a/fs/nfsd/stats.c b/fs/nfsd/stats.c
index 1d3b881e7382..a8c5a02a84f0 100644
--- a/fs/nfsd/stats.c
+++ b/fs/nfsd/stats.c
@@ -45,7 +45,7 @@ static int nfsd_proc_show(struct seq_file *seq, void *v)
 		   percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_WRITE]));
 
 	/* thread usage: */
-	seq_printf(seq, "th %u 0", nfsdstats.th_cnt);
+	seq_printf(seq, "th %u 0", atomic_read(&nfsdstats.th_cnt));
 
 	/* deprecated thread usage histogram stats */
 	for (i = 0; i < 10; i++)
diff --git a/fs/nfsd/stats.h b/fs/nfsd/stats.h
index 51ecda852e23..9b43dc3d9991 100644
--- a/fs/nfsd/stats.h
+++ b/fs/nfsd/stats.h
@@ -29,11 +29,9 @@ enum {
 struct nfsd_stats {
 	struct percpu_counter	counter[NFSD_STATS_COUNTERS_NUM];
 
-	/* Protected by nfsd_mutex */
-	unsigned int	th_cnt;		/* number of available threads */
+	atomic_t	th_cnt;		/* number of available threads */
 };
 
-
 extern struct nfsd_stats	nfsdstats;
 
 extern struct svc_stat		nfsd_svcstats;



  parent reply	other threads:[~2021-11-23  1:31 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23  1:29 [PATCH 00/19 v2] SUNRPC: clean up server thread management NeilBrown
2021-11-23  1:29 ` [PATCH 15/19] lockd: rename lockd_create_svc() to lockd_get() NeilBrown
2021-11-23  1:29 ` [PATCH 13/19] lockd: move svc_exit_thread() into the thread NeilBrown
2021-11-23  1:29 ` [PATCH 06/19] NFSD: narrow nfsd_mutex protection in nfsd thread NeilBrown
2021-11-23  1:29 ` [PATCH 05/19] SUNRPC: use sv_lock to protect updates to sv_nrthreads NeilBrown
2021-11-23 16:43   ` Chuck Lever III
2021-11-29  0:11     ` NeilBrown
2021-11-23  1:29 ` [PATCH 10/19] lockd: introduce nlmsvc_serv NeilBrown
2021-11-23  1:29 ` [PATCH 14/19] lockd: introduce lockd_put() NeilBrown
2021-11-23  1:29 ` [PATCH 02/19] NFSD: handle error better in write_ports_addfd() NeilBrown
2021-11-23 16:44   ` Chuck Lever III
2021-11-28 23:49     ` NeilBrown
2021-11-23  1:29 ` [PATCH 12/19] lockd: move lockd_start_svc() call into lockd_create_svc() NeilBrown
2021-11-23  1:29 ` [PATCH 16/19] SUNRPC: move the pool_map definitions (back) into svc.c NeilBrown
2021-11-23  1:29 ` [PATCH 07/19] NFSD: Make it possible to use svc_set_num_threads_sync NeilBrown
2021-11-23  1:29 ` NeilBrown [this message]
2021-11-23  1:29 ` [PATCH 01/19] SUNRPC/NFSD: clean up get/put functions NeilBrown
2021-11-23 16:45   ` Chuck Lever III
2021-11-28 23:36     ` NeilBrown
2021-11-23  1:29 ` [PATCH 18/19] lockd: use svc_set_num_threads() for thread start and stop NeilBrown
2021-11-23  1:29 ` [PATCH 09/19] NFSD: simplify locking for network notifier NeilBrown
2021-11-23  1:29 ` [PATCH 11/19] lockd: simplify management of network status notifiers NeilBrown
2021-11-23  1:29 ` [PATCH 08/19] SUNRPC: discard svo_setup and rename svc_set_num_threads_sync() NeilBrown
2021-11-23  1:29 ` [PATCH 19/19] NFS: switch the callback service back to non-pooled NeilBrown
2021-11-23  1:29 ` [PATCH 03/19] SUNRPC: stop using ->sv_nrthreads as a refcount NeilBrown
2021-11-23  1:29 ` [PATCH 17/19] SUNRPC: always treat sv_nrpools==1 as "not pooled" NeilBrown
2021-11-23 14:49 ` [PATCH 00/19 v2] SUNRPC: clean up server thread management J. Bruce Fields
2021-11-24 18:42   ` Chuck Lever III

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=163763097544.7284.7451205698169106567.stgit@noble.brown \
    --to=neilb@suse.de \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.