All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v4 1/3] NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE
Date: Wed,  5 Nov 2025 12:42:08 -0500	[thread overview]
Message-ID: <20251105174210.54023-2-snitzer@kernel.org> (raw)
In-Reply-To: <20251105174210.54023-1-snitzer@kernel.org>

NFSD_IO_DIRECT can easily improve streaming misaligned WRITE
performance if it uses buffered IO (without DONTCACHE) for the
misaligned end segment(s) and O_DIRECT for the aligned middle
segment's IO.

On one capable testbed, this commit improved streaming 47008 byte
write performance from 0.3433 GB/s to 1.26 GB/s.

This commit also merges nfsd_issue_dio_write into its only caller
(nfsd_direct_write).

Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 fs/nfsd/vfs.c | 73 ++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 42 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 701dd261c252..a4700c917c72 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1296,12 +1296,13 @@ nfsd_write_dio_seg_init(struct nfsd_write_dio_seg *segment,
 
 static void
 nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs,
-			  loff_t offset, unsigned long total,
+			  struct kiocb *kiocb, unsigned long total,
 			  struct nfsd_write_dio_args *args)
 {
 	u32 offset_align = args->nf->nf_dio_offset_align;
 	u32 mem_align = args->nf->nf_dio_mem_align;
 	loff_t prefix_end, orig_end, middle_end;
+	loff_t offset = kiocb->ki_pos;
 	size_t prefix, middle, suffix;
 
 	args->nsegs = 0;
@@ -1347,6 +1348,8 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs,
 		++args->nsegs;
 	}
 
+	args->flags_buffered = kiocb->ki_flags;
+	args->flags_direct = kiocb->ki_flags | IOCB_DIRECT;
 	return;
 
 no_dio:
@@ -1354,39 +1357,14 @@ nfsd_write_dio_iters_init(struct bio_vec *bvec, unsigned int nvecs,
 	nfsd_write_dio_seg_init(&args->segment[0], bvec, nvecs, total,
 				0, total);
 	args->nsegs = 1;
-}
 
-static int
-nfsd_issue_dio_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
-		     struct kiocb *kiocb, unsigned int nvecs,
-		     unsigned long *cnt, struct nfsd_write_dio_args *args)
-{
-	struct file *file = args->nf->nf_file;
-	ssize_t host_err;
-	unsigned int i;
-
-	nfsd_write_dio_iters_init(rqstp->rq_bvec, nvecs, kiocb->ki_pos,
-				  *cnt, args);
-
-	*cnt = 0;
-	for (i = 0; i < args->nsegs; i++) {
-		if (args->segment[i].use_dio) {
-			kiocb->ki_flags = args->flags_direct;
-			trace_nfsd_write_direct(rqstp, fhp, kiocb->ki_pos,
-						args->segment[i].iter.count);
-		} else
-			kiocb->ki_flags = args->flags_buffered;
-
-		host_err = vfs_iocb_iter_write(file, kiocb,
-					       &args->segment[i].iter);
-		if (host_err < 0)
-			return host_err;
-		*cnt += host_err;
-		if (host_err < args->segment[i].iter.count)
-			break;	/* partial write */
-	}
-
-	return 0;
+	/*
+	 * IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when
+	 * falling back to buffered IO if the entire WRITE is unaligned.
+	 */
+	args->flags_buffered = kiocb->ki_flags;
+	if (args->nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
+		args->flags_buffered |= IOCB_DONTCACHE;
 }
 
 static noinline_for_stack int
@@ -1395,20 +1373,31 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		  unsigned long *cnt, struct kiocb *kiocb)
 {
 	struct nfsd_write_dio_args args;
+	ssize_t host_err;
+	unsigned int i;
 
 	args.nf = nf;
+	nfsd_write_dio_iters_init(rqstp->rq_bvec, nvecs, kiocb, *cnt, &args);
 
-	/*
-	 * IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT when
-	 * writing unaligned segments or handling fallback I/O.
-	 */
-	args.flags_buffered = kiocb->ki_flags;
-	if (args.nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
-		args.flags_buffered |= IOCB_DONTCACHE;
+	*cnt = 0;
+	for (i = 0; i < args.nsegs; i++) {
+		if (args.segment[i].use_dio) {
+			kiocb->ki_flags = args.flags_direct;
+			trace_nfsd_write_direct(rqstp, fhp, kiocb->ki_pos,
+						args.segment[i].iter.count);
+		} else
+			kiocb->ki_flags = args.flags_buffered;
 
-	args.flags_direct = kiocb->ki_flags | IOCB_DIRECT;
+		host_err = vfs_iocb_iter_write(nf->nf_file, kiocb,
+					       &args.segment[i].iter);
+		if (host_err < 0)
+			return host_err;
+		*cnt += host_err;
+		if (host_err < args.segment[i].iter.count)
+			break;	/* partial write */
+	}
 
-	return nfsd_issue_dio_write(rqstp, fhp, kiocb, nvecs, cnt, &args);
+	return 0;
 }
 
 /**
-- 
2.44.0


  reply	other threads:[~2025-11-05 17:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 17:42 [PATCH v4 0/3] [PATCH 0/3] NFSD: additional NFSD Direct changes Mike Snitzer
2025-11-05 17:42 ` Mike Snitzer [this message]
2025-11-05 18:47   ` [PATCH v4 1/3] NFSD: avoid DONTCACHE for misaligned ends of misaligned DIO WRITE Chuck Lever
2025-11-07 15:29   ` Christoph Hellwig
2025-11-05 17:42 ` [PATCH v4 2/3] NFSD: add new NFSD_IO_DIRECT variants that may override stable_how Mike Snitzer
2025-11-05 18:49   ` Chuck Lever
2025-11-06 20:17     ` Mike Snitzer
2025-11-06 20:35       ` Chuck Lever
2025-11-06 22:56         ` Mike Snitzer
2025-11-07 14:48           ` Chuck Lever
2025-11-07 15:34           ` Christoph Hellwig
2025-11-07 15:35             ` Chuck Lever
2025-11-07 15:40               ` Christoph Hellwig
2025-11-07 15:30   ` Christoph Hellwig
2025-11-05 17:42 ` [PATCH v4 3/3] NFSD: update Documentation/filesystems/nfs/nfsd-io-modes.rst Mike Snitzer
2025-11-05 18:50   ` Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251105174210.54023-2-snitzer@kernel.org \
    --to=snitzer@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.