Re: [PATCH] block: skip redundant flush for O_DSYNC direct writes

马振先 <[email protected]>
Newsgroups org.kernel.vger.linux-block
Message-ID <CAAth02BEXd7uy4LpXS7t42bH2kvkFDEcsLdHHAUizaV++zWzEQ@mail.gmail.com>
On Thu, Aug 13, 2026 at 12:42 AM Christoph Hellwig <[email protected]> wrote:
>
> > +     bool dio_fua_done = false;
> >       ssize_t ret;
> >
> >       if (bdev_read_only(bdev))
> > @@ -763,9 +764,13 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
> >
> >       if (iocb->ki_flags & IOCB_DIRECT) {
> >               ret = blkdev_direct_write(iocb, from);
> > -             if (ret >= 0 && iov_iter_count(from))
> > +             if (ret >= 0 && iov_iter_count(from)) {
> >                       ret = direct_write_fallback(iocb, from, ret,
> >                                       blkdev_buffered_write(iocb, from));
> > +             } else if (ret > 0 && iocb_is_dsync(iocb)) {
> > +                     /* FUA from dio_bio_write_op() already made it durable */
> > +                     dio_fua_done = true;
>
> This is kinda the wrong way aroud, it should just have a need_sync
> variable that is only set for the fallback.

Agreed, that reads much cleaner, I'll modify the flag in v2.

> But looking at this, the original logic here actually is very fishy.
> If we have a driver that does not actually support FUA, emulating it
> for every write command is a bad idea.  So this should be fixed to
> only do FUA when actually useful, and then return from the non-fallback
> implementations if that actually happened.

Let me make sure:
     blkdev_write_iter() then only skips generic_write_sync() when
     the direct-IO path actually issued REQ_FUA (i.e. iocb_is_dsync(iocb)
     && bdev_fua(bdev) && the write completed without falling back to
     buffered).  Is that the direction you had in mind?  If yes, I'll send patch
     v2 later.

Thanks for the review,
Zhenxian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.