Re: [PATCH v7 2/3] mm: track DONTCACHE dirty pages per bdi_writeback

From: IBM

Date: Tue May 12 2026 - 22:16:28 EST


Jeff Layton <jlayton@xxxxxxxxxx> writes:

> Add a per-wb WB_DONTCACHE_DIRTY counter that tracks the number of dirty
> pages with the dropbehind flag set (i.e., pages dirtied via RWF_DONTCACHE
> writes).
>
> Increment the counter alongside WB_RECLAIMABLE in folio_account_dirtied()
> when the folio has the dropbehind flag set, and decrement it in
> folio_clear_dirty_for_io() and folio_account_cleaned(). Also decrement it
> when a non-DONTCACHE lookup atomically clears the dropbehind flag on a
> dirty folio in __filemap_get_folio_mpol(), using folio_test_clear_dropbehind()
> to prevent concurrent lookups from double-decrementing the counter, and
> guarding the decrement with mapping_can_writeback() to match the increment
> path.
>
> Transfer the counter alongside WB_RECLAIMABLE in inode_do_switch_wbs() so
> that the stat is properly migrated when an inode switches cgroup writeback
> domains.
>
> The counter will be used by the writeback flusher to determine how many
> pages to write back when expediting writeback for IOCB_DONTCACHE writes,
> without flushing the entire BDI's dirty pages.
>

Using wb_stat infra was a clever thing to do for counting the number of
dontcache folios.
I see that we don't collect DONTCACHE stats in collect_wb_stats(), which
I guess, is mainly for debug purposes only. Either ways I am not sure
how useful that might be, since it only shows the approximate stats
since it doesn't do wb_stat_sum() for most of the other stats too.
If for any reason we need that in future, that could go in a separate patch.

For this patch - LGTM. Please feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>