Re: [PATCH 0/2] mm, iomap: account dirty at page granularity for per-block dirty folios
From: David Hildenbrand (Arm)
Date: Tue Oct 27 2026 - 08:30:02 EST
On 10/27/26 12:27, Salvatore Dipietro wrote:
> Since iomap gained per-block dirty tracking, a large folio can be
> partially dirty: struct iomap_folio_state records exactly which
> blocks are dirty, and writeback only writes those ranges. The mm
> dirty accounting, however, still charges the whole folio even if a
> single block is dirty (up to 512x over-accounting for a 2 MB folio
> over 4 KB blocks).
>
> balance_dirty_pages() then throttles writers against a number that
> is unrelated to how much data actually needs writing back. On
> workloads that repeatedly dirty small ranges of large folios --
> e.g. PostgreSQL, which writes mostly 8/16 KB pages -- dirty_thresh
> is crossed and writers are throttled long before the real dirty data
> justifies it. On the benchmark below, run on v7.3-rc7, the
> unpatched kernel charges ~159 TB of dirtied pages while writing
> ~6 TB to the array, a factor of 27; with this series the dirtied
> pages charged match the data actually written.
>
> This series makes iomap charge and discharge the mm dirty counters
> per dirty page for folios that carry per-block dirty state, so a
> partially dirty large folio is accounted for the dirty part only:
>
> - Patch 1 adds the mm infrastructure: an AS_DIRTY_PER_BLOCK
> mapping flag, an @accounted argument to __folio_mark_dirty()
> and __filemap_dirty_folio() to skip the generic per-folio
> charge, and an address_space_operations::accounted_dirty_pages()
> callback used by the discharge and migration paths instead of
> folio_nr_pages(). No filesystem opts in, so it is a no-op on
> its own.
>
> - Patch 2 makes iomap charge per dirty page from the per-block
> dirty bitmap and wires iomap_accounted_dirty_pages() into every
> iomap-based filesystem.
>
> This was benchmarked with PostgreSQL using the pgbench simple-update
> workload on v7.3-rc7. Average throughput rises 46.8% (139.8k ->
> 205.2k tps) and run-to-run variability drops from a 23.60% to a
> 3.98% coefficient of variation: the worst iteration improves from
> 97.9k to 191.5k tps, while the best gains 8%, 199.4k -> 215.9k.
>
> Ten iterations per kernel, same database and workload (tps):
>
> Kernel Avg Min Max CV iters iters
> 1-5 6-10
> ______________________ ______ ______ ______ ______ ______ ______
> v7.3-rc7 139.8k 97.9k 199.4k 23.60% 164.4k 115.2k
> v7.3-rc7 + this series 205.2k 191.5k 215.9k 3.98% 200.1k 210.2k
>
> On unpatched v7.3-rc7 the worst iteration lands ~51% below the best,
> and throughput decays as the run progresses: iterations 6-10 average
> 30% below iterations 1-5. With this series the decay is gone -- the
> second half is similar to the first -- and the coefficient of
> variation stays at 3.98%.
>
> The over-accounting has existed since commit 4ce02c679722 ("iomap: Add
> per-block dirty state tracking to improve performance"), merged in
> v6.6, where the ifs bitmap started recording partial dirty state while
> the mm counters kept charging whole folios.
>
> The throughput collapse bisects to the v6.17 readahead series, first
> bad commit c4602f9fa77f ("mm/readahead: store folio order in struct
> file_ra_state"), which lets readahead stay at the largest folio order
> once it has ramped up, so a single dirty block charges far more than
> is written. Patch 2 therefore carries:
How does this relate to
[RFC PATCH 0/5] mm: sub-folio dirty tracking for PTE-mapped mmap writes
https://lore.kernel.org/all/20260903182943.662461-1-kirill@xxxxxxxxxxxxx/
?
I assume they try to solve different problems, but would more fine-grained folio
dirtying also make your solution benefit?
--
Cheers,
David