Skip to content

Commit dec3a7b

Browse files
Christoph Hellwigbrauner
authored andcommitted
iomap: move the iomap_sector sector calculation out of iomap_add_to_ioend
The calculation in iomap_sector is pretty trivial and most of the time iomap_add_to_ioend only callers either iomap_can_add_to_ioend or iomap_alloc_ioend from a single invocation. Calculate the sector in the two lower level functions and stop passing it from iomap_add_to_ioend and update the iomap_alloc_ioend argument passing order to match that of iomap_add_to_ioend. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20231207072710.176093-9-hch@lst.de Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 7edfc61 commit dec3a7b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

fs/iomap/buffered-io.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,17 +1656,16 @@ iomap_submit_ioend(struct iomap_writepage_ctx *wpc, struct iomap_ioend *ioend,
16561656
return 0;
16571657
}
16581658

1659-
static struct iomap_ioend *
1660-
iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc,
1661-
loff_t offset, sector_t sector, struct writeback_control *wbc)
1659+
static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
1660+
struct writeback_control *wbc, struct inode *inode, loff_t pos)
16621661
{
16631662
struct iomap_ioend *ioend;
16641663
struct bio *bio;
16651664

16661665
bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS,
16671666
REQ_OP_WRITE | wbc_to_write_flags(wbc),
16681667
GFP_NOFS, &iomap_ioend_bioset);
1669-
bio->bi_iter.bi_sector = sector;
1668+
bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
16701669
wbc_init_bio(wbc, bio);
16711670

16721671
ioend = container_of(bio, struct iomap_ioend, io_inline_bio);
@@ -1675,9 +1674,9 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc,
16751674
ioend->io_flags = wpc->iomap.flags;
16761675
ioend->io_inode = inode;
16771676
ioend->io_size = 0;
1678-
ioend->io_offset = offset;
1677+
ioend->io_offset = pos;
16791678
ioend->io_bio = bio;
1680-
ioend->io_sector = sector;
1679+
ioend->io_sector = bio->bi_iter.bi_sector;
16811680

16821681
wpc->nr_folios = 0;
16831682
return ioend;
@@ -1705,18 +1704,17 @@ iomap_chain_bio(struct bio *prev)
17051704
return new;
17061705
}
17071706

1708-
static bool
1709-
iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t offset,
1710-
sector_t sector)
1707+
static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos)
17111708
{
17121709
if ((wpc->iomap.flags & IOMAP_F_SHARED) !=
17131710
(wpc->ioend->io_flags & IOMAP_F_SHARED))
17141711
return false;
17151712
if (wpc->iomap.type != wpc->ioend->io_type)
17161713
return false;
1717-
if (offset != wpc->ioend->io_offset + wpc->ioend->io_size)
1714+
if (pos != wpc->ioend->io_offset + wpc->ioend->io_size)
17181715
return false;
1719-
if (sector != bio_end_sector(wpc->ioend->io_bio))
1716+
if (iomap_sector(&wpc->iomap, pos) !=
1717+
bio_end_sector(wpc->ioend->io_bio))
17201718
return false;
17211719
/*
17221720
* Limit ioend bio chain lengths to minimise IO completion latency. This
@@ -1737,14 +1735,13 @@ static void iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
17371735
struct inode *inode, loff_t pos, struct list_head *iolist)
17381736
{
17391737
struct iomap_folio_state *ifs = folio->private;
1740-
sector_t sector = iomap_sector(&wpc->iomap, pos);
17411738
unsigned len = i_blocksize(inode);
17421739
size_t poff = offset_in_folio(folio, pos);
17431740

1744-
if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, pos, sector)) {
1741+
if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, pos)) {
17451742
if (wpc->ioend)
17461743
list_add(&wpc->ioend->io_list, iolist);
1747-
wpc->ioend = iomap_alloc_ioend(inode, wpc, pos, sector, wbc);
1744+
wpc->ioend = iomap_alloc_ioend(wpc, wbc, inode, pos);
17481745
}
17491746

17501747
if (!bio_add_folio(wpc->ioend->io_bio, folio, len, poff)) {

0 commit comments

Comments
 (0)