Skip to content

Commit 9265503

Browse files
author
Matthew Wilcox (Oracle)
committed
iomap: Simplify iomap_writepage_map()
Rename end_offset to end_pos and file_offset to pos to match the rest of the file. Simplify the loop by calculating nblocks up front instead of each time around the loop. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]>
1 parent 6e47852 commit 9265503

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

fs/iomap/buffered-io.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,37 +1307,36 @@ iomap_add_to_ioend(struct inode *inode, loff_t offset, struct page *page,
13071307
static int
13081308
iomap_writepage_map(struct iomap_writepage_ctx *wpc,
13091309
struct writeback_control *wbc, struct inode *inode,
1310-
struct page *page, u64 end_offset)
1310+
struct page *page, u64 end_pos)
13111311
{
13121312
struct folio *folio = page_folio(page);
13131313
struct iomap_page *iop = iomap_page_create(inode, folio);
13141314
struct iomap_ioend *ioend, *next;
13151315
unsigned len = i_blocksize(inode);
1316-
u64 file_offset; /* file offset of page */
1316+
unsigned nblocks = i_blocks_per_folio(inode, folio);
1317+
u64 pos = folio_pos(folio);
13171318
int error = 0, count = 0, i;
13181319
LIST_HEAD(submit_list);
13191320

13201321
WARN_ON_ONCE(iop && atomic_read(&iop->write_bytes_pending) != 0);
13211322

13221323
/*
1323-
* Walk through the page to find areas to write back. If we run off the
1324-
* end of the current map or find the current map invalid, grab a new
1325-
* one.
1324+
* Walk through the folio to find areas to write back. If we
1325+
* run off the end of the current map or find the current map
1326+
* invalid, grab a new one.
13261327
*/
1327-
for (i = 0, file_offset = page_offset(page);
1328-
i < (PAGE_SIZE >> inode->i_blkbits) && file_offset < end_offset;
1329-
i++, file_offset += len) {
1328+
for (i = 0; i < nblocks && pos < end_pos; i++, pos += len) {
13301329
if (iop && !test_bit(i, iop->uptodate))
13311330
continue;
13321331

1333-
error = wpc->ops->map_blocks(wpc, inode, file_offset);
1332+
error = wpc->ops->map_blocks(wpc, inode, pos);
13341333
if (error)
13351334
break;
13361335
if (WARN_ON_ONCE(wpc->iomap.type == IOMAP_INLINE))
13371336
continue;
13381337
if (wpc->iomap.type == IOMAP_HOLE)
13391338
continue;
1340-
iomap_add_to_ioend(inode, file_offset, page, iop, wpc, wbc,
1339+
iomap_add_to_ioend(inode, pos, page, iop, wpc, wbc,
13411340
&submit_list);
13421341
count++;
13431342
}
@@ -1361,7 +1360,7 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc,
13611360
* now.
13621361
*/
13631362
if (wpc->ops->discard_folio)
1364-
wpc->ops->discard_folio(folio, file_offset);
1363+
wpc->ops->discard_folio(folio, pos);
13651364
if (!count) {
13661365
ClearPageUptodate(page);
13671366
unlock_page(page);

0 commit comments

Comments
 (0)