Skip to content

Commit 583772e

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: allow for up to 32 callback session slots
nfsd currently only uses a single slot in the callback channel, which is proving to be a bottleneck in some cases. Widen the callback channel to a max of 32 slots (subject to the client's target_maxreqs value). Change the cb_holds_slot boolean to an integer that tracks the current slot number (with -1 meaning "unassigned"). Move the callback slot tracking info into the session. Add a new u32 that acts as a bitmap to track which slots are in use, and a u32 to track the latest callback target_slotid that the client reports. To protect the new fields, add a new per-session spinlock (the se_lock). Fix nfsd41_cb_get_slot to always search for the lowest slotid (using ffs()). Finally, convert the session->se_cb_seq_nr field into an array of ints and add the necessary handling to ensure that the seqids get reset when the slot table grows after shrinking. Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent c840b8e commit 583772e

File tree

4 files changed

+109
-40
lines changed

4 files changed

+109
-40
lines changed

fs/nfsd/nfs4callback.c

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr,
374374
hdr->nops++;
375375
}
376376

377+
static u32 highest_slotid(struct nfsd4_session *ses)
378+
{
379+
u32 idx;
380+
381+
spin_lock(&ses->se_lock);
382+
idx = fls(~ses->se_cb_slot_avail);
383+
if (idx > 0)
384+
--idx;
385+
idx = max(idx, ses->se_cb_highest_slot);
386+
spin_unlock(&ses->se_lock);
387+
return idx;
388+
}
389+
377390
/*
378391
* CB_SEQUENCE4args
379392
*
@@ -400,15 +413,40 @@ static void encode_cb_sequence4args(struct xdr_stream *xdr,
400413
encode_sessionid4(xdr, session);
401414

402415
p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4 + 4);
403-
*p++ = cpu_to_be32(session->se_cb_seq_nr); /* csa_sequenceid */
404-
*p++ = xdr_zero; /* csa_slotid */
405-
*p++ = xdr_zero; /* csa_highest_slotid */
416+
*p++ = cpu_to_be32(session->se_cb_seq_nr[cb->cb_held_slot]); /* csa_sequenceid */
417+
*p++ = cpu_to_be32(cb->cb_held_slot); /* csa_slotid */
418+
*p++ = cpu_to_be32(highest_slotid(session)); /* csa_highest_slotid */
406419
*p++ = xdr_zero; /* csa_cachethis */
407420
xdr_encode_empty_array(p); /* csa_referring_call_lists */
408421

409422
hdr->nops++;
410423
}
411424

425+
static void update_cb_slot_table(struct nfsd4_session *ses, u32 target)
426+
{
427+
/* No need to do anything if nothing changed */
428+
if (likely(target == READ_ONCE(ses->se_cb_highest_slot)))
429+
return;
430+
431+
spin_lock(&ses->se_lock);
432+
if (target > ses->se_cb_highest_slot) {
433+
int i;
434+
435+
target = min(target, NFSD_BC_SLOT_TABLE_SIZE - 1);
436+
437+
/*
438+
* Growing the slot table. Reset any new sequences to 1.
439+
*
440+
* NB: There is some debate about whether the RFC requires this,
441+
* but the Linux client expects it.
442+
*/
443+
for (i = ses->se_cb_highest_slot + 1; i <= target; ++i)
444+
ses->se_cb_seq_nr[i] = 1;
445+
}
446+
ses->se_cb_highest_slot = target;
447+
spin_unlock(&ses->se_lock);
448+
}
449+
412450
/*
413451
* CB_SEQUENCE4resok
414452
*
@@ -436,7 +474,7 @@ static int decode_cb_sequence4resok(struct xdr_stream *xdr,
436474
struct nfsd4_session *session = cb->cb_clp->cl_cb_session;
437475
int status = -ESERVERFAULT;
438476
__be32 *p;
439-
u32 dummy;
477+
u32 seqid, slotid, target;
440478

441479
/*
442480
* If the server returns different values for sessionID, slotID or
@@ -452,21 +490,22 @@ static int decode_cb_sequence4resok(struct xdr_stream *xdr,
452490
}
453491
p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN);
454492

455-
dummy = be32_to_cpup(p++);
456-
if (dummy != session->se_cb_seq_nr) {
493+
seqid = be32_to_cpup(p++);
494+
if (seqid != session->se_cb_seq_nr[cb->cb_held_slot]) {
457495
dprintk("NFS: %s Invalid sequence number\n", __func__);
458496
goto out;
459497
}
460498

461-
dummy = be32_to_cpup(p++);
462-
if (dummy != 0) {
499+
slotid = be32_to_cpup(p++);
500+
if (slotid != cb->cb_held_slot) {
463501
dprintk("NFS: %s Invalid slotid\n", __func__);
464502
goto out;
465503
}
466504

467-
/*
468-
* FIXME: process highest slotid and target highest slotid
469-
*/
505+
p++; // ignore current highest slot value
506+
507+
target = be32_to_cpup(p++);
508+
update_cb_slot_table(session, target);
470509
status = 0;
471510
out:
472511
cb->cb_seq_status = status;
@@ -1167,6 +1206,22 @@ void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
11671206
spin_unlock(&clp->cl_lock);
11681207
}
11691208

1209+
static int grab_slot(struct nfsd4_session *ses)
1210+
{
1211+
int idx;
1212+
1213+
spin_lock(&ses->se_lock);
1214+
idx = ffs(ses->se_cb_slot_avail) - 1;
1215+
if (idx < 0 || idx > ses->se_cb_highest_slot) {
1216+
spin_unlock(&ses->se_lock);
1217+
return -1;
1218+
}
1219+
/* clear the bit for the slot */
1220+
ses->se_cb_slot_avail &= ~BIT(idx);
1221+
spin_unlock(&ses->se_lock);
1222+
return idx;
1223+
}
1224+
11701225
/*
11711226
* There's currently a single callback channel slot.
11721227
* If the slot is available, then mark it busy. Otherwise, set the
@@ -1175,28 +1230,32 @@ void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
11751230
static bool nfsd41_cb_get_slot(struct nfsd4_callback *cb, struct rpc_task *task)
11761231
{
11771232
struct nfs4_client *clp = cb->cb_clp;
1233+
struct nfsd4_session *ses = clp->cl_cb_session;
11781234

1179-
if (!cb->cb_holds_slot &&
1180-
test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
1235+
if (cb->cb_held_slot >= 0)
1236+
return true;
1237+
cb->cb_held_slot = grab_slot(ses);
1238+
if (cb->cb_held_slot < 0) {
11811239
rpc_sleep_on(&clp->cl_cb_waitq, task, NULL);
11821240
/* Race breaker */
1183-
if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
1184-
dprintk("%s slot is busy\n", __func__);
1241+
cb->cb_held_slot = grab_slot(ses);
1242+
if (cb->cb_held_slot < 0)
11851243
return false;
1186-
}
11871244
rpc_wake_up_queued_task(&clp->cl_cb_waitq, task);
11881245
}
1189-
cb->cb_holds_slot = true;
11901246
return true;
11911247
}
11921248

11931249
static void nfsd41_cb_release_slot(struct nfsd4_callback *cb)
11941250
{
11951251
struct nfs4_client *clp = cb->cb_clp;
1252+
struct nfsd4_session *ses = clp->cl_cb_session;
11961253

1197-
if (cb->cb_holds_slot) {
1198-
cb->cb_holds_slot = false;
1199-
clear_bit(0, &clp->cl_cb_slot_busy);
1254+
if (cb->cb_held_slot >= 0) {
1255+
spin_lock(&ses->se_lock);
1256+
ses->se_cb_slot_avail |= BIT(cb->cb_held_slot);
1257+
spin_unlock(&ses->se_lock);
1258+
cb->cb_held_slot = -1;
12001259
rpc_wake_up_next(&clp->cl_cb_waitq);
12011260
}
12021261
}
@@ -1213,8 +1272,8 @@ static void nfsd41_destroy_cb(struct nfsd4_callback *cb)
12131272
}
12141273

12151274
/*
1216-
* TODO: cb_sequence should support referring call lists, cachethis, multiple
1217-
* slots, and mark callback channel down on communication errors.
1275+
* TODO: cb_sequence should support referring call lists, cachethis,
1276+
* and mark callback channel down on communication errors.
12181277
*/
12191278
static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata)
12201279
{
@@ -1256,7 +1315,7 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback
12561315
return true;
12571316
}
12581317

1259-
if (!cb->cb_holds_slot)
1318+
if (cb->cb_held_slot < 0)
12601319
goto need_restart;
12611320

12621321
/* This is the operation status code for CB_SEQUENCE */
@@ -1270,10 +1329,10 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback
12701329
* If CB_SEQUENCE returns an error, then the state of the slot
12711330
* (sequence ID, cached reply) MUST NOT change.
12721331
*/
1273-
++session->se_cb_seq_nr;
1332+
++session->se_cb_seq_nr[cb->cb_held_slot];
12741333
break;
12751334
case -ESERVERFAULT:
1276-
++session->se_cb_seq_nr;
1335+
++session->se_cb_seq_nr[cb->cb_held_slot];
12771336
nfsd4_mark_cb_fault(cb->cb_clp);
12781337
ret = false;
12791338
break;
@@ -1299,17 +1358,16 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback
12991358
case -NFS4ERR_BADSLOT:
13001359
goto retry_nowait;
13011360
case -NFS4ERR_SEQ_MISORDERED:
1302-
if (session->se_cb_seq_nr != 1) {
1303-
session->se_cb_seq_nr = 1;
1361+
if (session->se_cb_seq_nr[cb->cb_held_slot] != 1) {
1362+
session->se_cb_seq_nr[cb->cb_held_slot] = 1;
13041363
goto retry_nowait;
13051364
}
13061365
break;
13071366
default:
13081367
nfsd4_mark_cb_fault(cb->cb_clp);
13091368
}
1310-
nfsd41_cb_release_slot(cb);
1311-
13121369
trace_nfsd_cb_free_slot(task, cb);
1370+
nfsd41_cb_release_slot(cb);
13131371

13141372
if (RPC_SIGNALLED(task))
13151373
goto need_restart;
@@ -1529,7 +1587,7 @@ void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
15291587
INIT_WORK(&cb->cb_work, nfsd4_run_cb_work);
15301588
cb->cb_status = 0;
15311589
cb->cb_need_restart = false;
1532-
cb->cb_holds_slot = false;
1590+
cb->cb_held_slot = -1;
15331591
}
15341592

15351593
/**

fs/nfsd/nfs4state.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,10 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fattrs,
20102010
}
20112011

20122012
memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs));
2013+
new->se_cb_slot_avail = ~0U;
2014+
new->se_cb_highest_slot = min(battrs->maxreqs - 1,
2015+
NFSD_BC_SLOT_TABLE_SIZE - 1);
2016+
spin_lock_init(&new->se_lock);
20132017
return new;
20142018
out_free:
20152019
while (i--)
@@ -2140,11 +2144,14 @@ static void init_session(struct svc_rqst *rqstp, struct nfsd4_session *new, stru
21402144

21412145
INIT_LIST_HEAD(&new->se_conns);
21422146

2143-
new->se_cb_seq_nr = 1;
2147+
atomic_set(&new->se_ref, 0);
21442148
new->se_dead = false;
21452149
new->se_cb_prog = cses->callback_prog;
21462150
new->se_cb_sec = cses->cb_sec;
2147-
atomic_set(&new->se_ref, 0);
2151+
2152+
for (idx = 0; idx < NFSD_BC_SLOT_TABLE_SIZE; ++idx)
2153+
new->se_cb_seq_nr[idx] = 1;
2154+
21482155
idx = hash_sessionid(&new->se_sessionid);
21492156
list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]);
21502157
spin_lock(&clp->cl_lock);
@@ -3153,7 +3160,6 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
31533160
kref_init(&clp->cl_nfsdfs.cl_ref);
31543161
nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL);
31553162
clp->cl_time = ktime_get_boottime_seconds();
3156-
clear_bit(0, &clp->cl_cb_slot_busy);
31573163
copy_verf(clp, verf);
31583164
memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage));
31593165
clp->cl_cb_session = NULL;
@@ -3935,6 +3941,8 @@ nfsd4_create_session(struct svc_rqst *rqstp,
39353941
cr_ses->flags &= ~SESSION4_PERSIST;
39363942
/* Upshifting from TCP to RDMA is not supported */
39373943
cr_ses->flags &= ~SESSION4_RDMA;
3944+
/* Report the correct number of backchannel slots */
3945+
cr_ses->back_channel.maxreqs = new->se_cb_highest_slot + 1;
39383946

39393947
init_session(rqstp, new, conf, cr_ses);
39403948
nfsd4_get_session_locked(new);

fs/nfsd/state.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ struct nfsd4_callback {
7171
struct work_struct cb_work;
7272
int cb_seq_status;
7373
int cb_status;
74+
int cb_held_slot;
7475
bool cb_need_restart;
75-
bool cb_holds_slot;
7676
};
7777

7878
struct nfsd4_callback_ops {
@@ -304,13 +304,20 @@ struct nfsd4_conn {
304304
unsigned char cn_flags;
305305
};
306306

307+
/* Maximum number of slots that nfsd will use in the backchannel */
308+
#define NFSD_BC_SLOT_TABLE_SIZE (sizeof(u32) * 8)
309+
307310
/*
308311
* Representation of a v4.1+ session. These are refcounted in a similar fashion
309312
* to the nfs4_client. References are only taken when the server is actively
310313
* working on the object (primarily during the processing of compounds).
311314
*/
312315
struct nfsd4_session {
313316
atomic_t se_ref;
317+
spinlock_t se_lock;
318+
u32 se_cb_slot_avail; /* bitmap of available slots */
319+
u32 se_cb_highest_slot; /* highest slot client wants */
320+
u32 se_cb_prog;
314321
bool se_dead;
315322
struct list_head se_hash; /* hash by sessionid */
316323
struct list_head se_perclnt;
@@ -319,8 +326,7 @@ struct nfsd4_session {
319326
struct nfsd4_channel_attrs se_fchannel;
320327
struct nfsd4_cb_sec se_cb_sec;
321328
struct list_head se_conns;
322-
u32 se_cb_prog;
323-
u32 se_cb_seq_nr;
329+
u32 se_cb_seq_nr[NFSD_BC_SLOT_TABLE_SIZE];
324330
struct nfsd4_slot *se_slots[]; /* forward channel slots */
325331
};
326332

@@ -454,9 +460,6 @@ struct nfs4_client {
454460
*/
455461
struct dentry *cl_nfsd_info_dentry;
456462

457-
/* for nfs41 callbacks */
458-
/* We currently support a single back channel with a single slot */
459-
unsigned long cl_cb_slot_busy;
460463
struct rpc_wait_queue cl_cb_waitq; /* backchannel callers may */
461464
/* wait here for slots */
462465
struct net *net;

fs/nfsd/trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ TRACE_EVENT(nfsd_cb_free_slot,
16971697
__entry->cl_id = sid->clientid.cl_id;
16981698
__entry->seqno = sid->sequence;
16991699
__entry->reserved = sid->reserved;
1700-
__entry->slot_seqno = session->se_cb_seq_nr;
1700+
__entry->slot_seqno = session->se_cb_seq_nr[cb->cb_held_slot];
17011701
),
17021702
TP_printk(SUNRPC_TRACE_TASK_SPECIFIER
17031703
" sessionid=%08x:%08x:%08x:%08x new slot seqno=%u",

0 commit comments

Comments
 (0)