[PATCH] sunrpc: delay pc_release callback until after the reply is sent

Jeff Layton posted 1 patch 3 months ago
net/sunrpc/svc.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
[PATCH] sunrpc: delay pc_release callback until after the reply is sent
Posted by Jeff Layton 3 months ago
The server-side sunrpc code currently calls pc_release before sending
the reply. Change svc_process and svc_process_bc to call pc_release
after sending the reply instead.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
I think this patch makes sense on its own, on the general principle of
expediting the reply. In my own testing, it doesn't seem to make any
difference in performance, probably owing to the fact that most
pc_release operations are very lightweight.
---
 net/sunrpc/svc.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index b1fab3a6954437cf751e4725fa52cfc83eddf2ab..fc70e13b1cb99a4ac4cbaa919f5a91d285844b11 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -1426,8 +1426,6 @@ svc_process_common(struct svc_rqst *rqstp)
 
 	/* Call the function that processes the request. */
 	rc = process.dispatch(rqstp);
-	if (procp->pc_release)
-		procp->pc_release(rqstp);
 	xdr_finish_decode(xdr);
 
 	if (!rc)
@@ -1526,6 +1524,14 @@ static void svc_drop(struct svc_rqst *rqstp)
 	trace_svc_drop(rqstp);
 }
 
+static void svc_release_rqst(struct svc_rqst *rqstp)
+{
+	const struct svc_procedure *procp = rqstp->rq_procinfo;
+
+	if (procp && procp->pc_release)
+		procp->pc_release(rqstp);
+}
+
 /**
  * svc_process - Execute one RPC transaction
  * @rqstp: RPC transaction context
@@ -1565,9 +1571,12 @@ void svc_process(struct svc_rqst *rqstp)
 	if (unlikely(*p != rpc_call))
 		goto out_baddir;
 
-	if (!svc_process_common(rqstp))
+	if (!svc_process_common(rqstp)) {
+		svc_release_rqst(rqstp);
 		goto out_drop;
+	}
 	svc_send(rqstp);
+	svc_release_rqst(rqstp);
 	return;
 
 out_baddir:
@@ -1635,6 +1644,7 @@ void svc_process_bc(struct rpc_rqst *req, struct svc_rqst *rqstp)
 	if (!proc_error) {
 		/* Processing error: drop the request */
 		xprt_free_bc_request(req);
+		svc_release_rqst(rqstp);
 		return;
 	}
 	/* Finally, send the reply synchronously */
@@ -1648,6 +1658,7 @@ void svc_process_bc(struct rpc_rqst *req, struct svc_rqst *rqstp)
 	timeout.to_maxval = timeout.to_initval;
 	memcpy(&req->rq_snd_buf, &rqstp->rq_res, sizeof(req->rq_snd_buf));
 	task = rpc_run_bc_task(req, &timeout);
+	svc_release_rqst(rqstp);
 
 	if (IS_ERR(task))
 		return;

---
base-commit: f4407c6fb86dc485e98052aebc0d39c8ced46e70
change-id: 20250708-rpc-6-17-fee766a442e3

Best regards,
-- 
Jeff Layton <jlayton@kernel.org>
Re: [PATCH] sunrpc: delay pc_release callback until after the reply is sent
Posted by Chuck Lever 3 months ago
On Tue, 08 Jul 2025 14:14:53 -0400, Jeff Layton wrote:
> The server-side sunrpc code currently calls pc_release before sending
> the reply. Change svc_process and svc_process_bc to call pc_release
> after sending the reply instead.
> 
> 

Applied to nfsd-testing, thanks!

[1/1] sunrpc: delay pc_release callback until after the reply is sent
      commit: 61d31be8f6efdaaf0df0ca25ce67a00ebbaec08a

--
Chuck Lever <chuck.lever@oracle.com>