Skip to content

Commit e253e1a

Browse files
chucklevergregkh
authored andcommitted
xprtrdma: Remove temp allocation of rpcrdma_rep objects
[ Upstream commit 0e13dd9 ] The original code was designed so that most calls to rpcrdma_rep_create() would occur on the NUMA node that the device preferred. There are a few cases where that's not possible, so those reps are marked as temporary. However, we have the device (and its preferred node) already in rpcrdma_rep_create(), so let's use that to guarantee the memory is allocated from the correct node. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Stable-dep-of: e786233 ("xprtrdma: Decouple req recycling from RPC completion") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b6c4002 commit e253e1a

3 files changed

Lines changed: 26 additions & 37 deletions

File tree

net/sunrpc/xprtrdma/rpc_rdma.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,7 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
14711471
credits = 1; /* don't deadlock */
14721472
else if (credits > r_xprt->rx_ep->re_max_requests)
14731473
credits = r_xprt->rx_ep->re_max_requests;
1474-
rpcrdma_post_recvs(r_xprt, credits + (buf->rb_bc_srv_max_requests << 1),
1475-
false);
1474+
rpcrdma_post_recvs(r_xprt, credits + (buf->rb_bc_srv_max_requests << 1));
14761475
if (buf->rb_credits != credits)
14771476
rpcrdma_update_cwnd(r_xprt, credits);
14781477

net/sunrpc/xprtrdma/verbs.c

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ static void rpcrdma_sendctx_put_locked(struct rpcrdma_xprt *r_xprt,
6969
struct rpcrdma_sendctx *sc);
7070
static int rpcrdma_reqs_setup(struct rpcrdma_xprt *r_xprt);
7171
static void rpcrdma_reqs_reset(struct rpcrdma_xprt *r_xprt);
72-
static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep);
7372
static void rpcrdma_reps_unmap(struct rpcrdma_xprt *r_xprt);
7473
static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt);
7574
static void rpcrdma_mrs_destroy(struct rpcrdma_xprt *r_xprt);
7675
static void rpcrdma_ep_get(struct rpcrdma_ep *ep);
7776
static int rpcrdma_ep_put(struct rpcrdma_ep *ep);
7877
static struct rpcrdma_regbuf *
78+
rpcrdma_regbuf_alloc_node(size_t size, enum dma_data_direction direction,
79+
int node);
80+
static struct rpcrdma_regbuf *
7981
rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction);
8082
static void rpcrdma_regbuf_dma_unmap(struct rpcrdma_regbuf *rb);
8183
static void rpcrdma_regbuf_free(struct rpcrdma_regbuf *rb);
@@ -505,7 +507,7 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
505507
* outstanding Receives.
506508
*/
507509
rpcrdma_ep_get(ep);
508-
rpcrdma_post_recvs(r_xprt, 1, true);
510+
rpcrdma_post_recvs(r_xprt, 1);
509511

510512
rc = rdma_connect(ep->re_id, &ep->re_remote_cma);
511513
if (rc)
@@ -938,18 +940,20 @@ static void rpcrdma_reqs_reset(struct rpcrdma_xprt *r_xprt)
938940
}
939941

940942
static noinline
941-
struct rpcrdma_rep *rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt,
942-
bool temp)
943+
struct rpcrdma_rep *rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt)
943944
{
944945
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
946+
struct rpcrdma_ep *ep = r_xprt->rx_ep;
947+
struct ib_device *device = ep->re_id->device;
945948
struct rpcrdma_rep *rep;
946949

947950
rep = kzalloc(sizeof(*rep), XPRTRDMA_GFP_FLAGS);
948951
if (rep == NULL)
949952
goto out;
950953

951-
rep->rr_rdmabuf = rpcrdma_regbuf_alloc(r_xprt->rx_ep->re_inline_recv,
952-
DMA_FROM_DEVICE);
954+
rep->rr_rdmabuf = rpcrdma_regbuf_alloc_node(ep->re_inline_recv,
955+
DMA_FROM_DEVICE,
956+
ibdev_to_node(device));
953957
if (!rep->rr_rdmabuf)
954958
goto out_free;
955959

@@ -964,7 +968,6 @@ struct rpcrdma_rep *rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt,
964968
rep->rr_recv_wr.wr_cqe = &rep->rr_cqe;
965969
rep->rr_recv_wr.sg_list = &rep->rr_rdmabuf->rg_iov;
966970
rep->rr_recv_wr.num_sge = 1;
967-
rep->rr_temp = temp;
968971

969972
spin_lock(&buf->rb_lock);
970973
list_add(&rep->rr_all, &buf->rb_all_reps);
@@ -983,17 +986,6 @@ static void rpcrdma_rep_free(struct rpcrdma_rep *rep)
983986
kfree(rep);
984987
}
985988

986-
static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep)
987-
{
988-
struct rpcrdma_buffer *buf = &rep->rr_rxprt->rx_buf;
989-
990-
spin_lock(&buf->rb_lock);
991-
list_del(&rep->rr_all);
992-
spin_unlock(&buf->rb_lock);
993-
994-
rpcrdma_rep_free(rep);
995-
}
996-
997989
static struct rpcrdma_rep *rpcrdma_rep_get_locked(struct rpcrdma_buffer *buf)
998990
{
999991
struct llist_node *node;
@@ -1025,10 +1017,8 @@ static void rpcrdma_reps_unmap(struct rpcrdma_xprt *r_xprt)
10251017
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
10261018
struct rpcrdma_rep *rep;
10271019

1028-
list_for_each_entry(rep, &buf->rb_all_reps, rr_all) {
1020+
list_for_each_entry(rep, &buf->rb_all_reps, rr_all)
10291021
rpcrdma_regbuf_dma_unmap(rep->rr_rdmabuf);
1030-
rep->rr_temp = true; /* Mark this rep for destruction */
1031-
}
10321022
}
10331023

10341024
static void rpcrdma_reps_destroy(struct rpcrdma_buffer *buf)
@@ -1245,14 +1235,15 @@ void rpcrdma_buffer_put(struct rpcrdma_buffer *buffers, struct rpcrdma_req *req)
12451235
* or Replies they may be registered externally via frwr_map.
12461236
*/
12471237
static struct rpcrdma_regbuf *
1248-
rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction)
1238+
rpcrdma_regbuf_alloc_node(size_t size, enum dma_data_direction direction,
1239+
int node)
12491240
{
12501241
struct rpcrdma_regbuf *rb;
12511242

1252-
rb = kmalloc(sizeof(*rb), XPRTRDMA_GFP_FLAGS);
1243+
rb = kmalloc_node(sizeof(*rb), XPRTRDMA_GFP_FLAGS, node);
12531244
if (!rb)
12541245
return NULL;
1255-
rb->rg_data = kmalloc(size, XPRTRDMA_GFP_FLAGS);
1246+
rb->rg_data = kmalloc_node(size, XPRTRDMA_GFP_FLAGS, node);
12561247
if (!rb->rg_data) {
12571248
kfree(rb);
12581249
return NULL;
@@ -1264,6 +1255,12 @@ rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction)
12641255
return rb;
12651256
}
12661257

1258+
static struct rpcrdma_regbuf *
1259+
rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction)
1260+
{
1261+
return rpcrdma_regbuf_alloc_node(size, direction, NUMA_NO_NODE);
1262+
}
1263+
12671264
/**
12681265
* rpcrdma_regbuf_realloc - re-allocate a SEND/RECV buffer
12691266
* @rb: regbuf to reallocate
@@ -1341,10 +1338,9 @@ static void rpcrdma_regbuf_free(struct rpcrdma_regbuf *rb)
13411338
* rpcrdma_post_recvs - Refill the Receive Queue
13421339
* @r_xprt: controlling transport instance
13431340
* @needed: current credit grant
1344-
* @temp: mark Receive buffers to be deleted after one use
13451341
*
13461342
*/
1347-
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp)
1343+
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed)
13481344
{
13491345
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
13501346
struct rpcrdma_ep *ep = r_xprt->rx_ep;
@@ -1358,8 +1354,7 @@ void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp)
13581354
if (likely(ep->re_receive_count > needed))
13591355
goto out;
13601356
needed -= ep->re_receive_count;
1361-
if (!temp)
1362-
needed += RPCRDMA_MAX_RECV_BATCH;
1357+
needed += RPCRDMA_MAX_RECV_BATCH;
13631358

13641359
if (atomic_inc_return(&ep->re_receiving) > 1)
13651360
goto out_dec;
@@ -1368,12 +1363,8 @@ void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp)
13681363
wr = NULL;
13691364
while (needed) {
13701365
rep = rpcrdma_rep_get_locked(buf);
1371-
if (rep && rep->rr_temp) {
1372-
rpcrdma_rep_destroy(rep);
1373-
continue;
1374-
}
13751366
if (!rep)
1376-
rep = rpcrdma_rep_create(r_xprt, temp);
1367+
rep = rpcrdma_rep_create(r_xprt);
13771368
if (!rep)
13781369
break;
13791370
if (!rpcrdma_regbuf_dma_map(r_xprt, rep->rr_rdmabuf)) {

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ struct rpcrdma_rep {
198198
__be32 rr_proc;
199199
int rr_wc_flags;
200200
u32 rr_inv_rkey;
201-
bool rr_temp;
202201
struct rpcrdma_regbuf *rr_rdmabuf;
203202
struct rpcrdma_xprt *rr_rxprt;
204203
struct rpc_rqst *rr_rqst;
@@ -466,7 +465,7 @@ void rpcrdma_flush_disconnect(struct rpcrdma_xprt *r_xprt, struct ib_wc *wc);
466465
int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt);
467466
void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt);
468467

469-
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp);
468+
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed);
470469

471470
/*
472471
* Buffer calls - xprtrdma/verbs.c

0 commit comments

Comments
 (0)