All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Chuck Lever <cel@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	linux-nfs@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>
Subject: Re: [PATCH v10 4/5] NFSD: Implement NFSD_IO_DIRECT for NFS WRITE
Date: Thu, 6 Nov 2025 14:02:22 -0500	[thread overview]
Message-ID: <aQzwvqlD0xiYjMCW@kernel.org> (raw)
In-Reply-To: <e0723227-6984-4c04-be7c-c3be852a8607@kernel.org>

On Thu, Nov 06, 2025 at 01:10:17PM -0500, Chuck Lever wrote:
> On 11/6/25 11:48 AM, Mike Snitzer wrote:
> >>  no_dio:
> >>  	/*
> >>  	 * No DIO alignment possible - pack into single non-DIO segment.
> >> -	 * IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT.
> >>  	 */
> >> -	if (args->nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
> >> -		args->flags_buffered |= IOCB_DONTCACHE;
> >> -	nfsd_write_dio_seg_init(&args->segment[0], bvec, nvecs, total,
> >> -				0, total);
> >> -	args->nsegs = 1;
> >> +	nfsd_write_dio_seg_init(&segments[0], bvec, nvecs, total,
> >> +				0, total, iocb);
> >> +	return 1;
> >>  }
> > Selectively pushing the flag twiddling out to nfsd_direct_write()
> > ignores that we don't want to use DONTCACHE for the unaligned
> > prefix/suffix. Chuck and I discussed this a fair bit 1-2 days ago.
> 
> Agreed. I fixed this up after applying Christoph's patch.

OK, here is the incremental I just came up with, but sounds like
you're all set:

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 6fce4f08a4d4..db86b31e0c10 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1272,6 +1272,19 @@ static unsigned long iov_iter_bvec_offset(const struct iov_iter *iter)
 	return (unsigned long)(iter->bvec->bv_offset + iter->iov_offset);
 }
 
+/*
+ * Check if the bvec iterator is aligned for direct I/O.
+ *
+ * bvecs generated from RPC receive buffers are contiguous: After the first
+ * bvec, all subsequent bvecs start at bv_offset zero (page-aligned).
+ * Therefore, only the first bvec is checked.
+ */
+static bool
+nfsd_iov_iter_aligned_bvec(const struct iov_iter *iter, unsigned int addr_mask)
+{
+	return (iov_iter_bvec_offset(iter) & addr_mask) == 0;
+}
+
 static void
 nfsd_write_dio_seg_init(struct nfsd_write_dio_seg *segment,
 			struct bio_vec *bvec, unsigned int nvecs,
@@ -1324,16 +1337,8 @@ nfsd_write_dio_iters_init(struct nfsd_file *nf, struct bio_vec *bvec,
 
 	nfsd_write_dio_seg_init(&segments[nsegs], bvec, nvecs,
 				total, prefix, middle, iocb);
-
-	/*
-	 * Check if the bvec iterator is aligned for direct I/O.
-	 *
-	 * bvecs generated from RPC receive buffers are contiguous: After the
-	 * first bvec, all subsequent bvecs start at bv_offset zero
-	 * (page-aligned).
-	 * Therefore, only the first bvec is checked.
-	 */
-	if (iov_iter_bvec_offset(&segments[nsegs].iter) & (mem_align - 1))
+	if (!nfsd_iov_iter_aligned_bvec(&segments[nsegs].iter,
+					(mem_align - 1)))
 		goto no_dio;
 	segments[nsegs].flags |= IOCB_DIRECT;
 	nsegs++;
@@ -1348,9 +1353,12 @@ nfsd_write_dio_iters_init(struct nfsd_file *nf, struct bio_vec *bvec,
 no_dio:
 	/*
 	 * No DIO alignment possible - pack into single non-DIO segment.
+	 * IOCB_DONTCACHE preserves the intent of NFSD_IO_DIRECT.
 	 */
 	nfsd_write_dio_seg_init(&segments[0], bvec, nvecs, total,
 				0, total, iocb);
+	if (nf->nf_file->f_op->fop_flags & FOP_DONTCACHE)
+		segments[0].flags |= IOCB_DONTCACHE;
 	return 1;
 }
 
@@ -1370,16 +1378,9 @@ nfsd_direct_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	*cnt = 0;
 	for (i = 0; i < nsegs; i++) {
 		kiocb->ki_flags = segments[i].flags;
-		if (kiocb->ki_flags & IOCB_DIRECT) {
+		if (kiocb->ki_flags & IOCB_DIRECT)
 			trace_nfsd_write_direct(rqstp, fhp, kiocb->ki_pos,
 						segments[i].iter.count);
-		} else if (nf->nf_file->f_op->fop_flags & FOP_DONTCACHE) {
-			/*
-			 * IOCB_DONTCACHE preserves the intent of
-			 * NFSD_IO_DIRECT.
-			 */
-			kiocb->ki_flags |= IOCB_DONTCACHE;
-		}
 
 		host_err = vfs_iocb_iter_write(file, kiocb, &segments[i].iter);
 		if (host_err < 0)

  reply	other threads:[~2025-11-06 19:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 19:28 [PATCH v10 0/5] NFSD: Implement NFSD_IO_DIRECT for NFS WRITE Chuck Lever
2025-11-05 19:28 ` [PATCH v10 1/5] NFSD: don't start nfsd if sv_permsocks is empty Chuck Lever
2025-11-05 19:31   ` Chuck Lever
2025-11-05 19:28 ` [PATCH v10 2/5] NFSD: Make FILE_SYNC WRITEs comply with spec Chuck Lever
2025-11-06  0:55   ` NeilBrown
2025-11-06 13:05   ` Christoph Hellwig
2025-11-05 19:28 ` [PATCH v10 3/5] NFSD: Enable return of an updated stable_how to NFS clients Chuck Lever
2025-11-06 13:07   ` Christoph Hellwig
2025-11-06 16:30     ` Chuck Lever
2025-11-05 19:28 ` [PATCH v10 4/5] NFSD: Implement NFSD_IO_DIRECT for NFS WRITE Chuck Lever
2025-11-06 10:11   ` NeilBrown
2025-11-06 13:15     ` Christoph Hellwig
2025-11-06 13:51       ` Christoph Hellwig
2025-11-06 14:45         ` Chuck Lever
2025-11-06 14:49           ` Christoph Hellwig
2025-11-06 16:48         ` Mike Snitzer
2025-11-06 18:10           ` Chuck Lever
2025-11-06 19:02             ` Mike Snitzer [this message]
2025-11-07 13:24               ` Christoph Hellwig
2025-11-07 14:38                 ` Chuck Lever
2025-11-07 15:24                   ` Christoph Hellwig
2025-11-07 15:26                     ` Chuck Lever
2025-11-10 13:26   ` kernel test robot
2025-11-10 19:00   ` kernel test robot
2025-11-05 19:28 ` [PATCH v10 5/5] NFSD: add Documentation/filesystems/nfs/nfsd-io-modes.rst Chuck Lever
2025-11-06 10:24   ` NeilBrown
2025-11-06 15:46     ` Mike Snitzer
2025-11-06 15:52       ` 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=aQzwvqlD0xiYjMCW@kernel.org \
    --to=snitzer@kernel.org \
    --cc=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=dai.ngo@oracle.com \
    --cc=hch@infradead.org \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /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.