Skip to content

Commit 3a5be9e

Browse files
committed
sunrpc: skip svc_xprt_enqueue when no work is pending
svc_reserve() and svc_xprt_release_slot() call svc_xprt_enqueue() after modifying xpt_reserved or xpt_nr_rqsts. The purpose is to re-dispatch the transport when write-space or a slot becomes available. However, when neither XPT_DATA nor XPT_DEFERRED is set, no thread can make progress on the transport and the enqueue accomplishes nothing. Trace data from a 256KB NFSv3 WRITE workload over RDMA shows 11.2 svc_xprt_enqueue() calls per RPC. Of these, 6.9 per RPC lack XPT_DATA and exit svc_xprt_ready() immediately after executing the smp_rmb(), READ_ONCE(), and tracepoint. svc_reserve() and svc_xprt_release_slot() account for roughly five of these per RPC. A new helper, svc_xprt_resource_released(), checks XPT_DATA | XPT_DEFERRED before calling svc_xprt_enqueue(). The existing smp_wmb() barriers are upgraded to smp_mb() to ensure the flags check observes a concurrent producer's set_bit(XPT_DATA). Each producer (svc_rdma_wc_receive, etc.) both sets XPT_DATA and calls svc_xprt_enqueue(), so even if the check reads a stale value, the producer's own enqueue provides a fallback path. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 1cd8fad commit 3a5be9e

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

net/sunrpc/svc_xprt.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,28 @@ static bool svc_xprt_reserve_slot(struct svc_rqst *rqstp, struct svc_xprt *xprt)
425425
return true;
426426
}
427427

428+
/*
429+
* After a caller releases write-space or a request slot,
430+
* re-enqueue the transport only when there is pending
431+
* work that a thread could act on. The smp_mb() pairs
432+
* with the smp_rmb() in svc_xprt_ready() and orders the
433+
* preceding counter update before the flags read so a
434+
* concurrent set_bit(XPT_DATA) is visible here.
435+
*/
436+
static void svc_xprt_resource_released(struct svc_xprt *xprt)
437+
{
438+
smp_mb();
439+
if (READ_ONCE(xprt->xpt_flags) &
440+
(BIT(XPT_DATA) | BIT(XPT_DEFERRED)))
441+
svc_xprt_enqueue(xprt);
442+
}
443+
428444
static void svc_xprt_release_slot(struct svc_rqst *rqstp)
429445
{
430446
struct svc_xprt *xprt = rqstp->rq_xprt;
431447
if (test_and_clear_bit(RQ_DATA, &rqstp->rq_flags)) {
432448
atomic_dec(&xprt->xpt_nr_rqsts);
433-
smp_wmb(); /* See smp_rmb() in svc_xprt_ready() */
434-
svc_xprt_enqueue(xprt);
449+
svc_xprt_resource_released(xprt);
435450
}
436451
}
437452

@@ -525,10 +540,10 @@ void svc_reserve(struct svc_rqst *rqstp, int space)
525540
space += rqstp->rq_res.head[0].iov_len;
526541

527542
if (xprt && space < rqstp->rq_reserved) {
528-
atomic_sub((rqstp->rq_reserved - space), &xprt->xpt_reserved);
543+
atomic_sub((rqstp->rq_reserved - space),
544+
&xprt->xpt_reserved);
529545
rqstp->rq_reserved = space;
530-
smp_wmb(); /* See smp_rmb() in svc_xprt_ready() */
531-
svc_xprt_enqueue(xprt);
546+
svc_xprt_resource_released(xprt);
532547
}
533548
}
534549
EXPORT_SYMBOL_GPL(svc_reserve);

0 commit comments

Comments
 (0)