iomap: don't use iomap_iter for simple dio reads
Subsystems (4)
PATCH 1/1 iomap: don't use iomap_iter for simple dio reads
Simple dio reads do not use the iter model, instead they only support a one-time mapping. Removing the relatively larger iomap_iter and 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.
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).
--- 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(-)
fs/ext4/ext4.h +0 -3
@@ -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) {/*
fs/ext4/file.c +38 -1
@@ -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);
fs/ext4/inode.c +1 -2
@@ -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;
fs/iomap/direct-io.c +14 -12
@@ -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);
fs/xfs/xfs_file.c +48 -1
61 lines not on this page · raw message
fs/xfs/xfs_iomap.c +1 -1
@@ -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,
fs/xfs/xfs_iomap.h +0 -4
@@ -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);
include/linux/iomap.h +18 -19
@@ -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
Signature · 1 line
2.53.0
Quoted 2 lines · Christoph Hellwig
Simple dio reads do not use the iter model, instead they only support a one-time mapping. Removing the relatively larger
iomap_iterand
Remove?
Quoted 5 lines
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.
Quoted 6 lines
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:
Quoted 7 lines
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...
fs/iomap/direct-io.c static void iomap_dio_simple_end_io(struct bio *bio)
Quoted 104 lines
Signed-off-by Christoph Hellwig <[email protected]>Tested-by Fengnan Chang <[email protected]>--- 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(-)fs/ext4/ext4.h +0
-3@@ -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) {/* fs/ext4/file.c +38
-1@@ -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);fs/ext4/inode.c +1
-2@@ -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;fs/iomap/direct-io.c +0
-0@@ -980,30 +980,32 @@ static void iomap_dio_simple_end_io(struct bio *bio)
This hunk fails to apply to me because...
Quoted 23 lines
fs/iomap/direct-io.c +7
-5}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;
fs/iomap/direct-io.c static void iomap_dio_simple_end_io(struct bio *bio) · line 1005
Quoted 10 lines
fs/iomap/direct-io.c +2
-2} - 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:
Quoted 214 lines
fs/iomap/direct-io.c +5
-5trace_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);fs/xfs/xfs_file.c +48
-1@@ -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 );fs/xfs/xfs_iomap.c +1
-1@@ -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,fs/xfs/xfs_iomap.h +0
-4@@ -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);include/linux/iomap.h +18
-19@@ -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 Signature · 1 line
2.53.0
Quoted 5 lines · Carlos Maiolino
Quoted 2 lines · Christoph Hellwig
Simple dio reads do not use the iter model, instead they only support a one-time mapping. Removing the relatively larger
iomap_iterandRemove?
Yeah. I've reworded the commit log a bit more as well.
Quoted 9 lines
Quoted 5 lines
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:
Quoted 6 lines
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.
I'm just enumerating the downsides. The different side of the same coin is that this now has optimized to the bones callbacks for the simple read case.
Quoted 9 lines
fs/iomap/direct-io.c static void iomap_dio_simple_end_io(struct bio *bio)
Quoted 5 lines
fs/iomap/direct-io.c +0
-0@@ -980,30 +980,32 @@ static void iomap_dio_simple_end_io(struct bio *bio)This hunk fails to apply to me because...
Quoted 7 lines
... 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
The patch requires
iomap: don't call sb_init_dio_done_wq from the simple dio read path
and I didn't think of that, sorry. I'll resend a series with both of them.