From: Carlos Maiolino <cem@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: brauner@kernel.org, tytso@mit.edu, changfengnan@bytedance.com,
linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] iomap: don't use iomap_iter for simple dio reads
Date: Thu, 3 Dec 2026 11:28:10 +0100 [thread overview]
Message-ID: <axFEOmV9r27thlZ3@cronus.toxiclabs.cc> (raw)
In-Reply-To: <20261203083744.2089627-1-hch@lst.de>
On Thu, Dec 03, 2026 at 09:36:40AM +0100, Christoph Hellwig wrote:
> Simple dio reads do not use the iter model, instead they only support
> a one-time mapping. Removing the relatively larger iomap_iter and
Remove?
> provide separate callbacks that directly do the read-only mapping.
> The downside of this is a bit of code duplication for the file system
> callbacks, although even that has the small upside of only inlining
> the smaller special-purpose version compared to the generic one.
If the concern is code duplication here, perhaps the duplicated
verifications could be factored out into something like:
static inline <fs>_iomap_checks() {...}
Wouldn't that still keep the special-purpose version inlined?
Not that I really care about it or that it's something for this patch,
just a future cleanup.
>
> Fengnan Chang tested this with the workloads that originally motived
> the simple dio read code, and the results are encouraging:
>
> Single-core performance improves significantly:
>
> ext4 / IOPOLL: +4.77% to +6.86%
> ext4 / IRQ: +3.51% to +7.73%
> XFS / IOPOLL: +4.77% to +12.03%
> XFS/ IRQ: +8.74% to +9.30%
>
> perf stat reports a reduction by ~201 insns/IO on ext4 (5155.6 -> 4954.2)
> and by ~365 +insns/IO on XFS (5501.7 -> 5136.7).
Cool...
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Fengnan Chang <changfengnan@bytedance.com>
> ---
> fs/ext4/ext4.h | 3 ---
> fs/ext4/file.c | 39 +++++++++++++++++++++++++++++++++-
> fs/ext4/inode.c | 3 +--
> fs/iomap/direct-io.c | 26 ++++++++++++-----------
> fs/xfs/xfs_file.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
> fs/xfs/xfs_iomap.c | 2 +-
> fs/xfs/xfs_iomap.h | 4 ----
> include/linux/iomap.h | 37 ++++++++++++++++----------------
> 8 files changed, 120 insertions(+), 43 deletions(-)
>
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index dc2c181337a1..128198ecf064 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -4371,9 +4371,6 @@ DECLARE_IOMAP_ITER_NEXT(ext4_iomap_buffered_da_write_next);
>
> extern const struct iomap_write_ops ext4_iomap_write_ops;
>
> -int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
> - unsigned flags, struct iomap *iomap, struct iomap *srcmap);
> -
> static inline int ext4_buffer_uptodate(struct buffer_head *bh)
> {
> /*
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index cfb22d0d5728..856bfb2b5654 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -66,6 +66,43 @@ static bool ext4_should_use_dio(struct kiocb *iocb, struct iov_iter *iter)
> return IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(iter), dio_align);
> }
>
> +static int ext4_simple_begin(struct inode *inode, loff_t offset, loff_t length,
> + unsigned flags, struct iomap *iomap)
> +{
> + struct ext4_map_blocks map;
> + u8 blkbits = inode->i_blkbits;
> + int ret;
> +
> + if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK)
> + return -EINVAL;
> + if (WARN_ON_ONCE(ext4_has_inline_data(inode)))
> + return -ERANGE;
> +
> + /*
> + * Calculate the first and last logical blocks respectively.
> + */
> + map.m_lblk = offset >> blkbits;
> + map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits,
> + EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1;
> +
> + ASSERT(!(flags & IOMAP_WRITE));
> +
> + ret = ext4_map_blocks(NULL, inode, &map, 0);
> + if (ret < 0)
> + return ret;
> + if ((map.m_flags & EXT4_MAP_UNWRITTEN) ||
> + !(map.m_flags & EXT4_MAP_MAPPED))
> + return -ENOTBLK;
> +
> + iomap->flags = 0;
> + iomap->type = IOMAP_MAPPED;
> + iomap->bdev = inode->i_sb->s_bdev;
> + iomap->addr = (u64)map.m_pblk << blkbits;
> + iomap->offset = EXT4_LBLK_TO_B(inode, map.m_lblk);
> + iomap->length = EXT4_LBLK_TO_B(inode, map.m_len);
> + return 0;
> +}
> +
> static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
> {
> ssize_t ret;
> @@ -91,7 +128,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
> return generic_file_read_iter(iocb, to);
> }
>
> - ret = iomap_dio_read_simple(iocb, to, ext4_iomap_begin);
> + ret = iomap_dio_read_simple(iocb, to, ext4_simple_begin);
> if (ret == -ENOTBLK)
> ret = iomap_dio_rw(iocb, to, ext4_iomap_next, NULL, 0, NULL, 0);
> inode_unlock_shared(inode);
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 07a62d8569d3..f987991b48c2 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4012,8 +4012,7 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
> return ret;
> }
>
> -
> -int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
> +static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
> unsigned flags, struct iomap *iomap, struct iomap *srcmap)
> {
> int ret;
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 0d6ce1a30b2c..6fa1ca9c30b7 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -980,30 +980,32 @@ static void iomap_dio_simple_end_io(struct bio *bio)
This hunk fails to apply to me because...
> }
>
> ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> - struct iomap_iter *iomi)
> + unsigned flags, struct iomap *iomap)
> {
> - gfp_t gfp = (iomi->flags & IOMAP_NOWAIT) ? GFP_NOWAIT : GFP_KERNEL;
> + struct inode *inode = file_inode(iocb->ki_filp);
> + size_t count = iov_iter_count(iter);
> + gfp_t gfp = (flags & IOMAP_NOWAIT) ? GFP_NOWAIT : GFP_KERNEL;
> struct iomap_dio_simple *sr;
> unsigned int alignment;
> struct bio *bio;
> ssize_t ret;
>
> - if (iomi->iomap.type != IOMAP_MAPPED ||
> - iomi->iomap.offset + iomi->iomap.length < iomi->pos + iomi->len ||
> - (iomi->iomap.flags & IOMAP_F_INTEGRITY)) {
> + if (iomap->type != IOMAP_MAPPED ||
> + iomap->offset + iomap->length < iocb->ki_pos + count ||
> + (iomap->flags & IOMAP_F_INTEGRITY)) {
> ret = -ENOTBLK;
> goto out_dio_end;
> }
>
> - alignment = iomap_dio_alignment(iomi->inode, iomi->iomap.bdev, 0);
> - if ((iomi->pos | iomi->len) & (alignment - 1)) {
> + alignment = iomap_dio_alignment(inode, iomap->bdev, 0);
> + if ((iocb->ki_pos | count) & (alignment - 1)) {
> ret = -EINVAL;
> goto out_dio_end;
> }
>
... Somehow seems the
if (unlikely(!iomi->inode->i_sb->s_dio_done_wq &&
...
}
is missing here but I'm not sure why. I tried to search in vfs
branches for something removing it but I couldn't find anything
related.
So either I missed some patch changing it or you've got
something in your branch modifying it before this patch?
Either way, except the nit-pick on the commit message, the patch
looks good to me. If it needs to be rebased or I just missed the
change somewhere, feel free to add:
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> trace_iomap_dio_rw_begin(iocb, iter, 0, 0);
>
> - bio = bio_alloc_bioset(iomi->iomap.bdev,
> + bio = bio_alloc_bioset(iomap->bdev,
> bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS),
> REQ_OP_READ, gfp, &iomap_dio_simple_pool);
> if (!bio) {
> @@ -1014,7 +1016,7 @@ ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> sr->iocb = iocb;
> sr->dio_flags = 0;
>
> - bio->bi_iter.bi_sector = iomap_sector(&iomi->iomap, iomi->pos);
> + bio->bi_iter.bi_sector = iomap_sector(iomap, iocb->ki_pos);
> bio->bi_ioprio = iocb->ki_ioprio;
>
> ret = bio_iov_iter_get_pages(bio, iter, BIO_MAX_SIZE,
> @@ -1023,7 +1025,7 @@ ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> if (unlikely(ret))
> goto out_bio_put;
>
> - if (bio->bi_iter.bi_size != iomi->len) {
> + if (bio->bi_iter.bi_size != count) {
> iov_iter_revert(iter, bio->bi_iter.bi_size);
> ret = -ENOTBLK;
> goto out_bio_release_pages;
> @@ -1049,7 +1051,7 @@ ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> }
> bio->bi_end_io = iomap_dio_simple_end_io;
> submit_bio(bio);
> - trace_iomap_dio_rw_queued(iomi->inode, iocb->ki_pos, iomi->len);
> + trace_iomap_dio_rw_queued(inode, iocb->ki_pos, count);
> return -EIOCBQUEUED;
>
> out_bio_release_pages:
> @@ -1057,7 +1059,7 @@ ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> out_bio_put:
> bio_put(bio);
> out_dio_end:
> - inode_dio_end(iomi->inode);
> + inode_dio_end(inode);
> return ret;
> }
> EXPORT_SYMBOL_GPL(__iomap_dio_read_simple);
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index ad1ce4f99ad8..ba46156128df 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -189,6 +189,53 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
> .bio_set = &iomap_ioend_bioset,
> };
>
> +static int
> +xfs_read_simple_begin(
> + struct inode *inode,
> + loff_t offset,
> + loff_t length,
> + unsigned flags,
> + struct iomap *iomap)
> +{
> + struct xfs_inode *ip = XFS_I(inode);
> + struct xfs_mount *mp = ip->i_mount;
> + xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
> + struct xfs_bmbt_irec imap;
> + struct xfs_iext_cursor icur;
> +
> + ASSERT(!(flags & ~(IOMAP_DIRECT | IOMAP_NOWAIT)));
> +
> + if (xfs_is_shutdown(mp))
> + return -EIO;
> + if (xfs_need_iread_extents(&ip->i_df))
> + return -ENOTBLK;
> +
> + if (flags & IOMAP_NOWAIT) {
> + if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
> + return -EAGAIN;
> + } else {
> + xfs_ilock(ip, XFS_ILOCK_SHARED);
> + }
> +
> + /* Hole, unwritten or dealloc? Pass. */
> + if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &icur, &imap) ||
> + imap.br_startoff > offset_fsb ||
> + imap.br_state == XFS_EXT_UNWRITTEN ||
> + isnullstartblock(imap.br_startblock)) {
> + xfs_iunlock(ip, XFS_ILOCK_SHARED);
> + return -ENOTBLK;
> + }
> + xfs_iunlock(ip, XFS_ILOCK_SHARED);
> +
> + iomap->flags = 0;
> + iomap->type = IOMAP_MAPPED;
> + iomap->addr = BBTOB(xfs_fsb_to_db(ip, imap.br_startblock));
> + iomap->offset = XFS_FSB_TO_B(mp, imap.br_startoff);
> + iomap->length = XFS_FSB_TO_B(mp, imap.br_blockcount);
> + iomap->bdev = xfs_inode_buftarg(ip)->bt_bdev;
> + return 0;
> +}
> +
> STATIC ssize_t
> xfs_file_dio_read(
> struct kiocb *iocb,
> @@ -211,7 +258,7 @@ xfs_file_dio_read(
> ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next,
> &xfs_dio_read_bounce_ops, 0, NULL, 0);
> } else {
> - ret = iomap_dio_read_simple(iocb, to, xfs_read_iomap_begin);
> + ret = iomap_dio_read_simple(iocb, to, xfs_read_simple_begin);
> if (ret == -ENOTBLK)
> ret = iomap_dio_rw(iocb, to, xfs_read_iomap_next, NULL,
> 0, NULL, 0);
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index 50eae7ff6145..08bd39294ebf 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -2201,7 +2201,7 @@ xfs_buffered_write_iomap_end(
> DEFINE_IOMAP_ITER_NEXT_END(xfs_buffered_write_iomap_next,
> xfs_buffered_write_iomap_begin, xfs_buffered_write_iomap_end);
>
> -int
> +static int
> xfs_read_iomap_begin(
> struct inode *inode,
> loff_t offset,
> diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
> index 071fff666507..975201b7aad0 100644
> --- a/fs/xfs/xfs_iomap.h
> +++ b/fs/xfs/xfs_iomap.h
> @@ -66,10 +66,6 @@ xfs_aligned_fsb_count(
> return count_fsb;
> }
>
> -int xfs_read_iomap_begin(struct inode *inode, loff_t offset,
> - loff_t length, unsigned flags, struct iomap *iomap,
> - struct iomap *srcmap);
> -
> DECLARE_IOMAP_ITER_NEXT(xfs_buffered_write_iomap_next);
> DECLARE_IOMAP_ITER_NEXT(xfs_direct_write_iomap_next);
> DECLARE_IOMAP_ITER_NEXT(xfs_zoned_direct_write_iomap_next);
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index 78a1b7603a4f..6db4f005fdfc 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -740,20 +740,20 @@ void iomap_dio_bio_end_io(struct bio *bio);
> * The caller can only provide an iomap begin handler, and the iterator
> * is never advanced.
> */
> +typedef int (*iomap_simple_begin_fn)(struct inode *inode, loff_t pos,
> + loff_t length, unsigned flags, struct iomap *iomap);
> ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
> - struct iomap_iter *iomi);
> + unsigned flags, struct iomap *iomap);
> static __always_inline ssize_t iomap_dio_read_simple(struct kiocb *iocb,
> - struct iov_iter *iter, iomap_iter_begin_fn begin)
> + struct iov_iter *iter, iomap_simple_begin_fn begin)
> {
> - struct iomap_iter iomi = {
> - .inode = file_inode(iocb->ki_filp),
> - .pos = iocb->ki_pos,
> - .len = iov_iter_count(iter),
> - .flags = IOMAP_DIRECT,
> - };
> + struct inode *inode = file_inode(iocb->ki_filp);
> + size_t count = iov_iter_count(iter);
> + unsigned flags = IOMAP_DIRECT;
> + struct iomap iomap;
> ssize_t ret;
>
> - if (!iomi.len)
> + if (!count)
> return 0;
>
> /*
> @@ -761,29 +761,28 @@ static __always_inline ssize_t iomap_dio_read_simple(struct kiocb *iocb,
> * early as it's the most common case to fail for typical direct IO
> * workloads.
> */
> - if (iomi.len > iomi.inode->i_sb->s_blocksize)
> + if (count > inode->i_sb->s_blocksize)
> return -ENOTBLK;
> - if (iocb->ki_pos + iomi.len > i_size_read(iomi.inode))
> + if (iocb->ki_pos + count > i_size_read(inode))
> return -ENOTBLK;
> - if (IS_ENCRYPTED(iomi.inode))
> + if (IS_ENCRYPTED(inode))
> return -ENOTBLK;
>
> - ret = kiocb_write_and_wait(iocb, iomi.len);
> + ret = kiocb_write_and_wait(iocb, count);
> if (ret)
> return ret;
>
> if (iocb->ki_flags & IOCB_NOWAIT)
> - iomi.flags |= IOMAP_NOWAIT;
> + flags |= IOMAP_NOWAIT;
>
> - inode_dio_begin(iomi.inode);
> - ret = begin(iomi.inode, iomi.pos, iomi.len, iomi.flags, &iomi.iomap,
> - &iomi.srcmap);
> + inode_dio_begin(inode);
> + ret = begin(inode, iocb->ki_pos, count, flags, &iomap);
> if (ret) {
> - inode_dio_end(iomi.inode);
> + inode_dio_end(inode);
> return ret;
> }
>
> - return __iomap_dio_read_simple(iocb, iter, &iomi);
> + return __iomap_dio_read_simple(iocb, iter, flags, &iomap);
> }
>
> #ifdef CONFIG_SWAP
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-12-03 10:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 8:36 [PATCH] iomap: don't use iomap_iter for simple dio reads Christoph Hellwig
2026-12-03 10:28 ` Carlos Maiolino [this message]
2026-12-04 9:04 ` Christoph Hellwig
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=axFEOmV9r27thlZ3@cronus.toxiclabs.cc \
--to=cem@kernel.org \
--cc=brauner@kernel.org \
--cc=changfengnan@bytedance.com \
--cc=hch@lst.de \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=tytso@mit.edu \
/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.