Skip to content

Commit 4866073

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
svcrdma: Use llist for managing cache of recv_ctxts
Use a wait-free mechanism for managing the svc_rdma_recv_ctxts free list. Subsequently, sc_recv_lock can be eliminated. Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent d6dfe43 commit 4866073

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

include/linux/sunrpc/svc_rdma.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#ifndef SVC_RDMA_H
4444
#define SVC_RDMA_H
45+
#include <linux/llist.h>
4546
#include <linux/sunrpc/xdr.h>
4647
#include <linux/sunrpc/svcsock.h>
4748
#include <linux/sunrpc/rpc_rdma.h>
@@ -107,8 +108,7 @@ struct svcxprt_rdma {
107108
struct list_head sc_read_complete_q;
108109
struct work_struct sc_work;
109110

110-
spinlock_t sc_recv_lock;
111-
struct list_head sc_recv_ctxts;
111+
struct llist_head sc_recv_ctxts;
112112
};
113113
/* sc_flags */
114114
#define RDMAXPRT_CONN_PENDING 3
@@ -125,6 +125,7 @@ enum {
125125
#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD
126126

127127
struct svc_rdma_recv_ctxt {
128+
struct llist_node rc_node;
128129
struct list_head rc_list;
129130
struct ib_recv_wr rc_recv_wr;
130131
struct ib_cqe rc_cqe;

net/sunrpc/xprtrdma/svc_rdma_recvfrom.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ static void svc_rdma_recv_ctxt_destroy(struct svcxprt_rdma *rdma,
172172
void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma)
173173
{
174174
struct svc_rdma_recv_ctxt *ctxt;
175+
struct llist_node *node;
175176

176-
while ((ctxt = svc_rdma_next_recv_ctxt(&rdma->sc_recv_ctxts))) {
177-
list_del(&ctxt->rc_list);
177+
while ((node = llist_del_first(&rdma->sc_recv_ctxts))) {
178+
ctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);
178179
svc_rdma_recv_ctxt_destroy(rdma, ctxt);
179180
}
180181
}
@@ -183,21 +184,18 @@ static struct svc_rdma_recv_ctxt *
183184
svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)
184185
{
185186
struct svc_rdma_recv_ctxt *ctxt;
187+
struct llist_node *node;
186188

187-
spin_lock(&rdma->sc_recv_lock);
188-
ctxt = svc_rdma_next_recv_ctxt(&rdma->sc_recv_ctxts);
189-
if (!ctxt)
189+
node = llist_del_first(&rdma->sc_recv_ctxts);
190+
if (!node)
190191
goto out_empty;
191-
list_del(&ctxt->rc_list);
192-
spin_unlock(&rdma->sc_recv_lock);
192+
ctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);
193193

194194
out:
195195
ctxt->rc_page_count = 0;
196196
return ctxt;
197197

198198
out_empty:
199-
spin_unlock(&rdma->sc_recv_lock);
200-
201199
ctxt = svc_rdma_recv_ctxt_alloc(rdma);
202200
if (!ctxt)
203201
return NULL;
@@ -218,11 +216,9 @@ void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,
218216
for (i = 0; i < ctxt->rc_page_count; i++)
219217
put_page(ctxt->rc_pages[i]);
220218

221-
if (!ctxt->rc_temp) {
222-
spin_lock(&rdma->sc_recv_lock);
223-
list_add(&ctxt->rc_list, &rdma->sc_recv_ctxts);
224-
spin_unlock(&rdma->sc_recv_lock);
225-
} else
219+
if (!ctxt->rc_temp)
220+
llist_add(&ctxt->rc_node, &rdma->sc_recv_ctxts);
221+
else
226222
svc_rdma_recv_ctxt_destroy(rdma, ctxt);
227223
}
228224

net/sunrpc/xprtrdma/svc_rdma_transport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,13 @@ static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv,
140140
INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
141141
INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
142142
INIT_LIST_HEAD(&cma_xprt->sc_send_ctxts);
143-
INIT_LIST_HEAD(&cma_xprt->sc_recv_ctxts);
143+
init_llist_head(&cma_xprt->sc_recv_ctxts);
144144
INIT_LIST_HEAD(&cma_xprt->sc_rw_ctxts);
145145
init_waitqueue_head(&cma_xprt->sc_send_wait);
146146

147147
spin_lock_init(&cma_xprt->sc_lock);
148148
spin_lock_init(&cma_xprt->sc_rq_dto_lock);
149149
spin_lock_init(&cma_xprt->sc_send_lock);
150-
spin_lock_init(&cma_xprt->sc_recv_lock);
151150
spin_lock_init(&cma_xprt->sc_rw_ctxt_lock);
152151

153152
/*

0 commit comments

Comments
 (0)