Linux NFS development
 help / color / mirror / Atom feed
From: Dai Ngo <dai.ngo@oracle.com>
To: chuck.lever@oracle.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v2 1/2] NFSD: keep track of the number of courtesy clients in the system
Date: Mon,  4 Jul 2022 12:05:42 -0700	[thread overview]
Message-ID: <1656961543-25210-2-git-send-email-dai.ngo@oracle.com> (raw)
In-Reply-To: <1656961543-25210-1-git-send-email-dai.ngo@oracle.com>

Add counter nfscourtesy_client_count to keep track of the number
of courtesy clients in the system.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
 fs/nfsd/nfs4state.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9409a0dc1b76..a34ffb0d8c77 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -126,11 +126,13 @@ static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;
 static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;
 
 static struct workqueue_struct *laundry_wq;
+static atomic_t courtesy_client_count;
 
 int nfsd4_create_laundry_wq(void)
 {
 	int rc = 0;
 
+	atomic_set(&courtesy_client_count, 0);
 	laundry_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, "nfsd4");
 	if (laundry_wq == NULL)
 		rc = -ENOMEM;
@@ -169,7 +171,8 @@ static __be32 get_client_locked(struct nfs4_client *clp)
 	if (is_client_expired(clp))
 		return nfserr_expired;
 	atomic_inc(&clp->cl_rpc_users);
-	clp->cl_state = NFSD4_ACTIVE;
+	if (xchg(&clp->cl_state, NFSD4_ACTIVE) != NFSD4_ACTIVE)
+		atomic_add_unless(&courtesy_client_count, -1, 0);
 	return nfs_ok;
 }
 
@@ -190,7 +193,8 @@ renew_client_locked(struct nfs4_client *clp)
 
 	list_move_tail(&clp->cl_lru, &nn->client_lru);
 	clp->cl_time = ktime_get_boottime_seconds();
-	clp->cl_state = NFSD4_ACTIVE;
+	if (xchg(&clp->cl_state, NFSD4_ACTIVE) != NFSD4_ACTIVE)
+		atomic_add_unless(&courtesy_client_count, -1, 0);
 }
 
 static void put_client_renew_locked(struct nfs4_client *clp)
@@ -2226,6 +2230,8 @@ __destroy_client(struct nfs4_client *clp)
 	nfsd4_shutdown_callback(clp);
 	if (clp->cl_cb_conn.cb_xprt)
 		svc_xprt_put(clp->cl_cb_conn.cb_xprt);
+	if (clp->cl_state != NFSD4_ACTIVE)
+		atomic_add_unless(&courtesy_client_count, -1, 0);
 	free_client(clp);
 	wake_up_all(&expiry_wq);
 }
@@ -5803,8 +5809,11 @@ nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist,
 			goto exp_client;
 		if (!state_expired(lt, clp->cl_time))
 			break;
-		if (!atomic_read(&clp->cl_rpc_users))
-			clp->cl_state = NFSD4_COURTESY;
+		if (!atomic_read(&clp->cl_rpc_users)) {
+			if (xchg(&clp->cl_state, NFSD4_COURTESY) ==
+							NFSD4_ACTIVE)
+				atomic_inc(&courtesy_client_count);
+		}
 		if (!client_has_state(clp) ||
 				ktime_get_boottime_seconds() >=
 				(clp->cl_time + NFSD_COURTESY_CLIENT_TIMEOUT))
-- 
2.9.5


  reply	other threads:[~2022-07-04 19:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 19:05 [PATCH v2 0/2] NFSD: handling memory shortage problem with Courteous server Dai Ngo
2022-07-04 19:05 ` Dai Ngo [this message]
2022-07-04 19:05 ` [PATCH v2 2/2] NFSD: handling memory shortage condition " Dai Ngo
2022-07-05 14:50 ` [PATCH v2 0/2] NFSD: handling memory shortage problem " Chuck Lever III
2022-07-05 18:42   ` dai.ngo
2022-07-05 19:08     ` Chuck Lever III
2022-07-06 15:46       ` J. Bruce Fields
2022-07-06 16:04         ` Chuck Lever III
2022-07-05 18:48   ` Jeff Layton
2022-07-05 19:15     ` Chuck Lever III
  -- strict thread matches above, loose matches on Subject: below --
2022-08-29  0:47 [PATCH v2 0/2] NFSD: memory shrinker for NFSv4 clients Dai Ngo
2022-08-29  0:47 ` [PATCH v2 1/2] NFSD: keep track of the number of courtesy clients in the system Dai Ngo
2022-08-29 16:48   ` Jeff Layton
2022-08-29 18:24     ` dai.ngo
2022-08-29 18:27       ` Jeff Layton

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=1656961543-25210-2-git-send-email-dai.ngo@oracle.com \
    --to=dai.ngo@oracle.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox