Skip to contentSkip to conversation

Remove svc_rqst :: rq_vec

PATCH Superseded [email protected] 3 participants 7 messages May 7, 2025 – May 8, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover Remove svc_rqst :: rq_vec

From: Chuck Lever <[email protected]>

I intend to insert these into the series that expands the maximum r/wsize, once they are reviewed.

Testing has shown no correctness issues, but some unexpected performance variation that I still need to chase down.

Chuck Lever (4):
NFSD: Use rqstp->rq_bvec in nfsd_iter_read()
NFSD: De-duplicate the svc_fill_write_vector() call sites
NFSD: Use rqstp->rq_bvec in nfsd_iter_write()
SUNRPC: Remove svc_rqst :: rq_vec

 fs/nfsd/nfs3proc.c         |  5 +---
 fs/nfsd/nfs4proc.c         |  8 ++---
 fs/nfsd/nfsproc.c          |  9 ++----
 fs/nfsd/vfs.c              | 61 +++++++++++++++++++++++++++-----------
 fs/nfsd/vfs.h              | 10 +++----
 include/linux/sunrpc/svc.h |  3 +-
 net/sunrpc/svc.c           | 33 ++++++++++-----------
 7 files changed, 71 insertions(+), 58 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/4 NFSD: Use rqstp->rq_bvec in nfsd_iter_read()

From: Chuck Lever <[email protected]>

If we can get rid of all uses of rq_vec, then it can be removed. Replace one use of rqstp::rq_vec with rqstp::rq_bvec.

---
 fs/nfsd/vfs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/nfsd/vfs.c +6 -6
index ea0773bb7c05..d3aa5b82d02d 100644
@@ -1083,23 +1083,23 @@ __be32 nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	unsigned long v, total;
 	struct iov_iter iter;
 	loff_t ppos = offset;
-	struct page *page;
 	ssize_t host_err;
+	size_t len;
 
 	v = 0;
 	total = *count;
 	while (total) {
-		page = *(rqstp->rq_next_page++);
-		rqstp->rq_vec[v].iov_base = page_address(page) + base;
-		rqstp->rq_vec[v].iov_len = min_t(size_t, total, PAGE_SIZE - base);
-		total -= rqstp->rq_vec[v].iov_len;
+		len = min_t(size_t, total, PAGE_SIZE - base);
+		bvec_set_page(&rqstp->rq_bvec[v], *(rqstp->rq_next_page++),
+			      len, base);
+		total -= len;
 		++v;
 		base = 0;
 	}
 	WARN_ON_ONCE(v > rqstp->rq_maxpages);
 
 	trace_nfsd_read_vector(rqstp, fhp, offset, *count);
-	iov_iter_kvec(&iter, ITER_DEST, rqstp->rq_vec, v, *count);
+	iov_iter_bvec(&iter, ITER_DEST, rqstp->rq_bvec, v, *count);
 	host_err = vfs_iter_read(file, &iter, &ppos, 0);
 	return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
 }
Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/4 NFSD: De-duplicate the svc_fill_write_vector() call sites

In reply to [email protected]

From: Chuck Lever <[email protected]>

All three call sites do the same thing. Instead, simply pass the xdr_buf containing the write payload directly to nfsd_write() and nfsd_vfs_write().

---
 fs/nfsd/nfs3proc.c         |  5 +---
 fs/nfsd/nfs4proc.c         |  8 ++-----
 fs/nfsd/nfsproc.c          |  9 +++----
 fs/nfsd/vfs.c              | 49 +++++++++++++++++++++++++++++---------
 fs/nfsd/vfs.h              | 10 ++++----
 include/linux/sunrpc/svc.h |  2 +-
 net/sunrpc/svc.c           |  4 ++--
 7 files changed, 52 insertions(+), 35 deletions(-)
fs/nfsd/nfs3proc.c +1 -4
index 372bdcf5e07a..3eecaabd96ce 100644
@@ -220,7 +220,6 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
 	struct nfsd3_writeargs *argp = rqstp->rq_argp;
 	struct nfsd3_writeres *resp = rqstp->rq_resp;
 	unsigned long cnt = argp->len;
-	unsigned int nvecs;
 
 	dprintk("nfsd: WRITE(3)    %s %d bytes at %Lu%s\n",
 				SVCFH_fmt(&argp->fh),
@@ -235,10 +234,8 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
 
 	fh_copy(&resp->fh, &argp->fh);
 	resp->committed = argp->stable;
-	nvecs = svc_fill_write_vector(rqstp, &argp->payload);
-
 	resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
-				  rqstp->rq_vec, nvecs, &cnt,
+				  &argp->payload, &cnt,
 				  resp->committed, resp->verf);
 	resp->count = cnt;
 	resp->status = nfsd3_map_status(resp->status);
fs/nfsd/nfs4proc.c +2 -6
index ba1c5e16172a..57dbc1162ea9 100644
@@ -1211,7 +1211,6 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	struct nfsd_file *nf = NULL;
 	__be32 status = nfs_ok;
 	unsigned long cnt;
-	int nvecs;
 
 	if (write->wr_offset > (u64)OFFSET_MAX ||
 	    write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
@@ -1226,12 +1225,9 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		return status;
 
 	write->wr_how_written = write->wr_stable_how;
-
-	nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
-
 	status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
-				write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
-				write->wr_how_written,
+				write->wr_offset, &write->wr_payload,
+				&cnt, write->wr_how_written,
 				(__be32 *)write->wr_verifier.data);
 	nfsd_file_put(nf);
 
fs/nfsd/nfsproc.c +3 -6
index 5d842671fe6f..14641cf58680 100644
@@ -250,17 +250,14 @@ nfsd_proc_write(struct svc_rqst *rqstp)
 	struct nfsd_writeargs *argp = rqstp->rq_argp;
 	struct nfsd_attrstat *resp = rqstp->rq_resp;
 	unsigned long cnt = argp->len;
-	unsigned int nvecs;
 
 	dprintk("nfsd: WRITE    %s %u bytes at %d\n",
 		SVCFH_fmt(&argp->fh),
 		argp->len, argp->offset);
 
-	nvecs = svc_fill_write_vector(rqstp, &argp->payload);
-
-	resp->status = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
-				  argp->offset, rqstp->rq_vec, nvecs,
-				  &cnt, NFS_DATA_SYNC, NULL);
+	fh_copy(&resp->fh, &argp->fh);
+	resp->status = nfsd_write(rqstp, &resp->fh, argp->offset,
+				  &argp->payload, &cnt, NFS_DATA_SYNC, NULL);
 	if (resp->status == nfs_ok)
 		resp->status = fh_getattr(&resp->fh, &resp->stat);
 	else if (resp->status == nfserr_jukebox)
fs/nfsd/vfs.c +38 -11

84 lines not on this page · raw message

fs/nfsd/vfs.h +5 -5
index f9b09b842856..eff04959606f 100644
@@ -128,13 +128,13 @@ bool		nfsd_read_splice_ok(struct svc_rqst *rqstp);
 __be32		nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
 				loff_t offset, unsigned long *count,
 				u32 *eof);
-__be32 		nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
-				struct kvec *, int, unsigned long *,
-				int stable, __be32 *verf);
+__be32		nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
+				loff_t offset, const struct xdr_buf *payload,
+				unsigned long *cnt, int stable, __be32 *verf);
 __be32		nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 				struct nfsd_file *nf, loff_t offset,
-				struct kvec *vec, int vlen, unsigned long *cnt,
-				int stable, __be32 *verf);
+				const struct xdr_buf *payload,
+				unsigned long *cnt, int stable, __be32 *verf);
 __be32		nfsd_readlink(struct svc_rqst *, struct svc_fh *,
 				char *, int *);
 __be32		nfsd_symlink(struct svc_rqst *, struct svc_fh *,
include/linux/sunrpc/svc.h +1 -1
index 088c162ae7d6..513b5ee88293 100644
@@ -464,7 +464,7 @@ int		   svc_encode_result_payload(struct svc_rqst *rqstp,
 					     unsigned int offset,
 					     unsigned int length);
 unsigned int	   svc_fill_write_vector(struct svc_rqst *rqstp,
-					 struct xdr_buf *payload);
+					 const struct xdr_buf *payload);
 char		  *svc_fill_symlink_pathname(struct svc_rqst *rqstp,
 					     struct kvec *first, void *p,
 					     size_t total);
net/sunrpc/svc.c +2 -2
index 930a10cac90b..7ad65e562470 100644
@@ -1733,10 +1733,10 @@ EXPORT_SYMBOL_GPL(svc_encode_result_payload);
  * Fills in rqstp::rq_vec, and returns the number of elements.
  */
 unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
-				   struct xdr_buf *payload)
+				   const struct xdr_buf *payload)
 {
+	const struct kvec *first = payload->head;
 	struct page **pages = payload->pages;
-	struct kvec *first = payload->head;
 	struct kvec *vec = rqstp->rq_vec;
 	size_t total = payload->len;
 	unsigned int i;
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 3/4 NFSD: Use rqstp->rq_bvec in nfsd_iter_write()

In reply to [email protected]

From: Chuck Lever <[email protected]>

If we can get rid of all uses of rq_vec, then it can be removed. Replace one use of rqstp::rq_vec with rqstp::rq_bvec.

---
 fs/nfsd/vfs.c    |  2 +-
 net/sunrpc/svc.c | 23 +++++++++++++----------
 2 files changed, 14 insertions(+), 11 deletions(-)
fs/nfsd/vfs.c +1 -1
index 9673ab33ee5d..334bdf8a576d 100644
@@ -1204,7 +1204,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (stable && !fhp->fh_use_wgather)
 		flags |= RWF_SYNC;
 
-	iov_iter_kvec(&iter, ITER_SOURCE, rqstp->rq_vec, nvecs, *cnt);
+	iov_iter_bvec(&iter, ITER_SOURCE, rqstp->rq_bvec, nvecs, *cnt);
 	since = READ_ONCE(file->f_wb_err);
 	if (verf)
 		nfsd_copy_write_verifier(verf, nn);
net/sunrpc/svc.c +13 -10
index 7ad65e562470..77e9c180f48b 100644
@@ -1727,35 +1727,38 @@ EXPORT_SYMBOL_GPL(svc_encode_result_payload);
 
 /**
  * svc_fill_write_vector - Construct data argument for VFS write call
- * @rqstp: svc_rqst to operate on
+ * @rqstp: RPC execution context
  * @payload: xdr_buf containing only the write data payload
  *
- * Fills in rqstp::rq_vec, and returns the number of elements.
+ * Fills in @rqstp->rq_bvec, and returns the number of elements it
+ * populated in that array.
  */
 unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
 				   const struct xdr_buf *payload)
 {
 	const struct kvec *first = payload->head;
 	struct page **pages = payload->pages;
-	struct kvec *vec = rqstp->rq_vec;
+	struct bio_vec *vec = rqstp->rq_bvec;
 	size_t total = payload->len;
-	unsigned int i;
+	unsigned int base, len, i;
 
 	/* Some types of transport can present the write payload
 	 * entirely in rq_arg.pages. In this case, @first is empty.
 	 */
 	i = 0;
 	if (first->iov_len) {
-		vec[i].iov_base = first->iov_base;
-		vec[i].iov_len = min_t(size_t, total, first->iov_len);
-		total -= vec[i].iov_len;
+		len = min_t(size_t, total, first->iov_len);
+		bvec_set_virt(&vec[i], first->iov_base, len);
+		total -= len;
 		++i;
 	}
 
+	base = payload->page_base;
 	while (total) {
-		vec[i].iov_base = page_address(*pages);
-		vec[i].iov_len = min_t(size_t, total, PAGE_SIZE);
-		total -= vec[i].iov_len;
+		len = min_t(size_t, total, PAGE_SIZE);
+		bvec_set_page(&vec[i], *pages, len, base);
+		total -= len;
+		base = 0;
 		++i;
 		++pages;
 	}
Signature · 1 line
2.49.0
#4 lore raw

Re: [PATCH v1 3/4] NFSD: Use rqstp->rq_bvec in nfsd_iter_write()

Quoted 5 lines · On Wed, May 07, 2025 at 10:07:27AM -0400, [email protected] wrote:

+ * Fills in @rqstp->rq_bvec, and returns the number of elements it
+ * populated in that array.
*/
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
const struct xdr_buf *payload)

The caller can simply use xdr_buf_to_bvec as done in my version of this and we can kill this helper.

author maintainer
#5 lore raw

PATCH 4/4 SUNRPC: Remove svc_rqst :: rq_vec

In reply to [email protected]

From: Chuck Lever <[email protected]>

Clean up: This array is no longer used.

---
 include/linux/sunrpc/svc.h | 1 -
 net/sunrpc/svc.c           | 6 ------
 2 files changed, 7 deletions(-)
include/linux/sunrpc/svc.h +0 -1
index 513b5ee88293..a66d13e55831 100644
@@ -205,7 +205,6 @@ struct svc_rqst {
 	struct page *		*rq_page_end;  /* one past the last page */
 
 	struct folio_batch	rq_fbatch;
-	struct kvec		*rq_vec;
 	struct bio_vec		*rq_bvec;
 
 	__be32			rq_xid;		/* transmission id */
net/sunrpc/svc.c +0 -6
index 77e9c180f48b..8056af53d3c0 100644
@@ -673,7 +673,6 @@ svc_rqst_free(struct svc_rqst *rqstp)
 {
 	folio_batch_release(&rqstp->rq_fbatch);
 	kfree(rqstp->rq_bvec);
-	kfree(rqstp->rq_vec);
 	svc_release_buffer(rqstp);
 	if (rqstp->rq_scratch_page)
 		put_page(rqstp->rq_scratch_page);
@@ -712,11 +711,6 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
 	if (!svc_init_buffer(rqstp, serv, node))
 		goto out_enomem;
 
-	rqstp->rq_vec = kcalloc_node(rqstp->rq_maxpages, sizeof(struct kvec),
-				      GFP_KERNEL, node);
-	if (!rqstp->rq_vec)
-		goto out_enomem;
-
 	rqstp->rq_bvec = kcalloc_node(rqstp->rq_maxpages,
 				      sizeof(struct bio_vec),
 				      GFP_KERNEL, node);
Signature · 1 line
2.49.0
maintainer Reviewed-by on the v1 series
#6 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, 2025-05-07 at 10:07 -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

I intend to insert these into the series that expands the maximum r/wsize, once they are reviewed.

Testing has shown no correctness issues, but some unexpected performance variation that I still need to chase down.

Interesting.

Quoted 6 lines

Chuck Lever (4):
NFSD: Use rqstp->rq_bvec in nfsd_iter_read()
NFSD: De-duplicate the svc_fill_write_vector() call sites
NFSD: Use rqstp->rq_bvec in nfsd_iter_write()
SUNRPC: Remove svc_rqst :: rq_vec

Quoted 8 lines
 fs/nfsd/nfs3proc.c         |  5 +---
 fs/nfsd/nfs4proc.c         |  8 ++---
 fs/nfsd/nfsproc.c          |  9 ++----
 fs/nfsd/vfs.c              | 61 +++++++++++++++++++++++++++-----------
 fs/nfsd/vfs.h              | 10 +++----
 include/linux/sunrpc/svc.h |  3 +-
 net/sunrpc/svc.c           | 33 ++++++++++-----------
 7 files changed, 71 insertions(+), 58 deletions(-)

Either way, this seems like a good simplification and cleanup.