Re: [PATCH 2/5] btrfs: unify folio dirty flag clearing

Qu Wenruo <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <[email protected]>

在 2026/5/7 14:59, Qu Wenruo 写道:
> Currently during folio writeback, we call folio_clear_dirty_for_io()
> before extent_writepage(), which causes folio dirty flag to be cleared,
> but without touching the subpage bitmaps.
> 
> This works fine for the bio submission path, as we always call
> btrfs_folio_clear_dirty() to clear the subpage bitmap.
> 
> But this is far from consistent, thus this patch is going to unify the
> behavior to always use btrfs_folio_clear_dirty() helper to clear both
> folio flag and subpage bitmap.
> 
> This involves:
> 
> - Replace folio_clear_dirty_for_io() with folio_test_dirty()
>    There is only one call site calling folio_clear_dirty_for_io() outside
>    of subpage.c, that's inside extent_write_cache_pages() just before
>    extent_writepage().
> 
[...]
> @@ -2585,7 +2596,7 @@ static int extent_write_cache_pages(struct address_space *mapping,
>   			}
>   
>   			if (folio_test_writeback(folio) ||
> -			    !folio_clear_dirty_for_io(folio)) {
> +			    !folio_test_dirty(folio)) {

This is causing regression related to cachestat() reporting.

On 64K page sized systems, even if we have written back all dirty pages, 
the xarray will still have PAGECACHE_TAG_DIRTY for the folio.

Normally that tag is cleared when calling folio_start_writeback() on a 
non-dirty folio, but it still looks like something is missing between 
clearing the last dirty block and submitting the last dirty block.

Will try to figure out the root cause and get it fixed.

But if the root fix doesn't come in time, I'd revert this only line to 
get the regression fixed first.

Thanks,
Qu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.