Linux NFS server support for multiple Write chunks
Subsystems (5)
cover Linux NFS server support for multiple Write chunks
The RPC/RDMA version 1 protocol allows clients to provision more than one Write chunk in each RPC/RDMA message. The Linux NFS client never has need to construct a message with multiple Write chunks, so the Linux NFS server has never implemented support for them.
At testing events, we discovered that the Solaris NFS client can emit such requests on occasion, but only when an application invokes readv(2) on a "forcedirectio" mount -- rare, indeed.
Even so, it's been on my "to-do" list for quite some time to get the Linux NFS server to handle multiple Write chunks. While addressing the recent NFSD/RDMA bug with Linux filesystems that do not have a .read_splice method [1], I realized that it was time to get this one off my plate.
So here is an attempt to support NFS/RDMA clients that send multiple Write chunks. To do this generically requires more xdr_buf slicing and dicing than the simple "zero or one" implementation.
At the same time, the ability to send RDMA Write requests _outside_ the .xpo_sendto path is introduced. Extensive testing has not revealed any functional or performance regression with this change.
Thoughts and comments are welcome.
[1] - https://bugzilla.kernel.org/show_bug.cgi?id=198053
---
Chuck Lever (11):
SUNRPC: Adjust synopsis of xdr_buf_subsegment()
svcrdma: Clean up RDMA Write path
NFSD: Invoke svc_encode_read_payload in "read" NFSD encoders
svcrdma: Post RDMA Writes while XDR encoding replies
svcrdma: Clean up svc_rdma_encode_reply_chunk()
svcrdma: Cache number of Write chunks
svcrdma: Add a data structure to track READ payloads
svcrdma: Add svc_rdma_skip_payloads()
svcrdma: Support multiple READ payloads when pulling up
svcrdma: Support multiple READ payloads in svc_rdma_map_reply_msg()
svcrdma: Support multiple Write chunks in svc_rdma_send_reply_chunk
fs/nfsd/nfs3xdr.c | 4 + fs/nfsd/nfs4xdr.c | 3 + fs/nfsd/nfsxdr.c | 4 + include/linux/sunrpc/svc_rdma.h | 24 +- include/trace/events/rpcrdma.h | 16 +- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 32 +- net/sunrpc/xprtrdma/svc_rdma_rw.c | 134 +++++--- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 556 ++++++++++++++++++++------------ 8 files changed, 486 insertions(+), 287 deletions(-)
--
Chuck Lever
RFC PATCH 1/11 SUNRPC: Adjust synopsis of xdr_buf_subsegment()
This makes it easier for callers to keep that buffer const as well.
--- include/linux/sunrpc/xdr.h | 3 ++- net/sunrpc/xdr.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/sunrpc/xdr.h +2 -1
@@ -183,7 +183,8 @@ xdr_adjust_iovec(struct kvec *iov, __be32 *p)*/ extern void xdr_shift_buf (struct xdr_buf *,size_t );extern void xdr_buf_from_iov (struct kvec *,struct xdr_buf *); -extern int xdr_buf_subsegment (struct xdr_buf *,struct xdr_buf *,unsigned int ,unsigned int ); +extern int xdr_buf_subsegment (const struct xdr_buf *buf,struct xdr_buf *subbuf, +unsigned int base,unsigned int len);extern int xdr_buf_read_mic (struct xdr_buf *,struct xdr_netobj *,unsigned int );extern int read_bytes_from_xdr_buf (struct xdr_buf *,unsigned int ,void *,unsigned int );extern int write_bytes_to_xdr_buf (struct xdr_buf *,unsigned int ,void *,unsigned int );
net/sunrpc/xdr.c +2 -3
@@ -1105,9 +1105,8 @@ EXPORT_SYMBOL_GPL(xdr_buf_from_iov);* * Returns -1 if base of length are out of bounds. */ -int -xdr_buf_subsegment (struct xdr_buf *buf,struct xdr_buf *subbuf, -unsigned int base,unsigned int len) +int xdr_buf_subsegment (const struct xdr_buf *buf,struct xdr_buf *subbuf, +unsigned int base,unsigned int len) { subbuf->buflen = subbuf->len = len;if (base < buf->head[0 ].iov_len) {
RFC PATCH 2/11 svcrdma: Clean up RDMA Write path
In reply to Chuck LeverConstify the xdr_buf argument to ensure the code here does not modify it, to enable callers to also use "const struct xdr_buf *".
Also, rename the helper functions, which emit RDMA Writes, not RDMA Sends.
--- net/sunrpc/xprtrdma/svc_rdma_rw.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_rw.c +15 -21
@@ -161,7 +161,7 @@ struct svc_rdma_write_info {__be32 *wi_segs;/* SGL constructor arguments */ -struct xdr_buf *wi_xdr; +const struct xdr_buf *wi_xdr;unsigned char *wi_base;unsigned int wi_next_off;
@@ -369,7 +369,7 @@ static void svc_rdma_pagelist_to_sg(struct svc_rdma_write_info *info, struct svc_rdma_rw_ctxt *ctxt) {unsigned int sge_no, sge_bytes, page_off, page_no; -struct xdr_buf *xdr = info->wi_xdr; +const struct xdr_buf *xdr = info->wi_xdr;struct scatterlist *sg;struct page **page;
@@ -470,27 +470,22 @@ svc_rdma_build_writes(struct svc_rdma_write_info *info,return -EIO ; } -/* Send one of an xdr_buf's kvecs by itself. To send a Reply -* chunk, the whole RPC Reply is written back to the client. -* This function writes either the head or tail of the xdr_buf -* containing the Reply. +/* RDMA Write an iov. */ -static int svc_rdma_send_xdr_kvec (struct svc_rdma_write_info *info, -struct kvec *vec) +static int svc_rdma_write_vec (struct svc_rdma_write_info *info, +const struct kvec *vec) { info->wi_base = vec->iov_base;return svc_rdma_build_writes (info, svc_rdma_vec_to_sg, vec->iov_len); } -/* Send an xdr_buf's page list by itself. A Write chunk is just -* the page list. A Reply chunk is @xdr's head, page list, and -* tail. This function is shared between the two types of chunk. +/* RDMA Write an xdr_buf's page list by itself. */ -static int svc_rdma_send_xdr_pagelist (struct svc_rdma_write_info *info, -struct xdr_buf *xdr, -unsigned int offset, -unsigned long length) +static int svc_rdma_write_pages (struct svc_rdma_write_info *info, +const struct xdr_buf *xdr, +unsigned int offset, +unsigned long length) { info->wi_xdr = xdr; info->wi_next_off = offset - xdr->head[0 ].iov_len;
@@ -527,7 +522,7 @@ int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma, __be32 *wr_ch,if (!info)return -ENOMEM ; - ret =svc_rdma_send_xdr_pagelist (info, xdr, offset, length); + ret =svc_rdma_write_pages (info, xdr, offset, length);if (ret <0 ) goto out_err;
@@ -567,7 +562,7 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,if (!info)return -ENOMEM ; - ret =svc_rdma_send_xdr_kvec (info, &xdr->head[0 ]); + ret =svc_rdma_write_vec (info, &xdr->head[0 ]);if (ret <0 ) goto out_err; consumed = xdr->head[0 ].iov_len;
@@ -576,16 +571,15 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,* client did not provide Write chunks. */ if (!rctxt->rc_write_list && xdr->page_len) { - ret =svc_rdma_send_xdr_pagelist (info, xdr, - xdr->head[0 ].iov_len, - xdr->page_len); + ret =svc_rdma_write_pages (info, xdr, xdr->head[0 ].iov_len, + xdr->page_len);if (ret <0 ) goto out_err; consumed += xdr->page_len; }if (xdr->tail[0 ].iov_len) { - ret =svc_rdma_send_xdr_kvec (info, &xdr->tail[0 ]); + ret =svc_rdma_write_vec (info, &xdr->tail[0 ]);if (ret <0 ) goto out_err; consumed += xdr->tail[0 ].iov_len;
RFC PATCH 3/11 NFSD: Invoke svc_encode_read_payload in "read" NFSD encoders
In reply to Chuck LeverHave the NFSD encoders annotate the boundaries of every direct-data-placement eligible READ data payload. Then change svcrdma to use that annotation instead of the xdr->page_len when handling Write chunks.
For NFSv4 on RDMA, that enables the ability to recognize multiple READ payloads per compound. Next step is to support multiple Write chunks.
--- fs/nfsd/nfs3xdr.c | 4 ++++ fs/nfsd/nfs4xdr.c | 3 +++ fs/nfsd/nfsxdr.c | 4 ++++ net/sunrpc/xprtrdma/svc_rdma_sendto.c | 24 +++++++----------------- 4 files changed, 18 insertions(+), 17 deletions(-)
fs/nfsd/nfs3xdr.c +4 -0
@@ -712,6 +712,8 @@ nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p) *p =0 ; rqstp->rq_res.tail[0 ].iov_len =4 - (resp->len&3 ); } +svc_encode_read_payload (rqstp, rqstp->rq_res.head[0 ].iov_len, + resp->len);return 1 ; }else return xdr_ressize_check (rqstp, p);
@@ -737,6 +739,8 @@ nfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p) *p =0 ; rqstp->rq_res.tail[0 ].iov_len =4 - (resp->count &3 ); } +svc_encode_read_payload (rqstp, rqstp->rq_res.head[0 ].iov_len, + resp->count);return 1 ; }else return xdr_ressize_check (rqstp, p);
fs/nfsd/nfs4xdr.c +3 -0
@@ -3547,6 +3547,8 @@ static __be32 nfsd4_encode_splice_read( buf->page_len =0 ;return nfserr; } +svc_encode_read_payload (read->rd_rqstp, buf->head[0 ].iov_len, + maxcount); *(p++) =htonl (eof); *(p++) =htonl (maxcount);
@@ -3713,6 +3715,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsdxdr_truncate_encode (xdr, length_offset);return nfserr; } +svc_encode_read_payload (readlink->rl_rqstp, length_offset, maxcount); wire_count =htonl (maxcount);write_bytes_to_xdr_buf (xdr->buf, length_offset, &wire_count,4 );
fs/nfsd/nfsxdr.c +4 -0
@@ -462,6 +462,8 @@ nfssvc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p) *p =0 ; rqstp->rq_res.tail[0 ].iov_len =4 - (resp->len&3 ); } +svc_encode_read_payload (rqstp, rqstp->rq_res.head[0 ].iov_len, + resp->len);return 1 ; }
@@ -482,6 +484,8 @@ nfssvc_encode_readres(struct svc_rqst *rqstp, __be32 *p) *p =0 ; rqstp->rq_res.tail[0 ].iov_len =4 - (resp->count&3 ); } +svc_encode_read_payload (rqstp, rqstp->rq_res.head[0 ].iov_len, + resp->count);return 1 ; }
net/sunrpc/xprtrdma/svc_rdma_sendto.c +7 -17
@@ -445,7 +445,6 @@ static ssize_t svc_rdma_encode_write_chunk(__be32 *src,* svc_rdma_encode_write_list - Encode RPC Reply's Write chunk list * @rctxt: Reply context with information about the RPC Call * @sctxt: Send context for the RPC Reply -* @length: size in bytes of the payload in the first Write chunk * * The client provides a Write chunk list in the Call message. Fill * in the segments in the first Write chunk in the Reply's transport
@@ -462,12 +461,12 @@ static ssize_t svc_rdma_encode_write_chunk(__be32 *src,*/ static ssize_t svc_rdma_encode_write_list (const struct svc_rdma_recv_ctxt *rctxt, -struct svc_rdma_send_ctxt *sctxt, -unsigned int length) +struct svc_rdma_send_ctxt *sctxt) {ssize_t len, ret; - ret =svc_rdma_encode_write_chunk (rctxt->rc_write_list, sctxt, length); + ret =svc_rdma_encode_write_chunk (rctxt->rc_write_list, sctxt, + rctxt->rc_read_payload_length);if (ret <0 )return ret; len = ret;
@@ -890,21 +889,12 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) goto err0;if (wr_lst) {/* XXX: Presume the client sent only one Write chunk */ -unsigned long offset; -unsigned int length; - -if (rctxt->rc_read_payload_length) { - offset = rctxt->rc_read_payload_offset; - length = rctxt->rc_read_payload_length; - }else { - offset = xdr->head[0 ].iov_len; - length = xdr->page_len; - } - ret =svc_rdma_send_write_chunk (rdma, wr_lst, xdr, offset, - length); + ret =svc_rdma_send_write_chunk (rdma, wr_lst, xdr, + rctxt->rc_read_payload_offset, + rctxt->rc_read_payload_length);if (ret <0 ) goto err2; -if (svc_rdma_encode_write_list (rctxt, sctxt, length) <0 ) +if (svc_rdma_encode_write_list (rctxt, sctxt) <0 ) goto err0; }else {if (xdr_stream_encode_item_absent (&sctxt->sc_stream) <0 )
RFC PATCH 4/11 svcrdma: Post RDMA Writes while XDR encoding replies
In reply to Chuck LeverThe only RPC/RDMA ordering requirement between RDMA Writes and RDMA Sends is that the responder must post the Writes on the Send queue before posting the Send that conveys the RPC Reply for that Write payload.
The Linux NFS server implementation now has a transport method that can post READ Payload Writes earlier than svc_rdma_sendto:
->xpo_read_payload.
Goals:
- Get RDMA Writes going earlier so they are more likely to be complete at the remote end before the Send completes.
- Allow more parallelism when dispatching RDMA operations by posting RDMA Writes before taking xpt_mutex.
Some care must be taken with pulled-up Replies. We don't want to push the Write chunk and then send the same payload data via Send.
--- include/linux/sunrpc/svc_rdma.h | 14 +++-- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 6 +- net/sunrpc/xprtrdma/svc_rdma_rw.c | 94 ++++++++++++++++++++++++------- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 84 +++++++++++++++------------- 4 files changed, 128 insertions(+), 70 deletions(-)
include/linux/sunrpc/svc_rdma.h +8 -6
@@ -125,6 +125,12 @@ enum {#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD +struct svc_rdma_payload { +__be32 *rp_chunk; +unsigned int rp_offset; +unsigned int rp_length; +}; +struct svc_rdma_recv_ctxt {struct llist_node rc_node;struct list_head rc_list;
@@ -139,10 +145,8 @@ struct svc_rdma_recv_ctxt {unsigned int rc_page_count;unsigned int rc_hdr_count;u32 rc_inv_rkey; -__be32 *rc_write_list; +struct svc_rdma_payload rc_read_payload;__be32 *rc_reply_chunk; -unsigned int rc_read_payload_offset; -unsigned int rc_read_payload_length;struct page *rc_pages[RPCSVC_MAXPAGES ]; };
@@ -178,9 +182,7 @@ extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma,struct svc_rqst *rqstp, struct svc_rdma_recv_ctxt *head, __be32 *p);extern int svc_rdma_send_write_chunk (struct svcxprt_rdma *rdma, -__be32 *wr_ch,struct xdr_buf *xdr, -unsigned int offset, -unsigned long length); +__be32 *wr_ch,const struct xdr_buf *xdr);extern int svc_rdma_send_reply_chunk (struct svcxprt_rdma *rdma,const struct svc_rdma_recv_ctxt *rctxt,struct xdr_buf *xdr);
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +3 -3
@@ -193,7 +193,7 @@ svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma) out: ctxt->rc_page_count =0 ; - ctxt->rc_read_payload_length =0 ; + ctxt->rc_read_payload.rp_length =0 ;return ctxt; out_empty:
@@ -479,7 +479,7 @@ static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt) p =xdr_inline_decode (&rctxt->rc_stream,sizeof (*p));if (!p)return false; - rctxt->rc_write_list = p; + rctxt->rc_read_payload.rp_chunk = p;while (*p != xdr_zero) {if (!xdr_check_write_chunk (rctxt,MAX_BYTES_WRITE_CHUNK ))return false;
@@ -489,7 +489,7 @@ static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt)return false; }if (!chcount) - rctxt->rc_write_list =NULL ; + rctxt->rc_read_payload.rp_chunk =NULL ;return chcount <2 ; }
net/sunrpc/xprtrdma/svc_rdma_rw.c +73 -21
155 lines not on this page · raw message
net/sunrpc/xprtrdma/svc_rdma_sendto.c +44 -40
169 lines not on this page · raw message
RFC PATCH 5/11 svcrdma: Clean up svc_rdma_encode_reply_chunk()
In reply to Chuck LeverClean up: Match the control flow of svc_rdma_encode_write_list().
--- net/sunrpc/xprtrdma/svc_rdma_rw.c | 3 +++ net/sunrpc/xprtrdma/svc_rdma_sendto.c | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_rw.c +3 -0
@@ -610,6 +610,9 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,struct svc_rdma_write_info *info;int consumed, ret; +if (!rctxt->rc_reply_chunk) +return 0 ; + info =svc_rdma_write_info_alloc (rdma, rctxt->rc_reply_chunk);if (!info)return -ENOMEM ;
net/sunrpc/xprtrdma/svc_rdma_sendto.c +12 -13
@@ -507,7 +507,10 @@ svc_rdma_encode_reply_chunk(const struct svc_rdma_recv_ctxt *rctxt, .rp_length = length, }; -return svc_rdma_encode_write_chunk (sctxt, &payload); +if (!rctxt->rc_reply_chunk) +return xdr_stream_encode_item_absent (&sctxt->sc_stream); +else +return svc_rdma_encode_write_chunk (sctxt, &payload); } static int svc_rdma_dma_map_page(struct svcxprt_rdma *rdma,
@@ -868,7 +871,6 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) container_of(xprt, struct svcxprt_rdma, sc_xprt);struct svc_rdma_recv_ctxt *rctxt = rqstp->rq_xprt_ctxt;__be32 *rdma_argp = rctxt->rc_recv_buf; -__be32 *rp_ch = rctxt->rc_reply_chunk;struct svc_rdma_send_ctxt *sctxt;__be32 *p;int ret;
@@ -888,25 +890,22 @@ int svc_rdma_sendto(struct svc_rqst *rqstp) rpcrdma_fixed_maxsz * sizeof(*p));if (!p) goto err0; + + ret =svc_rdma_send_reply_chunk (rdma, rctxt, &rqstp->rq_res); +if (ret <0 ) + goto err2; + *p++ = *rdma_argp; *p++ = *(rdma_argp +1 ); *p++ = rdma->sc_fc_credits; - *p = rp_ch ? rdma_nomsg : rdma_msg; + *p = rctxt->rc_reply_chunk ? rdma_nomsg : rdma_msg;if (svc_rdma_encode_read_list (sctxt) <0 ) goto err0;if (svc_rdma_encode_write_list (rctxt, sctxt) <0 ) goto err0; -if (rp_ch) { - ret =svc_rdma_send_reply_chunk (rdma, rctxt, &rqstp->rq_res); -if (ret <0 ) - goto err2; -if (svc_rdma_encode_reply_chunk (rctxt, sctxt, ret) <0 ) - goto err0; - }else { -if (xdr_stream_encode_item_absent (&sctxt->sc_stream) <0 ) - goto err0; - } +if (svc_rdma_encode_reply_chunk (rctxt, sctxt, ret) <0 ) + goto err0; ret =svc_rdma_send_reply_msg (rdma, sctxt, rctxt, rqstp);if (ret <0 )
RFC PATCH 6/11 svcrdma: Cache number of Write chunks
In reply to Chuck LeverHave the Call header decoder count the number of Write chunks it finds and cache that count for use in the Send path. Currently, the Linux NFS server implementation accepts only zero or one, but a subsequent patch will allow it to handle more than one.
--- include/linux/sunrpc/svc_rdma.h | 1 + net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 2 ++ net/sunrpc/xprtrdma/svc_rdma_rw.c | 2 +- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 10 +++++----- 4 files changed, 9 insertions(+), 6 deletions(-)
include/linux/sunrpc/svc_rdma.h +1 -0
@@ -147,6 +147,7 @@ struct svc_rdma_recv_ctxt {u32 rc_inv_rkey;struct svc_rdma_payload rc_read_payload;__be32 *rc_reply_chunk; +unsigned int rc_num_write_chunks;struct page *rc_pages[RPCSVC_MAXPAGES ]; };
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +2 -0
@@ -194,6 +194,7 @@ svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma) out: ctxt->rc_page_count =0 ; ctxt->rc_read_payload.rp_length =0 ; + ctxt->rc_num_write_chunks =0 ;return ctxt; out_empty:
@@ -488,6 +489,7 @@ static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt)if (!p)return false; } + rctxt->rc_num_write_chunks = chcount;if (!chcount) rctxt->rc_read_payload.rp_chunk =NULL ;return chcount <2 ;
net/sunrpc/xprtrdma/svc_rdma_rw.c +1 -1
@@ -625,7 +625,7 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,/* Send the page list in the Reply chunk only if the * client did not provide Write chunks. */ -if (!rctxt->rc_read_payload.rp_chunk && xdr->page_len) { +if (!rctxt->rc_num_write_chunks && xdr->page_len) { ret =svc_rdma_pages_write (info, xdr, xdr->head[0 ].iov_len, xdr->page_len);if (ret <0 )
net/sunrpc/xprtrdma/svc_rdma_sendto.c +5 -5
@@ -467,7 +467,7 @@ svc_rdma_encode_write_list(const struct svc_rdma_recv_ctxt *rctxt,ssize_t len, ret; len =0 ; -if (rctxt->rc_read_payload.rp_chunk) { +if (rctxt->rc_num_write_chunks) { ret =svc_rdma_encode_write_chunk (sctxt, &rctxt->rc_read_payload);if (ret <0 )
@@ -564,7 +564,7 @@ static bool svc_rdma_pull_up_needed(struct svcxprt_rdma *rdma,const struct svc_rdma_recv_ctxt *rctxt, struct xdr_buf *xdr) { - bool read_payload_present = rctxt && rctxt->rc_read_payload.rp_chunk; + bool read_payload_present = rctxt && rctxt->rc_num_write_chunks;int elements;/* For small messages, copying bytes is cheaper than DMA mapping.
@@ -628,7 +628,7 @@ static int svc_rdma_pull_up_reply_msg(struct svcxprt_rdma *rdma, tailbase = xdr->tail[0 ].iov_base; taillen = xdr->tail[0 ].iov_len; -if (rctxt && rctxt->rc_read_payload.rp_chunk) { +if (rctxt && rctxt->rc_num_write_chunks) {u32 xdrpad; xdrpad =xdr_pad_size (xdr->page_len);
@@ -713,7 +713,7 @@ int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma,* have added XDR padding in the tail buffer, and that * should not be included inline. */ -if (rctxt && rctxt->rc_read_payload.rp_chunk) { +if (rctxt && rctxt->rc_num_write_chunks) { base = xdr->tail[0 ].iov_base; len = xdr->tail[0 ].iov_len; xdr_pad =xdr_pad_size (xdr->page_len);
@@ -952,7 +952,7 @@ int svc_rdma_read_payload(struct svc_rqst *rqstp, unsigned int offset,struct xdr_buf uninitialized_var (subbuf );struct svcxprt_rdma *rdma; -if (!rctxt->rc_read_payload.rp_chunk || !length) +if (!rctxt->rc_num_write_chunks || !length)return 0 ;/* XXX: Just one READ payload slot for now, since our
RFC PATCH 7/11 svcrdma: Add a data structure to track READ payloads
In reply to Chuck LeverThe Linux NFS/RDMA server implementation currently supports only a single Write chunk per RPC/RDMA request. Requests with more than one are so rare there has never been a strong need to support more. However we are aware of at least one existing NFS client implementation that can generate such requests, so let's dig in.
Allocate a data structure at Receive time to keep track of the set of READ payloads and the Write chunks.
--- include/linux/sunrpc/svc_rdma.h | 3 ++ net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 30 +++++++++++++++++++----- net/sunrpc/xprtrdma/svc_rdma_rw.c | 2 +- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 38 +++++++++++++++++-------------- 4 files changed, 47 insertions(+), 26 deletions(-)
include/linux/sunrpc/svc_rdma.h +2 -1
@@ -145,9 +145,10 @@ struct svc_rdma_recv_ctxt {unsigned int rc_page_count;unsigned int rc_hdr_count;u32 rc_inv_rkey; -struct svc_rdma_payload rc_read_payload; +struct svc_rdma_payload *rc_read_payloads;__be32 *rc_reply_chunk;unsigned int rc_num_write_chunks; +unsigned int rc_cur_payload;struct page *rc_pages[RPCSVC_MAXPAGES ]; };
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +23 -7
@@ -193,8 +193,9 @@ svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma) out: ctxt->rc_page_count =0 ; - ctxt->rc_read_payload.rp_length =0 ; ctxt->rc_num_write_chunks =0 ; + ctxt->rc_cur_payload =0 ; + ctxt->rc_read_payloads =NULL ;return ctxt; out_empty:
@@ -217,7 +218,8 @@ void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,for (i =0 ; i < ctxt->rc_page_count; i++)put_page (ctxt->rc_pages[i]); - +kfree (ctxt->rc_read_payloads); + ctxt->rc_read_payloads =NULL ;if (!ctxt->rc_temp)llist_add (&ctxt->rc_node, &rdma->sc_recv_ctxts);else
@@ -474,13 +476,13 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt, u32 maxlen)*/ static bool xdr_check_write_list (struct svc_rdma_recv_ctxt *rctxt) { -u32 chcount =0 ; -__be32 *p; +u32 i, segcount, chcount =0 ; +__be32 *p, *saved; p =xdr_inline_decode (&rctxt->rc_stream,sizeof (*p));if (!p)return false; - rctxt->rc_read_payload.rp_chunk = p; + saved = p;while (*p != xdr_zero) {if (!xdr_check_write_chunk (rctxt,MAX_BYTES_WRITE_CHUNK ))return false;
@@ -491,8 +493,22 @@ static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt) } rctxt->rc_num_write_chunks = chcount;if (!chcount) - rctxt->rc_read_payload.rp_chunk =NULL ; -return chcount <2 ; +return true; + + rctxt->rc_read_payloads =kcalloc (chcount, +sizeof (struct svc_rdma_payload ), +GFP_KERNEL ); +if (!rctxt->rc_read_payloads) +return false; + + i =0 ; + p = saved; +while (*p != xdr_zero) { + rctxt->rc_read_payloads[i++].rp_chunk = p++; + segcount =be32_to_cpup (p++); + p += segcount * rpcrdma_segment_maxsz; + } +return true; }/* Sanity check the Reply chunk.
net/sunrpc/xprtrdma/svc_rdma_rw.c +1 -1
@@ -625,7 +625,7 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,/* Send the page list in the Reply chunk only if the * client did not provide Write chunks. */ -if (!rctxt->rc_num_write_chunks && xdr->page_len) { +if (!rctxt->rc_cur_payload && xdr->page_len) { ret =svc_rdma_pages_write (info, xdr, xdr->head[0 ].iov_len, xdr->page_len);if (ret <0 )
net/sunrpc/xprtrdma/svc_rdma_sendto.c +21 -17
@@ -447,10 +447,11 @@ static ssize_t svc_rdma_encode_write_chunk(struct svc_rdma_send_ctxt *sctxt,* @rctxt: Reply context with information about the RPC Call * @sctxt: Send context for the RPC Reply * -* The client provides a Write chunk list in the Call message. Fill -* in the segments in the first Write chunk in the Reply's transport -* header with the number of bytes consumed in each segment. -* Remaining chunks are returned unused. +* The client provided a Write list in the Call message. For each +* READ payload, fill in the segments in the Write chunks in the +* Reply's transport header with the number of bytes consumed +* in each segment. Any remaining Write chunks are returned to +* the client unused. * * Assumptions: * - Client has provided only one Write chunk
@@ -465,11 +466,12 @@ svc_rdma_encode_write_list(const struct svc_rdma_recv_ctxt *rctxt, struct svc_rdma_send_ctxt *sctxt) {ssize_t len, ret; +unsigned int i; len =0 ; -if (rctxt->rc_num_write_chunks) { +for (i =0 ; i < rctxt->rc_num_write_chunks; i++) { ret =svc_rdma_encode_write_chunk (sctxt, - &rctxt->rc_read_payload); + &rctxt->rc_read_payloads[i]);if (ret <0 )return ret; len += ret;
@@ -564,7 +566,7 @@ static bool svc_rdma_pull_up_needed(struct svcxprt_rdma *rdma,const struct svc_rdma_recv_ctxt *rctxt, struct xdr_buf *xdr) { - bool read_payload_present = rctxt && rctxt->rc_num_write_chunks; + bool read_payload_present = rctxt && rctxt->rc_cur_payload;int elements;/* For small messages, copying bytes is cheaper than DMA mapping.
@@ -628,7 +630,7 @@ static int svc_rdma_pull_up_reply_msg(struct svcxprt_rdma *rdma, tailbase = xdr->tail[0 ].iov_base; taillen = xdr->tail[0 ].iov_len; -if (rctxt && rctxt->rc_num_write_chunks) { +if (rctxt && rctxt->rc_cur_payload) {u32 xdrpad; xdrpad =xdr_pad_size (xdr->page_len);
@@ -708,12 +710,12 @@ int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma,if (ret <0 )return ret; -/* If a Write chunk is present, the xdr_buf's page list +/* If Write chunks are present, the xdr_buf's page list * is not included inline. However the Upper Layer may * have added XDR padding in the tail buffer, and that * should not be included inline. */ -if (rctxt && rctxt->rc_num_write_chunks) { +if (rctxt && rctxt->rc_cur_payload) { base = xdr->tail[0 ].iov_base; len = xdr->tail[0 ].iov_len; xdr_pad =xdr_pad_size (xdr->page_len);
@@ -951,21 +953,23 @@ int svc_rdma_read_payload(struct svc_rqst *rqstp, unsigned int offset,struct svc_rdma_recv_ctxt *rctxt = rqstp->rq_xprt_ctxt;struct xdr_buf uninitialized_var (subbuf );struct svcxprt_rdma *rdma; +unsigned int i;if (!rctxt->rc_num_write_chunks || !length)return 0 ; -/* XXX: Just one READ payload slot for now, since our -* transport implementation currently supports only one -* Write chunk. -*/ - rctxt->rc_read_payload.rp_offset = offset; - rctxt->rc_read_payload.rp_length = length; +if (rctxt->rc_cur_payload > rctxt->rc_num_write_chunks) +return -ENOENT ; + i = rctxt->rc_cur_payload++; + + rctxt->rc_read_payloads[i].rp_offset = offset; + rctxt->rc_read_payloads[i].rp_length = length;if (xdr_buf_subsegment (&rqstp->rq_res, &subbuf, offset, length))return -EMSGSIZE ; rdma = container_of(rqstp->rq_xprt, struct svcxprt_rdma, sc_xprt); -return svc_rdma_send_write_chunk (rdma, rctxt->rc_read_payload.rp_chunk, +return svc_rdma_send_write_chunk (rdma, + rctxt->rc_read_payloads[i].rp_chunk, &subbuf); }
RFC PATCH 8/11 svcrdma: Add svc_rdma_skip_payloads()
In reply to Chuck LeverWe'll need a generic mechanism for processing only the parts of an egress RPC message that are _not_ a READ payload. This will be used in subsequent patches.
This is a separate patch to reduce the complexity of subsequent patches, so that the logic of this new mechanism can be separately reviewed.
--- include/linux/sunrpc/svc_rdma.h | 4 ++ net/sunrpc/xprtrdma/svc_rdma_sendto.c | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
include/linux/sunrpc/svc_rdma.h +4 -0
@@ -195,6 +195,10 @@ extern struct svc_rdma_send_ctxt * svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma);extern void svc_rdma_send_ctxt_put (struct svcxprt_rdma *rdma,struct svc_rdma_send_ctxt *ctxt); +extern int svc_rdma_skip_payloads (const struct xdr_buf *xdr, +const struct svc_rdma_recv_ctxt *rctxt, +int (*actor)(const struct xdr_buf *,void *), +void *data);extern int svc_rdma_send (struct svcxprt_rdma *rdma,struct ib_send_wr *wr); extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma, struct svc_rdma_send_ctxt *sctxt,
net/sunrpc/xprtrdma/svc_rdma_sendto.c +72 -0
78 lines not on this page · raw message
RFC PATCH 9/11 svcrdma: Support multiple READ payloads when pulling up
In reply to Chuck LeverWhen counting the number of SGEs needed to construct a Send request, do not count READ payloads. And, when copying the Reply message into the pull-up buffer, READ payloads are not to be copied to the Send buffer.
--- include/trace/events/rpcrdma.h | 15 ++- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 186 ++++++++++++++++++++------------- 2 files changed, 121 insertions(+), 80 deletions(-)
include/trace/events/rpcrdma.h +10 -5
@@ -1641,20 +1641,25 @@ TRACE_EVENT(svcrdma_dma_map_rwctx,TRACE_EVENT (svcrdma_send_pullup,TP_PROTO ( - unsigned int len + unsigned int hdrlen, + unsigned int msglen ), -TP_ARGS (len), +TP_ARGS (hdrlen, msglen),TP_STRUCT__entry ( - __field(unsigned int, len) + __field(unsigned int, hdrlen) + __field(unsigned int, msglen) ),TP_fast_assign ( - __entry->len = len; + __entry->hdrlen = hdrlen; + __entry->msglen = msglen; ), -TP_printk ("len=%u" , __entry->len) +TP_printk ("hdr=%u msg=%u (total %u)" , + __entry->hdrlen, __entry->msglen, + __entry->hdrlen + __entry->msglen) ); TRACE_EVENT(svcrdma_send_failed,
net/sunrpc/xprtrdma/svc_rdma_sendto.c +111 -75
220 lines not on this page · raw message
RFC PATCH 10/11 svcrdma: Support multiple READ payloads in svc_rdma_map_reply_msg()
In reply to Chuck LeverThe function is restructured to DMA map only the parts of rq_res that do not contain a READ payload.
This change has been tested to confirm that it does not cause a regression in the no Write chunk and single Write chunk cases. Multiple Write chunks have not been tested.
--- include/linux/sunrpc/svc_rdma.h | 2 include/trace/events/rpcrdma.h | 1 net/sunrpc/xprtrdma/svc_rdma_sendto.c | 173 +++++++++++++++++++-------------- 3 files changed, 99 insertions(+), 77 deletions(-)
include/linux/sunrpc/svc_rdma.h +1 -1
@@ -203,7 +203,7 @@ extern int svc_rdma_send(struct svcxprt_rdma *rdma, struct ib_send_wr *wr);extern int svc_rdma_map_reply_msg (struct svcxprt_rdma *rdma,struct svc_rdma_send_ctxt *sctxt,const struct svc_rdma_recv_ctxt *rctxt, -struct xdr_buf *xdr); +const struct xdr_buf *xdr);extern int svc_rdma_sendto (struct svc_rqst *);extern int svc_rdma_read_payload (struct svc_rqst *rqstp,unsigned int offset,unsigned int length);
include/trace/events/rpcrdma.h +1 -0
@@ -1612,6 +1612,7 @@ DECLARE_EVENT_CLASS(svcrdma_dma_map_class, TP_ARGS(rdma, dma_addr, length))DEFINE_SVC_DMA_EVENT (dma_map_page); +DEFINE_SVC_DMA_EVENT (dma_map_failed);DEFINE_SVC_DMA_EVENT (dma_unmap_page); TRACE_EVENT(svcrdma_dma_map_rwctx,
net/sunrpc/xprtrdma/svc_rdma_sendto.c +97 -76
223 lines not on this page · raw message
RFC PATCH 11/11 svcrdma: Support multiple Write chunks in svc_rdma_send_reply_chunk
In reply to Chuck LeverThis should be the last stop.
--- include/linux/sunrpc/svc_rdma.h | 2 +- net/sunrpc/xprtrdma/svc_rdma_rw.c | 35 ++++++++--------------------------- 2 files changed, 9 insertions(+), 28 deletions(-)
include/linux/sunrpc/svc_rdma.h +1 -1
@@ -187,7 +187,7 @@ extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma, __be32 *wr_ch, const struct xdr_buf *xdr);extern int svc_rdma_send_reply_chunk (struct svcxprt_rdma *rdma,const struct svc_rdma_recv_ctxt *rctxt, -struct xdr_buf *xdr); +const struct xdr_buf *xdr);/* svc_rdma_sendto.c */ extern void svc_rdma_send_ctxts_destroy (struct svcxprt_rdma *rdma);
net/sunrpc/xprtrdma/svc_rdma_rw.c +8 -27
@@ -516,7 +516,7 @@ static int svc_rdma_pages_write(struct svc_rdma_write_info *info,/** * svc_rdma_xb_write - Construct RDMA Writes to write an xdr_buf * @xdr: xdr_buf to write -* @info: pointer to write arguments +* @data: pointer to write arguments * * Returns: * On succes, returns zero
@@ -524,9 +524,9 @@ static int svc_rdma_pages_write(struct svc_rdma_write_info *info,* %-ENOMEM if a resource has been exhausted * %-EIO if an rdma-rw error occurred */ -static int svc_rdma_xb_write (const struct xdr_buf *xdr, -struct svc_rdma_write_info *info) +static int svc_rdma_xb_write (const struct xdr_buf *xdr,void *data) { +struct svc_rdma_write_info *info = data;int ret;if (xdr->head[0 ].iov_len) {
@@ -605,10 +605,10 @@ int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma, __be32 *wr_ch,*/ int svc_rdma_send_reply_chunk (struct svcxprt_rdma *rdma,const struct svc_rdma_recv_ctxt *rctxt, -struct xdr_buf *xdr) +const struct xdr_buf *xdr) {struct svc_rdma_write_info *info; -int consumed, ret; +int ret;if (!rctxt->rc_reply_chunk)return 0 ;
@@ -617,35 +617,16 @@ int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,if (!info)return -ENOMEM ; - ret =svc_rdma_iov_write (info, &xdr->head[0 ]); + ret =svc_rdma_skip_payloads (xdr, rctxt, svc_rdma_xb_write, info);if (ret <0 ) goto out_err; - consumed = xdr->head[0 ].iov_len; - -/* Send the page list in the Reply chunk only if the -* client did not provide Write chunks. -*/ -if (!rctxt->rc_cur_payload && xdr->page_len) { - ret =svc_rdma_pages_write (info, xdr, xdr->head[0 ].iov_len, - xdr->page_len); -if (ret <0 ) - goto out_err; - consumed += xdr->page_len; - } - -if (xdr->tail[0 ].iov_len) { - ret =svc_rdma_iov_write (info, &xdr->tail[0 ]); -if (ret <0 ) - goto out_err; - consumed += xdr->tail[0 ].iov_len; - } ret =svc_rdma_post_chunk_ctxt (&info->wi_cc);if (ret <0 ) goto out_err; -trace_svcrdma_send_reply_chunk (consumed); -return consumed; +trace_svcrdma_send_reply_chunk (xdr->len); +return xdr->len; out_err:svc_rdma_write_info_free (info);