Re: [PATCH] ext4: cancel dirty accounting for folios without buffers
From: Jan Kara
Date: Wed Jun 24 2026 - 08:37:00 EST
On Wed 24-06-26 17:52:06, Zhu Jia wrote:
> Hi Yi,
>
> Thanks for taking a look.
>
> Yes, clearing PAGECACHE_TAG_DIRTY/TOWRITE would make the page-cache state
> cleaner. I had a version that did this by adding a helper around
> folio_cancel_dirty() and clearing the xarray tags after confirming the
> folio was still the same clean page-cache entry.
>
> It looked like this:
>
> static void ext4_cancel_dirty_folio(struct address_space *mapping,
> struct folio *folio)
> {
> XA_STATE(xas, &mapping->i_pages, folio->index);
> unsigned long flags;
>
> folio_cancel_dirty(folio);
>
> xas_lock_irqsave(&xas, flags);
> if (xas_load(&xas) == folio && !folio_test_dirty(folio)) {
> xas_clear_mark(&xas, PAGECACHE_TAG_DIRTY);
> xas_clear_mark(&xas, PAGECACHE_TAG_TOWRITE);
> }
> xas_unlock_irqrestore(&xas, flags);
> }
>
> The reason I left the tags unchanged in this version is that I was not sure
> whether it is appropriate for ext4 to open-code xarray tag cleanup directly.
>
> If you think this is the right direction, I can add the helper back and
> send a v2.
That was a good judgement! Playing with xarray tags like this in filesystem
code is certainly not a good thing. For now, I'd leave the xarray tags
dangling - they will be eventually synced with reality on next writeback
attempt. If this inconsistency of tags needs to be fixed, the fix belongs
to the generic code (so that it can be used in other places as well).
Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR