From: NeilBrown <neilb@suse.de>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Subject: [PATCH 4/6] nfsd: allocate new session-based DRC slots on demand.
Date: Tue, 19 Nov 2024 11:41:31 +1100 [thread overview]
Message-ID: <20241119004928.3245873-5-neilb@suse.de> (raw)
In-Reply-To: <20241119004928.3245873-1-neilb@suse.de>
If a client ever uses the highest available slot for a given session,
attempt to allocate another slot so there is room for the client to use
more slots if wanted. GFP_NOWAIT is used so if there is not plenty of
free memory, failure is expected - which is what we want. It also
allows the allocation while holding a spinlock.
We would expect to stablise with one more slot available than the client
actually uses.
Now that we grow the slot table on demand we can start with a smaller
allocation. Define NFSD_MAX_INITIAL_SLOTS and allocate at most that
many when session is created.
Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/nfsd/nfs4state.c | 32 ++++++++++++++++++++++++++------
fs/nfsd/state.h | 2 ++
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 31ff9f92a895..fb522165b376 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1956,7 +1956,7 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fattrs,
if (!slot || xa_is_err(xa_store(&new->se_slots, 0, slot, GFP_KERNEL)))
goto out_free;
- for (i = 1; i < numslots; i++) {
+ for (i = 1; i < numslots && i < NFSD_MAX_INITIAL_SLOTS; i++) {
slot = kzalloc(slotsize, GFP_KERNEL | __GFP_NORETRY);
if (!slot)
break;
@@ -4248,11 +4248,6 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
slot = xa_load(&session->se_slots, seq->slotid);
dprintk("%s: slotid %d\n", __func__, seq->slotid);
- /* We do not negotiate the number of slots yet, so set the
- * maxslots to the session maxreqs which is used to encode
- * sr_highest_slotid and the sr_target_slot id to maxslots */
- seq->maxslots = session->se_fchannel.maxreqs;
-
trace_nfsd_slot_seqid_sequence(clp, seq, slot);
status = check_slot_seqid(seq->seqid, slot->sl_seqid,
slot->sl_flags & NFSD4_SLOT_INUSE);
@@ -4302,6 +4297,31 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
cstate->session = session;
cstate->clp = clp;
+ /*
+ * If the client ever uses the highest available slot,
+ * gently try to allocate another one.
+ */
+ if (seq->slotid == session->se_fchannel.maxreqs - 1 &&
+ session->se_fchannel.maxreqs < NFSD_MAX_SLOTS_PER_SESSION) {
+ int s = session->se_fchannel.maxreqs;
+
+ /*
+ * GFP_NOWAIT is a low-priority non-blocking allocation
+ * which can be used under client_lock and only succeeds
+ * if there is plenty of memory.
+ * Use GFP_ATOMIC which is higher priority for xa_store()
+ * so we are less likely to waste the effort of the first
+ * allocation.
+ */
+ slot = kzalloc(slot_bytes(&session->se_fchannel), GFP_NOWAIT);
+ if (slot && !xa_is_err(xa_store(&session->se_slots, s, slot,
+ GFP_ATOMIC)))
+ session->se_fchannel.maxreqs += 1;
+ else
+ kfree(slot);
+ }
+ seq->maxslots = session->se_fchannel.maxreqs;
+
out:
switch (clp->cl_cb_state) {
case NFSD4_CB_DOWN:
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index e97626916a68..a14a823670e9 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -249,6 +249,8 @@ static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
* get good throughput on high-latency servers.
*/
#define NFSD_MAX_SLOTS_PER_SESSION 2048
+/* Maximum number of slots per session to allocate for CREATE_SESSION */
+#define NFSD_MAX_INITIAL_SLOTS 32
/* Maximum session per slot cache size */
#define NFSD_SLOT_CACHE_SIZE 2048
/* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */
--
2.47.0
next prev parent reply other threads:[~2024-11-19 0:50 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 0:41 [PATCH 0/6 RFC v2] nfsd: allocate/free session-based DRC slots on demand NeilBrown
2024-11-19 0:41 ` [PATCH 1/6] nfsd: use an xarray to store v4.1 session slots NeilBrown
2024-11-19 0:41 ` [PATCH 2/6] nfsd: remove artificial limits on the session-based DRC NeilBrown
2024-11-19 0:41 ` [PATCH 3/6] nfsd: add session slot count to /proc/fs/nfsd/clients/*/info NeilBrown
2024-11-19 19:14 ` Chuck Lever
2024-11-19 22:22 ` NeilBrown
2024-11-20 0:21 ` Chuck Lever
2024-11-19 19:21 ` Chuck Lever
2024-11-19 22:24 ` NeilBrown
2024-11-20 0:25 ` Chuck Lever
2024-11-21 21:03 ` NeilBrown
2024-11-21 21:24 ` Chuck Lever III
2024-11-19 0:41 ` NeilBrown [this message]
2024-11-19 19:20 ` [PATCH 4/6] nfsd: allocate new session-based DRC slots on demand Chuck Lever
2024-11-19 22:27 ` NeilBrown
2024-11-20 0:32 ` Chuck Lever
2024-11-21 21:20 ` NeilBrown
2024-11-19 19:34 ` Jeff Layton
2024-11-19 0:41 ` [PATCH 5/6] nfsd: add support for freeing unused session-DRC slots NeilBrown
2024-11-19 19:25 ` Chuck Lever
2024-11-19 22:35 ` NeilBrown
2024-11-20 1:27 ` Chuck Lever
2024-11-21 21:47 ` NeilBrown
2024-11-21 22:29 ` Chuck Lever III
2024-12-02 16:11 ` Chuck Lever III
2024-12-03 4:28 ` NeilBrown
2024-12-03 14:40 ` Chuck Lever III
2024-11-19 19:48 ` Jeff Layton
2024-11-19 0:41 ` [PATCH 6/6] nfsd: add shrinker to reduce number of slots allocated per session NeilBrown
2024-11-19 19:28 ` Chuck Lever
2024-11-19 22:41 ` NeilBrown
2024-11-19 21:17 ` Jeff Layton
2024-11-19 22:47 ` NeilBrown
2024-11-19 21:31 ` [PATCH 0/6 RFC v2] nfsd: allocate/free session-based DRC slots on demand Jeff Layton
2024-11-19 22:52 ` NeilBrown
-- strict thread matches above, loose matches on Subject: below --
2024-12-06 0:43 [PATCH 0/6 v3] " NeilBrown
2024-12-06 0:43 ` [PATCH 4/6] nfsd: allocate new " NeilBrown
2024-12-06 1:04 ` Jeff Layton
2024-12-06 1:43 ` NeilBrown
2024-12-06 13:49 ` Jeff Layton
2024-12-06 20:51 ` Chuck Lever
2024-12-08 4:52 ` NeilBrown
2024-12-08 22:43 [PATCH 0/6 v4] nfsd: allocate/free " NeilBrown
2024-12-08 22:43 ` [PATCH 4/6] nfsd: allocate new " NeilBrown
2024-12-11 21:47 [PATCH 0/6 v5] nfsd: allocate/free " NeilBrown
2024-12-11 21:47 ` [PATCH 4/6] nfsd: allocate new " NeilBrown
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=20241119004928.3245873-5-neilb@suse.de \
--to=neilb@suse.de \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/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