mm: reinstate unconditional writeback start in balance_dirty_pages()
Subsystems (3)
v2 cover mm: reinstate unconditional writeback start in balance_dirty_pages()
Changelog
--------
v1: https://lore.kernel.org/linux-fsdevel/[email protected]/
v1 -> v2:
* fix it by bringing back the removed logic instead of the strictlimit wb check (Jan and Christoph)
Joanne Koong (1):
mm: reinstate unconditional writeback start in balance_dirty_pages()
mm/page-writeback.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
Signature · 1 line
2.52.0
PATCH v2 1/1 mm: reinstate unconditional writeback start in balance_dirty_pages()
Commit 64dd89ae01f2 ("mm/block/fs: remove laptop_mode") removed this unconditional writeback start from balance_dirty_pages():
if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb);
This logic needs to be reinstated to prevent performance regressions for strictlimited BDIs and memcg setups. The problem occurs because:
a) For strictlimited BDIs, throttling is calculated using per-wb thresholds. The per-wb threshold can be exceeded even when the global dirty threshold was not exceeded (nr_dirty < gdtc->bg_thresh)
b) For memcg-based throttling, memcg uses its own dirty count / thresholds and can trigger throttling even when the global threshold isn't exceeded
Without the unconditional writeback start, IO is throttled as it waits for dirty pages to be written back but there is no writeback running. This leads to severe stalls. On fuse, buffered write performance dropped from 1400 MiB/s to 2000 KiB/s.
Reinstate the unconditional writeback start so that writeback is guaranteed to be running whenever IO needs to be throttled.
--- mm/page-writeback.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
mm/page-writeback.c +21 -0
@@ -1858,6 +1858,27 @@ static int balance_dirty_pages(struct bdi_writeback *wb,break ; } +/* +* Unconditionally start background writeback if it's not +* already in progress. We need to do this because the global +* dirty threshold check above (nr_dirty > gdtc->bg_thresh) +* doesn't account for these cases: +* +* a) strictlimit BDIs: throttling is calculated using per-wb +* thresholds. The per-wb threshold can be exceeded even when +* nr_dirty < gdtc->bg_thresh +* +* b) memcg-based throttling: memcg uses its own dirty count and +* thresholds and can trigger throttling even when global +* nr_dirty < gdtc->bg_thresh +* +* Writeback needs to be started else the writer stalls in the +* throttle loop waiting for dirty pages to be written back +* while no writeback is running. +*/ +if (unlikely (!writeback_in_progress (wb))) +wb_start_background_writeback (wb); +mem_cgroup_flush_foreign (wb);/*
Signature · 1 line
2.52.0
Andrew Morton
maintainerQuoted 17 lines · On Thu, 26 Mar 2026 14:51:27 -0700 Joanne Koong <[email protected]> wrote:
Commit
64dd89ae01f2("mm/block/fs: removelaptop_mode") removed this unconditional writeback start frombalance_dirty_pages():if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb);This logic needs to be reinstated to prevent performance regressions for strictlimited BDIs and memcg setups. The problem occurs because:
a) For strictlimited BDIs, throttling is calculated using per-wb thresholds. The per-wb threshold can be exceeded even when the global dirty threshold was not exceeded (
nr_dirty<gdtc->bg_thresh)b) For memcg-based throttling, memcg uses its own dirty count / thresholds and can trigger throttling even when the global threshold isn't exceeded
Quoted 7 lines
Without the unconditional writeback start, IO is throttled as it waits for dirty pages to be written back but there is no writeback running. This leads to severe stalls. On fuse, buffered write performance dropped from 1400 MiB/s to 2000 KiB/s.
Reinstate the unconditional writeback start so that writeback is guaranteed to be running whenever IO needs to be throttled.
Thanks, I queued this in mm.git's mm-hotfixes-unstable branch for test and review. This starts it on the track to mainline before the 7.0 release.
I assume we want to be prompt with this because the fuse regression sounds pretty horrid.
Looks good:
Quoted 22 lines · Joanne Koong
Commit
64dd89ae01f2("mm/block/fs: removelaptop_mode") removed this unconditional writeback start frombalance_dirty_pages():if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb);This logic needs to be reinstated to prevent performance regressions for strictlimited BDIs and memcg setups. The problem occurs because:
a) For strictlimited BDIs, throttling is calculated using per-wb thresholds. The per-wb threshold can be exceeded even when the global dirty threshold was not exceeded (
nr_dirty<gdtc->bg_thresh)b) For memcg-based throttling, memcg uses its own dirty count / thresholds and can trigger throttling even when the global threshold isn't exceeded
Without the unconditional writeback start, IO is throttled as it waits for dirty pages to be written back but there is no writeback running. This leads to severe stalls. On fuse, buffered write performance dropped from 1400 MiB/s to 2000 KiB/s.
Quoted 5 lines
Reinstate the unconditional writeback start so that writeback is guaranteed to be running whenever IO needs to be throttled.
Fixes 64dd89ae01f2 ("mm/block/fs: remove laptop_mode")Signed-off-by Joanne Koong <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 39 lines
--- mm/page-writeback.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)mm/page-writeback.c +21
-0@@ -1858,6 +1858,27 @@ static int balance_dirty_pages(struct bdi_writeback *wb,break ; } +/* +* Unconditionally start background writeback if it's not +* already in progress. We need to do this because the global +* dirty threshold check above (nr_dirty > gdtc->bg_thresh) +* doesn't account for these cases: +* +* a) strictlimit BDIs: throttling is calculated using per-wb +* thresholds. The per-wb threshold can be exceeded even when +* nr_dirty < gdtc->bg_thresh +* +* b) memcg-based throttling: memcg uses its own dirty count and +* thresholds and can trigger throttling even when global +* nr_dirty < gdtc->bg_thresh +* +* Writeback needs to be started else the writer stalls in the +* throttle loop waiting for dirty pages to be written back +* while no writeback is running. +*/ +if (unlikely (!writeback_in_progress (wb))) +wb_start_background_writeback (wb); +mem_cgroup_flush_foreign (wb);/* Signature · 1 line
2.52.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 22 lines · Joanne Koong
Commit
64dd89ae01f2("mm/block/fs: removelaptop_mode") removed this unconditional writeback start frombalance_dirty_pages():if (unlikely(!writeback_in_progress(wb))) wb_start_background_writeback(wb);This logic needs to be reinstated to prevent performance regressions for strictlimited BDIs and memcg setups. The problem occurs because:
a) For strictlimited BDIs, throttling is calculated using per-wb thresholds. The per-wb threshold can be exceeded even when the global dirty threshold was not exceeded (
nr_dirty<gdtc->bg_thresh)b) For memcg-based throttling, memcg uses its own dirty count / thresholds and can trigger throttling even when the global threshold isn't exceeded
Without the unconditional writeback start, IO is throttled as it waits for dirty pages to be written back but there is no writeback running. This leads to severe stalls. On fuse, buffered write performance dropped from 1400 MiB/s to 2000 KiB/s.
Quoted 5 lines
Reinstate the unconditional writeback start so that writeback is guaranteed to be running whenever IO needs to be throttled.
Fixes 64dd89ae01f2 ("mm/block/fs: remove laptop_mode")Signed-off-by Joanne Koong <[email protected]>
Thanks for the fix. This was a combination of the old comment and my overly hasty read of the existing dirty > bg_thresh && !writeback_in_progress() block. The patch looks good to me.