Skip to content

Commit f8fc887

Browse files
adam900710kdave
authored andcommitted
btrfs: clear TAG_TOWRITE from buffer tree when submitting a tree block
[POSSIBLE BUG] After commit 5e121ae ("btrfs: use buffer xarray for extent buffer writeback operations"), we have a dedicated xarray for extent buffers, and a lot of tags are migrated to that buffer tree, like PAGECACHE_TAG_TOWRITE/DIRTY/WRITEBACK. This frees us from the limits of page flags, but there is a new asymmetric behavior, we call buffer_tree_tag_for_writeback() to set PAGECACHE_TAG_TOWRITE for the involved ranges, but there is no one to clear that tag. Before that rework, we relied on the page cache tag which was cleared when folio_start_writeback() was called. Although this has its own problems (e.g. the first one calling folio_start_writeback() will clear the tag for the whole page), it at least cleared the tag. But now our real tags are stored in the buffer tree, no one is really clearing the PAGECACHE_TAG_TOWRITE tag now. [FIX] Thankfully this is not going to cause any real bug, but just some inefficiency iterating the extent buffers. As if we hit an extent buffer which is not dirty but still has the PAGECACHE_TAG_TOWRITE tag, lock_extent_buffer_for_io() will skip it so we won't writeback the extent buffer again. To properly fix the inefficiency, just clear the PAGECACHE_TAG_TOWRITE inside lock_extent_buffer_for_io(). There is no error path between lock_extent_buffer_for_io() and write_one_eb(), so we're safe to clear the tag there. Reviewed-by: Naohiro Aota <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent af6e5d2 commit f8fc887

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

fs/btrfs/extent_io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ static noinline_for_stack bool lock_extent_buffer_for_io(struct extent_buffer *e
18841884
xas_load(&xas);
18851885
xas_set_mark(&xas, PAGECACHE_TAG_WRITEBACK);
18861886
xas_clear_mark(&xas, PAGECACHE_TAG_DIRTY);
1887+
xas_clear_mark(&xas, PAGECACHE_TAG_TOWRITE);
18871888
xas_unlock_irqrestore(&xas, flags);
18881889

18891890
btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);

0 commit comments

Comments
 (0)