From: Mike Snitzer <snitzer@kernel.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org, Jeff Layton <jlayton@kernel.org>
Subject: Re: [PATCH v3 2/4] NFSD: prepare nfsd_vfs_write() to use O_DIRECT on misaligned WRITEs
Date: Fri, 1 Aug 2025 18:29:43 -0400 [thread overview]
Message-ID: <aI0_12zwHYRPOS3t@kernel.org> (raw)
In-Reply-To: <27aecf85-059f-4789-bcfc-b518a2643e19@oracle.com>
On Fri, Aug 01, 2025 at 04:52:38PM -0400, Chuck Lever wrote:
> On 7/31/25 7:06 PM, Mike Snitzer wrote:
> > Refactor nfsd_vfs_write() to support splitting a WRITE into parts
> > (which will be either misaligned or DIO-aligned). Doing so in a
> > preliminary commit just allows for indentation and slight
> > transformation to be more easily understood and reviewed.
> >
> > Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> > Reviewed-by: Jeff Layton <jlayton@kernel.org>
> > ---
> > fs/nfsd/vfs.c | 45 +++++++++++++++++++++++++++------------------
> > 1 file changed, 27 insertions(+), 18 deletions(-)
> >
> > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> > index 35c29b8ade9c3..edac73349da0f 100644
> > --- a/fs/nfsd/vfs.c
> > +++ b/fs/nfsd/vfs.c
> > @@ -1341,7 +1341,6 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > struct super_block *sb = file_inode(file)->i_sb;
> > struct kiocb kiocb;
> > struct svc_export *exp;
> > - struct iov_iter iter;
> > errseq_t since;
> > __be32 nfserr;
> > int host_err;
> > @@ -1349,6 +1348,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > unsigned int pflags = current->flags;
> > bool restore_flags = false;
> > unsigned int nvecs;
> > + struct iov_iter iter_stack[1];
> > + struct iov_iter *iter = iter_stack;
> > + unsigned int n_iters = 0;
> >
> > trace_nfsd_write_opened(rqstp, fhp, offset, *cnt);
> >
> > @@ -1378,14 +1380,15 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > kiocb.ki_flags |= IOCB_DSYNC;
> >
> > nvecs = xdr_buf_to_bvec(rqstp->rq_bvec, rqstp->rq_maxpages, payload);
> > - iov_iter_bvec(&iter, ITER_SOURCE, rqstp->rq_bvec, nvecs, *cnt);
> > + iov_iter_bvec(&iter[0], ITER_SOURCE, rqstp->rq_bvec, nvecs, *cnt);
> > + n_iters++;
> >
> > switch (nfsd_io_cache_write) {
> > case NFSD_IO_DIRECT:
> > /* direct I/O must be aligned to device logical sector size */
> > if (nf->nf_dio_mem_align && nf->nf_dio_offset_align &&
> > (((offset | *cnt) & (nf->nf_dio_offset_align-1)) == 0) &&
> > - iov_iter_is_aligned(&iter, nf->nf_dio_mem_align - 1,
> > + iov_iter_is_aligned(&iter[0], nf->nf_dio_mem_align - 1,
> > nf->nf_dio_offset_align - 1))
> > kiocb.ki_flags = IOCB_DIRECT;
> > break;
> > @@ -1399,22 +1402,28 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > since = READ_ONCE(file->f_wb_err);
> > if (verf)
> > nfsd_copy_write_verifier(verf, nn);
> > - host_err = vfs_iocb_iter_write(file, &kiocb, &iter);
> > - if (host_err < 0) {
> > - commit_reset_write_verifier(nn, rqstp, host_err);
> > - goto out_nfserr;
> > - }
> > - *cnt = host_err;
> > - nfsd_stats_io_write_add(nn, exp, *cnt);
> > - fsnotify_modify(file);
> > - host_err = filemap_check_wb_err(file->f_mapping, since);
> > - if (host_err < 0)
> > - goto out_nfserr;
> > -
> > - if (stable && fhp->fh_use_wgather) {
> > - host_err = wait_for_concurrent_writes(file);
> > - if (host_err < 0)
> > + *cnt = 0;
> > + for (int i = 0; i < n_iters; i++) {
> > + host_err = vfs_iocb_iter_write(file, &kiocb, &iter[i]);
> > + if (host_err < 0) {
> > commit_reset_write_verifier(nn, rqstp, host_err);
> > + goto out_nfserr;
> > + }
>
> Does this loop wait after each iter is written? Would it be better to
> wait once after all the iters have been written?
It does, sorry about that. This incremental fixes it up and is easily
folded into this patch:
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 2eabcb5651ba..1590fc1fb420 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1533,19 +1533,17 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
}
*cnt += host_err;
nfsd_stats_io_write_add(nn, exp, host_err);
+ }
- fsnotify_modify(file);
- host_err = filemap_check_wb_err(file->f_mapping, since);
+ fsnotify_modify(file);
+ host_err = filemap_check_wb_err(file->f_mapping, since);
+ if (host_err < 0)
+ goto out_nfserr;
+
+ if (stable && fhp->fh_use_wgather) {
+ host_err = wait_for_concurrent_writes(file);
if (host_err < 0)
- goto out_nfserr;
-
- if (stable && fhp->fh_use_wgather) {
- host_err = wait_for_concurrent_writes(file);
- if (host_err < 0) {
- commit_reset_write_verifier(nn, rqstp, host_err);
- goto out_nfserr;
- }
- }
+ commit_reset_write_verifier(nn, rqstp, host_err);
}
out_nfserr:
next prev parent reply other threads:[~2025-08-01 22:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 23:06 [PATCH v3 0/4] NFSD DIRECT: add handling for misaligned WRITEs Mike Snitzer
2025-07-31 23:06 ` [PATCH v3 1/4] NFSD: refactor nfsd_read_vector_dio to EVENT_CLASS useful for READ and WRITE Mike Snitzer
2025-07-31 23:06 ` [PATCH v3 2/4] NFSD: prepare nfsd_vfs_write() to use O_DIRECT on misaligned WRITEs Mike Snitzer
2025-08-01 20:52 ` Chuck Lever
2025-08-01 22:29 ` Mike Snitzer [this message]
2025-07-31 23:06 ` [PATCH v3 3/4] NFSD: issue WRITEs using O_DIRECT even if IO is misaligned Mike Snitzer
2025-08-05 14:55 ` Chuck Lever
2025-08-05 19:02 ` Mike Snitzer
2025-07-31 23:06 ` [PATCH v3 4/4] NFSD: handle unaligned DIO for NFS reexport Mike Snitzer
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=aI0_12zwHYRPOS3t@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.