SUNRPC/NFS: limit transport disconnects when cancelling flexfiles I/O
Subsystems (4)
v2 cover SUNRPC/NFS: limit transport disconnects when cancelling flexfiles I/O
From: Tim Menninger <[email protected]>
This series narrows the transport disconnects performed when flexfiles cancels I/O for a recalled or revoked layout segment.
Today ff_layout_cancel_io() first cancels matching RPC tasks and then calls rpc_clnt_disconnect() if any tasks matched. rpc_clnt_disconnect() operates on the entire rpc_clnt, so for a data server client using multiple transports it disconnects transports that may have had no I/O associated with the affected layout segment.
I encountered this while testing pNFS over RPC/RDMA during data server recovery. Restarting the NFS service on a data server while sustained direct-read I/O was active could cause repeated reconnect activity and a large throughput drop. The client-wide disconnect from ff_layout_cancel_io() amplified the disruption by tearing down otherwise unaffected transports.
The first patch adds a SUNRPC helper that combines task cancellation with request-scoped conditional disconnects. Matching tasks are cancelled as before. A subsequent transport-queue pass marks matching requests belonging to the same rpc_clnt that remain on the transmit or receive queues so that, when released, xprt_conditional_disconnect() is called using the request's saved connection cookie.
The disconnect state is stored on struct rpc_rqst rather than struct rpc_task. A task can release one request and later acquire another, so a task-scoped indication could otherwise be consumed by a successor request and applied to the wrong transport generation.
The request-marking pass also preserves the rpc_clnt selection used by rpc_cancel_tasks(). An rpc_xprt may be shared by multiple rpc_clnt instances, so requests belonging to other clients sharing the same transport are not marked.
The second patch switches flexfiles to the new helper, preserving its I/O cancellation behavior while avoiding client-wide transport disconnects.
Testing:
The code in this series does not depend on:
https://lore.kernel.org/all/[email protected]/
However, I used that change while collecting the results below because, without it, the client enters the earlier recovery livelock before the transport-disconnect behavior can be observed cleanly.
As a control experiment, I also tested skipping the ff_layout_cancel_io() task-cancellation and client-disconnect path entirely for RPC/RDMA. Doing so eliminates the reconnect pathology. This shows that the pathology depends on the cancellation/disconnect path introduced by commit b739a5bd9d9f ("NFSv4/flexfiles: Cancel I/O if the layout is recalled or revoked"), but simply opting RPC/RDMA out of that behavior would also remove the cancellation that is intended to drain I/O associated with a recalled or revoked layout segment.
This series instead preserves that cancellation while limiting transport disconnects to matching requests that remain in flight.
I have repeated the data-server restart test many times and the behavior is consistent. The counters below are intentionally collected after the restart event, once throughput has partially recovered and the client has entered the post-recovery state in which it remains until the workload completes.
This distinction matters because some transport activity during the data-server restart itself is expected. The problem addressed here is the continued reconnect activity after that transition has completed:
once recovery has settled, the client should not continue cycling otherwise healthy RPC/RDMA connections.
Over a 30-second post-recovery sampling window, this series reduces sunrpc events from 4,526 to 289, a roughly
16-fold reduction. RPC/RDMA disconnect and connect events fall by about 6.6-fold. During the same interval, read throughput improves from approximately 0.4-1.1 GB/s to 1.9-2.2 GB/s.
Before (throughput: approximately 0.4-1.1 GB/s):
Performance counter stats for 'system wide':
4,526 sunrpc:xprt_disconnect_force
1,911 rpcrdma:xprtrdma_disconnect
1,909 rpcrdma:xprtrdma_connect
30.021267692 seconds time elapsed
After (throughput: approximately 1.9-2.2 GB/s):
Performance counter stats for 'system wide':
289 sunrpc:xprt_disconnect_force
289 rpcrdma:xprtrdma_disconnect
291 rpcrdma:xprtrdma_connect
30.080790959 seconds time elapsed
---
Changes in v2:
- Rebase onto v7.4-rc1.
- Adapt to the device-ID-aware ff_layout_cancel_io() interface, preserving device-node reference cleanup.
- No functional changes to the SUNRPC implementation.
v1: https://lore.kernel.org/all/[email protected]/
Tim Menninger (2):
SUNRPC: add request-scoped disconnects when cancelling tasks NFSv4/flexfiles: limit transport disconnects when cancelling I/O
fs/nfs/flexfilelayout/flexfilelayout.c | 7 +- include/linux/sunrpc/sched.h | 4 ++ include/linux/sunrpc/xprt.h | 5 ++ net/sunrpc/clnt.c | 94 +++++++++++++++++++++----- net/sunrpc/sunrpc.h | 5 ++ net/sunrpc/xprt.c | 76 +++++++++++++++++++++ 6 files changed, 170 insertions(+), 21 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/2 SUNRPC: add request-scoped disconnects when cancelling tasks
From: Tim Menninger <[email protected]>
rpc_cancel_tasks() allows callers to cancel a selected set of RPC tasks, but callers that also need to tear down the connection currently have to disconnect at the rpc_clnt level.
That is broader than necessary for clients with multiple transports. A cancelled request is associated with a specific rpc_xprt and records the connection generation on which it was transmitted in rq_connect_cookie.
Add rpc_cancel_tasks_and_disconnect() to cancel matching tasks and mark matching requests that remain on the transport transmit or receive queues for conditional transport disconnect when the request is released.
Store the disconnect indication in struct rpc_rqst rather than struct rpc_task. An RPC task can release one request and later acquire another, so task-scoped state could otherwise be consumed by a successor request and disconnect the wrong transport generation.
After cancelling matching tasks, walk the client's transports and mark matching requests belonging to that client that remain on the transmit or receive queues. An rpc_xprt may be shared by multiple rpc_clnt instances, so requests belonging to other clients are left untouched.
When a marked request is released, use xprt_conditional_disconnect() with its saved rq_connect_cookie. This disconnects the transport only if it is still using the same connection generation on which the request was sent, and leaves a replacement connection untouched.
Requests that were never transmitted do not require a disconnect.
--- include/linux/sunrpc/sched.h | 4 ++ include/linux/sunrpc/xprt.h | 5 ++ net/sunrpc/clnt.c | 94 +++++++++++++++++++++++++++++------- net/sunrpc/sunrpc.h | 5 ++ net/sunrpc/xprt.c | 76 +++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+), 17 deletions(-)
include/linux/sunrpc/sched.h +4 -0
@@ -230,6 +230,10 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error,bool (*fnmatch)(const struct rpc_task *,const void *), const void *data); +unsigned long rpc_cancel_tasks_and_disconnect (struct rpc_clnt *clnt,int error, +bool (*fnmatch)(const struct rpc_task *, +const void *), +const void *data);void rpc_execute (struct rpc_task *);void rpc_init_priority_wait_queue (struct rpc_wait_queue *,const char *);void rpc_init_wait_queue (struct rpc_wait_queue *,const char *);
include/linux/sunrpc/xprt.h +5 -0
@@ -112,6 +112,11 @@ struct rpc_rqst {ktime_t rq_xtime;/* transmit time stamp */ int rq_ntrans; +bool rq_disconnect_on_release; +/* +* protected by rq_xprt->queue_lock +* while the request is active +*/ #if defined(CONFIG_SUNRPC_BACKCHANNEL )struct lwq_node rq_bc_list;/* Callback service list */
net/sunrpc/clnt.c +77 -17
116 lines not on this page · raw message
net/sunrpc/sunrpc.h +5 -0
@@ -43,4 +43,9 @@ void rpc_clients_notifier_unregister(void);void auth_domain_cleanup (void );void svc_sock_update_bufs (struct svc_serv *serv);enum svc_auth_status svc_authenticate (struct svc_rqst *rqstp); +void xprt_mark_matching_reqs_disconnect_on_release (struct rpc_xprt *xprt, +const struct rpc_clnt *clnt, +bool (*fnmatch)(const struct rpc_task *, +const void *), +const void *data);#endif /* _NET_SUNRPC_SUNRPC_H */
net/sunrpc/xprt.c +76 -0
112 lines not on this page · raw message
Signature · 1 line
2.53.0
Trond Myklebust
maintainerRe: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks
Quoted 43 lines · On Thu, 2026-11-05 at 02:02 +0000, [email protected] wrote:
From: Tim Menninger <[email protected]>
rpc_cancel_tasks()allows callers to cancel a selected set of RPC tasks,
but callers that also need to tear down the connection currently have to
disconnect at therpc_clntlevel.That is broader than necessary for clients with multiple transports. A
cancelled request is associated with a specificrpc_xprtand records the
connection generation on which it was transmitted inrq_connect_cookie.Add
rpc_cancel_tasks_and_disconnect()to cancel matching tasks and mark
matching requests that remain on the transport transmit or receive queues
for conditional transport disconnect when the request is released.Store the disconnect indication in struct
rpc_rqstrather than structrpc_task. An RPC task can release one request and later acquire another,
so task-scoped state could otherwise be consumed by a successor request
and disconnect the wrong transport generation.After cancelling matching tasks, walk the client's transports and mark
matching requests belonging to that client that remain on the transmit
or receive queues. Anrpc_xprtmay be shared by multiplerpc_clntinstances, so requests belonging to other clients are left untouched.When a marked request is released, use
xprt_conditional_disconnect()with
its savedrq_connect_cookie. This disconnects the transport only if it is
still using the same connection generation on which the request was sent,
and leaves a replacement connection untouched.
Quoted 2 lines
Requests that were never transmitted do not require a disconnect.
I'm all for optimising where it makes sense, however this is adding another spinlock protected section in xprt_release() for something that is clearly a rare corner case.
So how about something like the following change instead?
8<---------------------------------------------------------------
fs/nfs/flexfilelayout/flexfilelayout.c +9 -0
@@ -2459,6 +2459,12 @@ static bool ff_layout_match_io(const struct rpc_task *task, const void *data)return false; } +static bool ff_layout_match_untransmitted_io (const struct rpc_task *task, +const void *data) +{ +return !RPC_WAS_SENT (task) &&ff_layout_match_io (task, data); +} +static void ff_layout_cancel_io (struct pnfs_layout_segment *lseg) {struct nfs4_ff_layout_segment *flseg =FF_LAYOUT_LSEG (lseg);
@@ -2484,6 +2490,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg) clnt = ds_clp->cl_rpcclient;if (!clnt)continue ; +rpc_cancel_tasks (clnt, -ECANCELED , + ff_layout_match_untransmitted_io, + lseg);if (!rpc_cancel_tasks (clnt, -ECANCELED , ff_layout_match_io, lseg))continue ;
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected], [email protected]
Trond Myklebust
maintainerRe: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks
Quoted 53 lines · Trond Myklebust
Quoted 49 lines · On Thu, 2026-11-05 at 02:02 +0000, [email protected] wrote:
From: Tim Menninger <[email protected]>
rpc_cancel_tasks()allows callers to cancel a selected set of RPC tasks,
but callers that also need to tear down the connection currently have
to
disconnect at therpc_clntlevel.That is broader than necessary for clients with multiple transports.
A
cancelled request is associated with a specificrpc_xprtand records
the
connection generation on which it was transmitted inrq_connect_cookie.Add
rpc_cancel_tasks_and_disconnect()to cancel matching tasks and mark
matching requests that remain on the transport transmit or receive queues
for conditional transport disconnect when the request is released.Store the disconnect indication in struct
rpc_rqstrather than structrpc_task. An RPC task can release one request and later acquire another,
so task-scoped state could otherwise be consumed by a successor request
and disconnect the wrong transport generation.After cancelling matching tasks, walk the client's transports and mark
matching requests belonging to that client that remain on the transmit
or receive queues. Anrpc_xprtmay be shared by multiplerpc_clntinstances, so requests belonging to other clients are left untouched.When a marked request is released, use
xprt_conditional_disconnect()
with
its savedrq_connect_cookie. This disconnects the transport only if it is
still using the same connection generation on which the request was sent,
and leaves a replacement connection untouched.Quoted 2 lines
Requests that were never transmitted do not require a disconnect.
Quoted 7 lines
I'm all for optimising where it makes sense, however this is adding another spinlock protected section in
xprt_release()for something that
is clearly a rare corner case.So how about something like the following change instead?
Sorry, I oversimplified. Something like this:
8<------------------------------------------------------
fs/nfs/flexfilelayout/flexfilelayout.c +9 -0
@@ -2459,6 +2459,12 @@ static bool ff_layout_match_io(const struct rpc_task *task, const void *data)return false; } +static bool ff_layout_match_untransmitted_io (const struct rpc_task *task, +const void *data) +{ +return !RPC_WAS_SENT (task) &&ff_layout_match_io (task, data); +} +static void ff_layout_cancel_io (struct pnfs_layout_segment *lseg) {struct nfs4_ff_layout_segment *flseg =FF_LAYOUT_LSEG (lseg);
@@ -2484,6 +2490,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg) clnt = ds_clp->cl_rpcclient;if (!clnt)continue ; +rpc_cancel_tasks (clnt, -ECANCELED , + ff_layout_match_untransmitted_io, + lseg);if (!rpc_cancel_tasks (clnt, -ECANCELED , ff_layout_match_io, lseg))continue ;
include/linux/sunrpc/sched.h +2 -2
@@ -219,8 +219,8 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req, struct rpc_timeout *timeout);void rpc_put_task (struct rpc_task *);void rpc_put_task_async (struct rpc_task *); -bool rpc_task_set_rpc_status (struct rpc_task *task,int rpc_status); -void rpc_task_try_cancel (struct rpc_task *task,int error); +bool rpc_task_set_rpc_status (struct rpc_task *task,int rpc_status); +bool rpc_task_try_cancel (struct rpc_task *task,int error);void rpc_signal_task (struct rpc_task *);void rpc_exit_task (struct rpc_task *);void rpc_exit (struct rpc_task *,int );
net/sunrpc/clnt.c +2 -1
@@ -930,7 +930,8 @@ unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error,continue ;if (!fnmatch (task, data))continue ; -rpc_task_try_cancel (task, error); +if (!rpc_task_try_cancel (task, error)) +continue ; count++; }spin_unlock (&clnt->cl_lock);
net/sunrpc/sched.c +3 -2
@@ -869,15 +869,16 @@ void rpc_signal_task(struct rpc_task *task)rpc_wake_up_queued_task (queue, task); } -void rpc_task_try_cancel (struct rpc_task *task,int error) +bool rpc_task_try_cancel (struct rpc_task *task,int error) {struct rpc_wait_queue *queue;if (!rpc_task_set_rpc_status (task, error)) -return ; +return false; queue =READ_ONCE (task->tk_waitqueue);if (queue)rpc_wake_up_queued_task (queue, task); +return true; }void rpc_exit (struct rpc_task *task,int status)
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected], [email protected]
Re: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks
Quoted 3 lines
I'm all for optimising where it makes sense, however this is adding another spinlock protected section in
xprt_release()for something that is clearly a rare corner case.
I agree about avoiding the additional lock acquisition in xprt_release(). I should rework that part.
Quoted 1 line
So how about something like the following change instead?
I tested it with the same reproducer, but I still see the reconnect behavior, without a noticeable improvement.
I think there are two separate issues here. Counting only successful cancellations avoids triggering another disconnect merely because an already-cancelled task still matches. Cancelling untransmitted tasks separately also avoids disconnecting solely because of those tasks.
However, when cancellation of a transmitted task succeeds, we still call rpc_clnt_disconnect(), which disconnects every connected transport on that client. That can affect another transport which carried no matching requests, or a replacement connection generation established since the cancelled request was transmitted. Neither RPC_WAS_SENT() nor a successful cancellation status update tells us whether those connections carried the affected request.
What I'm trying to do is limit that blast radius. For a request with rq_xprt == X and rq_connect_cookie == C, cancellation should not disconnect X if its current cookie no longer matches C, nor disconnect an unrelated transport Y on the same client.
Would retaining the request/connection-generation scope, while removing the additional unconditional lock acquisition from xprt_release(), be a reasonable direction?
Re: [PATCH v2 1/2] SUNRPC: add request-scoped disconnects when cancelling tasks
Quoted 3 lines
Would retaining the request/connection-generation scope, while removing the additional unconditional lock acquisition from
xprt_release(), be a reasonable direction?
I've posted v3 with the additional unconditional lock acquisition removed:
https://lore.kernel.org/all/[email protected]
There is still a broader question about when we should cancel I/O in the first place. This series does not change those cancellation decisions. I still think the narrower disconnect scope is useful independently of how we resolve that broader question. Where cancellation does require a disconnect, it should not also tear down unrelated transports or a replacement connection generation that did not carry the affected requests.
I posted v3 to put that narrower change forward for review, not to suggest that the cancellation-policy question is settled.
PATCH v2 2/2 NFSv4/flexfiles: limit transport disconnects when cancelling I/O
In reply to [email protected]From: Tim Menninger <[email protected]>
ff_layout_cancel_io() cancels RPC tasks associated with a recalled or revoked layout segment. If any matching tasks are found, it then calls rpc_clnt_disconnect().
rpc_clnt_disconnect() disconnects every transport attached to the RPC client. A data server client can have multiple transports, while the cancelled requests may have used only a subset of them. Cancelling I/O for one layout segment can therefore disrupt unrelated I/O using other transports belonging to the same data server client.
This is particularly disruptive with RPC/RDMA during data server recovery, where unnecessary transport disconnects can result in repeated reconnect activity on otherwise unaffected connections.
Use rpc_cancel_tasks_and_disconnect() instead. Matching tasks are still cancelled, but only matching requests belonging to that client that remain on the transport transmit or receive queues are marked for disconnect. When such a request is released, SUNRPC conditionally disconnects the connection generation on which that request was sent.
This preserves cancellation and draining of I/O associated with the layout segment without disconnecting unrelated transports attached to the same RPC client.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +3 -4
@@ -2599,10 +2599,9 @@ static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg, clnt = ds_clp->cl_rpcclient;if (!clnt) goto next; -if (!rpc_cancel_tasks (clnt, -ECANCELED , - ff_layout_match_io, lseg)) - goto next; -rpc_clnt_disconnect (clnt); +rpc_cancel_tasks_and_disconnect (clnt, -ECANCELED , + ff_layout_match_io, + lseg); next:nfs4_ff_layout_put_deviceid (mirror_ds); }
Signature · 1 line
2.53.0