Re: [PATCH v1 3/8] iomap: add buffered write support for IOMAP_IN_MEM iomaps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 9, 2025 at 9:38 AM Darrick J. Wong <djwong@xxxxxxxxxx> wrote:
>
> On Fri, Jun 06, 2025 at 04:37:58PM -0700, Joanne Koong wrote:
> > Add buffered write support for IOMAP_IN_MEM iomaps. This lets
> > IOMAP_IN_MEM iomaps use some of the internal features in iomaps
> > such as granular dirty tracking for large folios.
> >
> > Signed-off-by: Joanne Koong <joannelkoong@xxxxxxxxx>
> > ---
> >  fs/iomap/buffered-io.c | 24 +++++++++++++++++-------
> >  include/linux/iomap.h  | 10 ++++++++++
> >  2 files changed, 27 insertions(+), 7 deletions(-)
> >
> > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> > index 1caeb4921035..fd2ea1306d88 100644
> > --- a/fs/iomap/buffered-io.c
> > +++ b/fs/iomap/buffered-io.c
> > @@ -300,7 +300,7 @@ static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,
> >  {
> >       const struct iomap *srcmap = iomap_iter_srcmap(iter);
> >
> > -     return srcmap->type != IOMAP_MAPPED ||
> > +     return (srcmap->type != IOMAP_MAPPED && srcmap->type != IOMAP_IN_MEM) ||
> >               (srcmap->flags & IOMAP_F_NEW) ||
> >               pos >= i_size_read(iter->inode);
> >  }
> > @@ -583,16 +583,26 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
> >                                        pos + len - 1);
> >  }
> >
> > -static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,
> > -             size_t poff, size_t plen, const struct iomap *iomap)
> > +static int iomap_read_folio_sync(const struct iomap_iter *iter, loff_t block_start,
> > +                              struct folio *folio, size_t poff, size_t plen)
> >  {
> > -     return iomap_bio_read_folio_sync(block_start, folio, poff, plen, iomap);
> > +     const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops;
> > +     const struct iomap *srcmap = iomap_iter_srcmap(iter);
> > +
> > +     if (folio_ops && folio_ops->read_folio_sync)
> > +             return folio_ops->read_folio_sync(block_start, folio,
> > +                                               poff, plen, srcmap,
> > +                                               iter->private);
>
> Hmm, patch 6 hooks this up to fuse_do_readfolio, which means that iomap
> provides the folios and manages their uptodate/dirty state.  You still
> want fuse to handle the folio contents (aka poke the fuse server via
> FUSE_READ/FUSE_WRITE), but this avoids the memcpy that IOMAP_INLINE
> performs.
>
> So I think you're effectively addding another IO path to buffered-io.c,
> which explains why you moved the bio code to a separate file.  I wonder

The bio code needed to be moved to its own separate file because it
depends on CONFIG_BLOCK whereas fuse should still compile/run even if
CONFIG_BLOCK is not set.

Btw, I think you will need this too for your fuse server iomap patchset.

> if you could hook up this new IO path by checking for a non-NULL
> ->read_folio_sync function and calling it regardless of iomap::type?

I think this is already doing that? It will call ->read_folio_sync()
if the callback was provided, regardless of what the iomap type is.

>
> --D
>
> > +
> > +     /* IOMAP_IN_MEM iomaps must always handle ->read_folio_sync() */
> > +     WARN_ON_ONCE(iter->iomap.type == IOMAP_IN_MEM);
> > +
> > +     return iomap_bio_read_folio_sync(block_start, folio, poff, plen, srcmap);
> >  }
> >
> >  static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
> >               size_t len, struct folio *folio)
> >  {
> > -     const struct iomap *srcmap = iomap_iter_srcmap(iter);
> >       struct iomap_folio_state *ifs;
> >       loff_t block_size = i_blocksize(iter->inode);
> >       loff_t block_start = round_down(pos, block_size);
> > @@ -640,8 +650,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
> >                       if (iter->flags & IOMAP_NOWAIT)
> >                               return -EAGAIN;
> >
> > -                     status = iomap_read_folio_sync(block_start, folio,
> > -                                     poff, plen, srcmap);
> > +                     status = iomap_read_folio_sync(iter, block_start, folio,
> > +                                                    poff, plen);
> >                       if (status)
> >                               return status;
> >               }
> > diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> > index dbbf217eb03f..e748aeebe1a5 100644
> > --- a/include/linux/iomap.h
> > +++ b/include/linux/iomap.h
> > @@ -175,6 +175,16 @@ struct iomap_folio_ops {
> >        * locked by the iomap code.
> >        */
> >       bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap);
> > +
> > +     /*
> > +      * Required for IOMAP_IN_MEM iomaps. Otherwise optional if the caller
> > +      * wishes to handle reading in a folio.
> > +      *
> > +      * The read must be done synchronously.
> > +      */
> > +     int (*read_folio_sync)(loff_t block_start, struct folio *folio,
> > +                            size_t off, size_t len, const struct iomap *iomap,
> > +                            void *private);
> >  };
> >
> >  /*
> > --
> > 2.47.1
> >
> >





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux