From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293695; b=3e9g0LBVnpiCKJP8W6KBmGECuuehpA8mFoMiuRskjk129mInb0Bab2jEv2V44Z7EEzlm 0QdNb6OFUF3eE5qMzIn/2bKXIbb9YEQhBdOSC09Kpxj5JSjdtkzRilmXj6Tk0UV7QIbcQ jd/hSbAgwxnnB69k+14Ab9dYiVQW6EU5Iv0Hw4oHNgo9dsbzdHisA0UEIDyDKBIeyyvrf kq419cQTh+F2qTQDXYHxvBfHtoE5DEGVsCmobIEaQQQqMfrowqkzFHnV5yhSrFMy+LXWo daGAZ79WHAhAGdtyPksvP0iePioPVJeqD0ZaN53zYrDbQd9gN8ZQ6jyUGzrEyV8v48A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293695; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=gky81tF/vOEO2EmOuTd8ESpeiLcdei/Amio3O/MzHwY=; b=p1gNRV49w8S57iSlIqKc/nHHVP1TIePkPG6kHCDipQJrwUT+613gTDphNBG48or0/G5E vdBWs2ZBPYq/hOdfS/FDWaPytjm5O0Yz+jpVI4mzKEUZuge5dgFWx9ZNjqeZe3Tcbff2e w2LtWFmLocGLSDvQ1UUYsUKNmwC7U19KzFtiy9qZ2uVFAvvSpIgwIF92UbcCo6DDEzAt4 xEA1nDGQY0wSwoueDUtfUwiutBPBKXPdAZ+JSi8T/gp+Udy4qvfRPqbCmODKveyhXrBeV A/bKDNcU578DglhhPLaIqQW6jktfcLn1XU7OIk+bgd2HO3pYH34RRlOPyEJRtR0uhhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Z1PxcH7i; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0F26606A337; Thu, 3 Dec 2026 10:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Z1PxcH7i Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDA2B1F00893; Thu, 3 Dec 2026 10:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796293695; bh=gky81tF/vOEO2EmOuTd8ESpeiLcdei/Amio3O/MzHwY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Z1PxcH7ipo2UaxwXpGYiqh70U+LMnL/kVG31cO2WDQZeJkOjhtX7c4KjYNXq1Jlz9 3Xe+vOyWsMZg5fuL4LPZOHozdfrhaKW9EWoe601QzD1sN5JS128T153ycHPtyew2v8 U43yyOnplcvIv1vzTskVZK7jyzJgy9E7iru3c5smDoP2yqZJsB2YrB+gs0mkuQpWYe +EK56dRt5OtttRuQ9oQ1PNcgk/ZeWW3aj8s+VlF9jYKeJKXEeLfYWfeDH4mzqJeDrO r8n1XvdagQKX3dkSmPC6V0RJP9DrbrYyFB1pickqCX5xCia8RTJNBS/VSFgkvhiT96 f5JfHIZmuiXgg== Date: Thu, 3 Dec 2026 11:28:10 +0100 From: Carlos Maiolino To: Christoph Hellwig 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 Message-ID: References: <20261203083744.2089627-1-hch@lst.de> X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 _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 > Tested-by: Fengnan Chang > --- > 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 > 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 >