Linux EXT4 FS development
 help / color / mirror / Atom feed
* optimize iomap simple dio reads v2
@ 2026-12-04  9:10 Christoph Hellwig
  2026-12-04  9:10 ` [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path Christoph Hellwig
  2026-12-04  9:10 ` [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Hellwig @ 2026-12-04  9:10 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Theodore Ts'o, Carlos Maiolino, Fengnan Chang, linux-ext4,
	linux-xfs, linux-fsdevel

Hi all,

this series remove a bit of dead code and then optimizes the iomap
simple dio read path.

Changes since v2:
 - combine the two previously sent patches into a series
 - improve the commit log of the second patch

Diffstat:
 fs/ext4/ext4.h        |    3 ---
 fs/ext4/file.c        |   35 ++++++++++++++++++++++++++++++++++-
 fs/ext4/inode.c       |    3 +--
 fs/iomap/direct-io.c  |   33 ++++++++++++++-------------------
 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, 116 insertions(+), 50 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path
  2026-12-04  9:10 optimize iomap simple dio reads v2 Christoph Hellwig
@ 2026-12-04  9:10 ` Christoph Hellwig
  2026-12-04  9:35   ` sashiko-bot
  2026-12-04  9:10 ` [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2026-12-04  9:10 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Theodore Ts'o, Carlos Maiolino, Fengnan Chang, linux-ext4,
	linux-xfs, linux-fsdevel

Since commit bcb0d867a601 ("iomap: use bio_complete_in_task for
buffered simple dio read failures"), the simple read path doesn't
ever use the per-sb dio aio workqueue, so don't initialize it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Fengnan Chang <changfengnan@bytedance.com>
---
 fs/iomap/direct-io.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index f00b0841fdd0..0d6ce1a30b2c 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -1001,13 +1001,6 @@ ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,
 		goto out_dio_end;
 	}
 
-	if (unlikely(!iomi->inode->i_sb->s_dio_done_wq &&
-			!is_sync_kiocb(iocb))) {
-		ret = sb_init_dio_done_wq(iomi->inode->i_sb);
-		if (ret < 0)
-			goto out_dio_end;
-	}
-
 	trace_iomap_dio_rw_begin(iocb, iter, 0, 0);
 
 	bio = bio_alloc_bioset(iomi->iomap.bdev,
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads
  2026-12-04  9:10 optimize iomap simple dio reads v2 Christoph Hellwig
  2026-12-04  9:10 ` [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path Christoph Hellwig
@ 2026-12-04  9:10 ` Christoph Hellwig
  2026-12-04  9:35   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2026-12-04  9:10 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Theodore Ts'o, Carlos Maiolino, Fengnan Chang, linux-ext4,
	linux-xfs, linux-fsdevel, Carlos Maiolino

Simple dio reads do not use the iter model, but instead always map
kust a single extent without calling back into the file system at
completion time.

Given that cacheline usage and zeroing costs where one of the main
motivations behind the simple dio read code, try to optimize it by
not using the relativly large struct iomap_iter, but only a plain
undecored iomap and a hand-crafted callback.

The downside of this is a bit of code duplication for the file system
callbacks, although even that has the upside of only inlining the
smaller special-purpose version compared to the generic one.

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).

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Tested-by: Fengnan Chang <changfengnan@bytedance.com>
---
 fs/ext4/ext4.h        |  3 ---
 fs/ext4/file.c        | 35 ++++++++++++++++++++++++++++++-
 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, 116 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..1772694e3719 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -66,6 +66,39 @@ 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)
+{
+	u8 blkbits = inode->i_blkbits;
+	struct ext4_map_blocks map;
+	int ret;
+	
+	ASSERT(!(flags & ~(IOMAP_DIRECT | IOMAP_NOWAIT)));
+
+	if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK)
+		return -EINVAL;
+	if (WARN_ON_ONCE(ext4_has_inline_data(inode)))
+		return -ERANGE;
+
+	map.m_lblk = offset >> blkbits;
+	map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits,
+			  EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1;
+	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 +124,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)
 }
 
 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;
 	}
 
 	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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads
  2026-12-04  9:10 ` [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads Christoph Hellwig
@ 2026-12-04  9:35   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-04  9:35 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-ext4, tytso

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ext4: making ext4_iomap_begin() static breaks
  CONFIG_EXT4_KUNIT_TESTS builds
- [Medium] xfs: xfs_read_simple_begin() returns -ENOTBLK instead of
  -EAGAIN on NOWAIT
- [Low] iomap: iomap_dio_read_simple() comment omits uninitialized iomap
  contract
--

commit 5329ccff0d2b6f54203c2a7e79854425463b11e1
Author: Christoph Hellwig <hch@lst.de>

iomap: don't use struct iomap_iter for simple dio reads

This commit replaces struct iomap_iter in iomap_dio_read_simple() with a
plain struct iomap and a dedicated iomap_simple_begin_fn callback, adding
simple-read begin handlers in ext4 and XFS.

[ ... ]

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 07a62d8569d31..f987991b48c23 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;

[Severity: Medium]
Does making ext4_iomap_begin() static break CONFIG_EXT4_KUNIT_TESTS builds?

fs/ext4/inode.c still has EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_iomap_begin),
which expands to an extern declaration and conflicts with the static
definition.

inode_test_iomap_and_atomic_writes() in fs/ext4/inode-test.c also calls
ext4_iomap_begin() directly, so removing the prototype from fs/ext4/ext4.h
and external linkage breaks compiling and linking ext4-test.o.

[ ... ]

> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index ad1ce4f99ad88..ba46156128dfa 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;

[Severity: Medium]
Should this return -EAGAIN instead of -ENOTBLK when IOMAP_NOWAIT is set?

When extents are not yet loaded on a nonblocking direct read, returning
-ENOTBLK falls back to iomap_dio_rw(), where __iomap_dio_rw() allocates
struct iomap_dio with GFP_KERNEL before xfs_ilock_for_iomap() fails with
-EAGAIN.

Returning (flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOTBLK preserves the previous
behavior and avoids a potentially sleeping allocation on IOCB_NOWAIT.

[ ... ]

> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index 78a1b7603a4f2..6db4f005fdfc4 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;

[Severity: Low]
Could the comment above iomap_simple_begin_fn document that iomap is
uninitialized on entry?

The comment still mentions the removed iterator ("and the iterator is never
advanced") and does not state that iomap_dio_read_simple() passes an
uninitialized stack struct iomap, unlike iomap_iter.

A future caller assuming zero-initialization (e.g., omitting iomap->flags = 0)
would expose uninitialized stack memory to IOMAP_F_INTEGRITY and
IOMAP_F_ANON_WRITE checks in __iomap_dio_read_simple() and iomap_sector().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204091101.2533591-2-hch@lst.de?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path
  2026-12-04  9:10 ` [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path Christoph Hellwig
@ 2026-12-04  9:35   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-04  9:35 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-ext4, tytso

Sashiko has finished reviewing this 2-patch series:

- Patch 1: no issues found.
- Patch 2 ("iomap: don't use struct iomap_iter for simple dio reads"): 3
  potential issues (2 Medium, 1 Low)

A detailed review has been sent as a separate reply to patch 2.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204091101.2533591-2-hch@lst.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  9:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:10 optimize iomap simple dio reads v2 Christoph Hellwig
2026-12-04  9:10 ` [PATCH 1/2] iomap: don't call sb_init_dio_done_wq from the simple dio read path Christoph Hellwig
2026-12-04  9:35   ` sashiko-bot
2026-12-04  9:10 ` [PATCH 2/2] iomap: don't use struct iomap_iter for simple dio reads Christoph Hellwig
2026-12-04  9:35   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox