Skip to content

Commit 0a5d7be

Browse files
committed
sunrpc: skip svc_xprt_enqueue in svc_xprt_received when idle
svc_xprt_received() unconditionally calls svc_xprt_enqueue() after clearing XPT_BUSY. When no work flags are pending, the enqueue traverses svc_xprt_ready() -- executing an smp_rmb(), READ_ONCE(), and tracepoint -- before returning false. Trace data from a 256KB NFSv3 workload over RDMA shows 85% of svc_xprt_received() invocations reach svc_xprt_enqueue() with no pending work flags. In the WRITE phase, 167,335 of 196,420 calls find no work; in the READ phase, 97,165 of 98,276. Each unnecessary call executes a memory barrier, a flags read, and (when tracing is active) fires the svc_xprt_enqueue tracepoint. Add a flags pre-check between clear_bit(XPT_BUSY) and svc_xprt_enqueue(). Both the clear and the subsequent READ_ONCE operate on the same xpt_flags word, so cache-line serialization of the atomic bitops ensures the read observes any flag set by a concurrent producer before the line was acquired for the clear. If a producer's set_bit occurs after the clear_bit, that producer's own svc_xprt_enqueue() call observes !XPT_BUSY and dispatches the transport. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 3a5be9e commit 0a5d7be

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

net/sunrpc/svc_xprt.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,19 @@ void svc_xprt_received(struct svc_xprt *xprt)
234234
svc_xprt_get(xprt);
235235
smp_mb__before_atomic();
236236
clear_bit(XPT_BUSY, &xprt->xpt_flags);
237-
svc_xprt_enqueue(xprt);
237+
238+
/*
239+
* Skip the enqueue when no actionable flags are set.
240+
* Each producer both sets its flag (XPT_DATA, XPT_CLOSE,
241+
* etc.) and calls svc_xprt_enqueue(); if a set_bit races
242+
* with this check, the producer's own enqueue observes
243+
* !XPT_BUSY and dispatches the transport.
244+
*/
245+
if (READ_ONCE(xprt->xpt_flags) &
246+
(BIT(XPT_CONN) | BIT(XPT_CLOSE) | BIT(XPT_HANDSHAKE) |
247+
BIT(XPT_DATA) | BIT(XPT_DEFERRED)))
248+
svc_xprt_enqueue(xprt);
249+
238250
svc_xprt_put(xprt);
239251
}
240252
EXPORT_SYMBOL_GPL(svc_xprt_received);

0 commit comments

Comments
 (0)