Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: start background writeback based on per-wb threshold for strictlimit BDIs

The proactive nr_dirty > gdtc->bg_thresh check in balance_dirty_pages()
only checks the global dirty threshold to start background writeback while
the writer is still free-running, but for strictlimit BDIs (eg fuse), the
per-wb dirty count can exceed the per-wb background threshold while the
global threshold is not yet exceeded, so background writeback for this
case never gets proactively started.

Add a per-wb threshold check for strictlimit BDIs so that background
writeback is started when wb_dirty exceeds wb_bg_thresh, which drains
dirty pages before the writer hits the throttle wall, matching the
proactive behavior that the global check provides for non-strictlimit
BDIs.

fio runs on fuse show about a 3-4% improvement in perf for buffered
writes:
fio --name=writeback_test --ioengine=psync --rw=write --bs=128k \
--size=2G --numjobs=4 --ramp_time=10 --runtime=20 \
--time_based --group_reporting=1 --direct=0

Link: https://lore.kernel.org/20260326234629.840938-2-joannelkoong@gmail.com
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Joanne Koong and committed by
Andrew Morton
04379068 9ec95329

+6 -10
+6 -10
mm/page-writeback.c
··· 1835 1835 balance_domain_limits(mdtc, strictlimit); 1836 1836 } 1837 1837 1838 - if (nr_dirty > gdtc->bg_thresh && !writeback_in_progress(wb)) 1838 + if (!writeback_in_progress(wb) && 1839 + (nr_dirty > gdtc->bg_thresh || 1840 + (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh))) 1839 1841 wb_start_background_writeback(wb); 1840 1842 1841 1843 /* ··· 1864 1862 * Unconditionally start background writeback if it's not 1865 1863 * already in progress. We need to do this because the global 1866 1864 * dirty threshold check above (nr_dirty > gdtc->bg_thresh) 1867 - * doesn't account for these cases: 1868 - * 1869 - * a) strictlimit BDIs: throttling is calculated using per-wb 1870 - * thresholds. The per-wb threshold can be exceeded even when 1871 - * nr_dirty < gdtc->bg_thresh 1872 - * 1873 - * b) memcg-based throttling: memcg uses its own dirty count and 1874 - * thresholds and can trigger throttling even when global 1875 - * nr_dirty < gdtc->bg_thresh 1865 + * doesn't account for the memcg-based throttling case. memcg 1866 + * uses its own dirty count and thresholds and can trigger 1867 + * throttling even when global nr_dirty < gdtc->bg_thresh 1876 1868 * 1877 1869 * Writeback needs to be started else the writer stalls in the 1878 1870 * throttle loop waiting for dirty pages to be written back