Skip to content

Commit 4e923d6

Browse files
adam900710kdave
authored andcommitted
btrfs: remove the nr_ret parameter from __extent_writepage_io()
The parameter @nr_ret is used to tell the caller how many sectors have been submitted for IO. Then callers check @nr_ret value to determine if we need to manually clear the PAGECACHE_TAG_DIRTY, as if we submitted no sector (e.g. all sectors are beyond i_size) there is no folio_start_writeback() called thus PAGECACHE_TAG_DIRTY tag will not be cleared. Remove this parameter by: - Moving the btrfs_folio_clear_writeback() call into __extent_writepage_io() So that if we didn't submit any IO, then manually call btrfs_folio_set_writeback() to clear PAGECACHE_TAG_DIRTY when the page is no longer dirty. - Use a bool to record if we have submitted any sector Instead of an int. - Use subpage compatible helpers to end folio writeback. This brings no change to the behavior, just for the sake of consistency. As for the call site inside __extent_writepage(), we're always called for the whole page, so the existing full page helper folio_(start|end)_writeback() is totally fine. For the call site inside extent_write_locked_range(), although we can have subpage range, folio_start_writeback() will only clear PAGECACHE_TAG_DIRTY if the page is no longer dirty, and the full folio will still be dirty if there is any subpage dirty range. Only when the last dirty subpage sector is cleared, the folio_start_writeback() will clear PAGECACHE_TAG_DIRTY. So no matter if we call the full page or subpage helper, the result is still the same, then just use the subpage helpers for consistency. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b55f497 commit 4e923d6

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

fs/btrfs/extent_io.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
14091409
struct folio *folio,
14101410
u64 start, u32 len,
14111411
struct btrfs_bio_ctrl *bio_ctrl,
1412-
loff_t i_size, int *nr_ret)
1412+
loff_t i_size)
14131413
{
14141414
struct btrfs_fs_info *fs_info = inode->root->fs_info;
14151415
unsigned long range_bitmap = 0;
@@ -1422,11 +1422,11 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
14221422
*/
14231423
unsigned long dirty_bitmap = 1;
14241424
unsigned int bitmap_size = 1;
1425+
bool submitted_io = false;
14251426
const u64 folio_start = folio_pos(folio);
14261427
u64 cur;
14271428
int bit;
14281429
int ret = 0;
1429-
int nr = 0;
14301430

14311431
ASSERT(start >= folio_start &&
14321432
start + len <= folio_start + folio_size(folio));
@@ -1470,20 +1470,24 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
14701470
}
14711471
ret = submit_one_sector(inode, folio, cur, bio_ctrl, i_size);
14721472
if (ret < 0)
1473-
goto out_error;
1474-
nr++;
1473+
goto out;
1474+
submitted_io = true;
14751475
}
14761476

14771477
btrfs_folio_assert_not_dirty(fs_info, folio, start, len);
1478-
*nr_ret = nr;
1479-
return 0;
1480-
1481-
out_error:
1478+
out:
14821479
/*
1483-
* If we finish without problem, we should not only clear folio dirty,
1484-
* but also empty subpage dirty bits
1480+
* If we didn't submitted any sector (>= i_size), folio dirty get
1481+
* cleared but PAGECACHE_TAG_DIRTY is not cleared (only cleared
1482+
* by folio_start_writeback() if the folio is not dirty).
1483+
*
1484+
* Here we set writeback and clear for the range. If the full folio
1485+
* is no longer dirty then we clear the PAGECACHE_TAG_DIRTY tag.
14851486
*/
1486-
*nr_ret = nr;
1487+
if (!submitted_io) {
1488+
btrfs_folio_set_writeback(fs_info, folio, start, len);
1489+
btrfs_folio_clear_writeback(fs_info, folio, start, len);
1490+
}
14871491
return ret;
14881492
}
14891493

@@ -1501,7 +1505,6 @@ static int __extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ct
15011505
struct inode *inode = folio->mapping->host;
15021506
const u64 page_start = folio_pos(folio);
15031507
int ret;
1504-
int nr = 0;
15051508
size_t pg_offset;
15061509
loff_t i_size = i_size_read(inode);
15071510
unsigned long end_index = i_size >> PAGE_SHIFT;
@@ -1532,18 +1535,13 @@ static int __extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ct
15321535
goto done;
15331536

15341537
ret = __extent_writepage_io(BTRFS_I(inode), folio, folio_pos(folio),
1535-
PAGE_SIZE, bio_ctrl, i_size, &nr);
1538+
PAGE_SIZE, bio_ctrl, i_size);
15361539
if (ret == 1)
15371540
return 0;
15381541

15391542
bio_ctrl->wbc->nr_to_write--;
15401543

15411544
done:
1542-
if (nr == 0) {
1543-
/* make sure the mapping tag for page dirty gets cleared */
1544-
folio_start_writeback(folio);
1545-
folio_end_writeback(folio);
1546-
}
15471545
if (ret) {
15481546
btrfs_mark_ordered_io_finished(BTRFS_I(inode), folio,
15491547
page_start, PAGE_SIZE, !ret);
@@ -2276,7 +2274,6 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
22762274
u64 cur_end = min(round_down(cur, PAGE_SIZE) + PAGE_SIZE - 1, end);
22772275
u32 cur_len = cur_end + 1 - cur;
22782276
struct folio *folio;
2279-
int nr = 0;
22802277

22812278
folio = __filemap_get_folio(mapping, cur >> PAGE_SHIFT, 0, 0);
22822279

@@ -2297,15 +2294,10 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
22972294
ASSERT(folio_test_dirty(folio));
22982295

22992296
ret = __extent_writepage_io(BTRFS_I(inode), folio, cur, cur_len,
2300-
&bio_ctrl, i_size, &nr);
2297+
&bio_ctrl, i_size);
23012298
if (ret == 1)
23022299
goto next_page;
23032300

2304-
/* Make sure the mapping tag for page dirty gets cleared. */
2305-
if (nr == 0) {
2306-
btrfs_folio_set_writeback(fs_info, folio, cur, cur_len);
2307-
btrfs_folio_clear_writeback(fs_info, folio, cur, cur_len);
2308-
}
23092301
if (ret) {
23102302
btrfs_mark_ordered_io_finished(BTRFS_I(inode), folio,
23112303
cur, cur_len, !ret);

0 commit comments

Comments
 (0)