Skip to content

Commit 3435c74

Browse files
chuckleveramschuma-ntap
authored andcommitted
SUNRPC: Generalize the RPC buffer release API
xprtrdma needs to allocate the Call and Reply buffers separately. TBH, the reliance on using a single buffer for the pair of XDR buffers is transport implementation-specific. Instead of passing just the rq_buffer into the buf_free method, pass the task structure and let buf_free take care of freeing both XDR buffers at once. There's a micro-optimization here. In the common case, both xprt_release and the transport's buf_free method were checking if rq_buffer was NULL. Now the check is done only once per RPC. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 5fe6eaa commit 3435c74

File tree

8 files changed

+20
-31
lines changed

8 files changed

+20
-31
lines changed

include/linux/sunrpc/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ struct rpc_task *rpc_wake_up_first(struct rpc_wait_queue *,
240240
void rpc_wake_up_status(struct rpc_wait_queue *, int);
241241
void rpc_delay(struct rpc_task *, unsigned long);
242242
int rpc_malloc(struct rpc_task *);
243-
void rpc_free(void *);
243+
void rpc_free(struct rpc_task *);
244244
int rpciod_up(void);
245245
void rpciod_down(void);
246246
int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *);

include/linux/sunrpc/xprt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct rpc_xprt_ops {
128128
void (*set_port)(struct rpc_xprt *xprt, unsigned short port);
129129
void (*connect)(struct rpc_xprt *xprt, struct rpc_task *task);
130130
int (*buf_alloc)(struct rpc_task *task);
131-
void (*buf_free)(void *buffer);
131+
void (*buf_free)(struct rpc_task *task);
132132
int (*send_request)(struct rpc_task *task);
133133
void (*set_retrans_timeout)(struct rpc_task *task);
134134
void (*timer)(struct rpc_xprt *xprt, struct rpc_task *task);

net/sunrpc/sched.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,18 +896,16 @@ int rpc_malloc(struct rpc_task *task)
896896
EXPORT_SYMBOL_GPL(rpc_malloc);
897897

898898
/**
899-
* rpc_free - free buffer allocated via rpc_malloc
900-
* @buffer: buffer to free
899+
* rpc_free - free RPC buffer resources allocated via rpc_malloc
900+
* @task: RPC task
901901
*
902902
*/
903-
void rpc_free(void *buffer)
903+
void rpc_free(struct rpc_task *task)
904904
{
905+
void *buffer = task->tk_rqstp->rq_buffer;
905906
size_t size;
906907
struct rpc_buffer *buf;
907908

908-
if (!buffer)
909-
return;
910-
911909
buf = container_of(buffer, struct rpc_buffer, data);
912910
size = buf->len;
913911

net/sunrpc/xprt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ void xprt_release(struct rpc_task *task)
12951295
xprt_schedule_autodisconnect(xprt);
12961296
spin_unlock_bh(&xprt->transport_lock);
12971297
if (req->rq_buffer)
1298-
xprt->ops->buf_free(req->rq_buffer);
1298+
xprt->ops->buf_free(task);
12991299
xprt_inject_disconnect(xprt);
13001300
if (req->rq_cred != NULL)
13011301
put_rpccred(req->rq_cred);

net/sunrpc/xprtrdma/svc_rdma_backchannel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ xprt_rdma_bc_allocate(struct rpc_task *task)
186186
}
187187

188188
static void
189-
xprt_rdma_bc_free(void *buffer)
189+
xprt_rdma_bc_free(struct rpc_task *task)
190190
{
191191
/* No-op: ctxt and page have already been freed. */
192192
}

net/sunrpc/xprtrdma/transport.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ xprt_rdma_allocate(struct rpc_task *task)
523523
out:
524524
dprintk("RPC: %s: size %zd, request 0x%p\n", __func__, size, req);
525525
req->rl_connect_cookie = 0; /* our reserved value */
526-
req->rl_task = task;
527526
rqst->rq_buffer = req->rl_sendbuf->rg_base;
528527
return 0;
529528

@@ -571,31 +570,26 @@ xprt_rdma_allocate(struct rpc_task *task)
571570
return -ENOMEM;
572571
}
573572

574-
/*
575-
* This function returns all RDMA resources to the pool.
573+
/**
574+
* xprt_rdma_free - release resources allocated by xprt_rdma_allocate
575+
* @task: RPC task
576+
*
577+
* Caller guarantees rqst->rq_buffer is non-NULL.
576578
*/
577579
static void
578-
xprt_rdma_free(void *buffer)
580+
xprt_rdma_free(struct rpc_task *task)
579581
{
580-
struct rpcrdma_req *req;
581-
struct rpcrdma_xprt *r_xprt;
582-
struct rpcrdma_regbuf *rb;
583-
584-
if (buffer == NULL)
585-
return;
582+
struct rpc_rqst *rqst = task->tk_rqstp;
583+
struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(rqst->rq_xprt);
584+
struct rpcrdma_req *req = rpcr_to_rdmar(rqst);
586585

587-
rb = container_of(buffer, struct rpcrdma_regbuf, rg_base[0]);
588-
req = rb->rg_owner;
589586
if (req->rl_backchannel)
590587
return;
591588

592-
r_xprt = container_of(req->rl_buffer, struct rpcrdma_xprt, rx_buf);
593-
594589
dprintk("RPC: %s: called on 0x%p\n", __func__, req->rl_reply);
595590

596591
r_xprt->rx_ia.ri_ops->ro_unmap_safe(r_xprt, req,
597-
!RPC_IS_ASYNC(req->rl_task));
598-
592+
!RPC_IS_ASYNC(task));
599593
rpcrdma_buffer_put(req);
600594
}
601595

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ struct rpcrdma_req {
283283
struct list_head rl_free;
284284
unsigned int rl_niovs;
285285
unsigned int rl_connect_cookie;
286-
struct rpc_task *rl_task;
287286
struct rpcrdma_buffer *rl_buffer;
288287
struct rpcrdma_rep *rl_reply;/* holder for reply buffer */
289288
struct ib_sge rl_send_iov[RPCRDMA_MAX_IOVS];

net/sunrpc/xprtsock.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,13 +2560,11 @@ static int bc_malloc(struct rpc_task *task)
25602560
/*
25612561
* Free the space allocated in the bc_alloc routine
25622562
*/
2563-
static void bc_free(void *buffer)
2563+
static void bc_free(struct rpc_task *task)
25642564
{
2565+
void *buffer = task->tk_rqstp->rq_buffer;
25652566
struct rpc_buffer *buf;
25662567

2567-
if (!buffer)
2568-
return;
2569-
25702568
buf = container_of(buffer, struct rpc_buffer, data);
25712569
free_page((unsigned long)buf);
25722570
}

0 commit comments

Comments
 (0)