v1->v2: -add dtc_is_global() helper -rename "bool bg" to "include_writeback" -fold patches using domain_dirty_avail -reflow comment to 80col -Fix potential NULL deref of mdtc->dirty_exceeded This series add a lot of helpers to remove repeated code between domain and wb; dirty limit and dirty background; global domain and wb domain. The helpers also improve readability. More details can be found on respective patches. Thanks. A simple domain hierarchy is tested: global domain (> 20G) | cgroup domain1(10G) | wb1 | fio Test steps: /* make it easy to observe */ echo 300000 > /proc/sys/vm/dirty_expire_centisecs echo 3000 > /proc/sys/vm/dirty_writeback_centisecs /* create cgroup domain */ cd /sys/fs/cgroup echo "+memory +io" > cgroup.subtree_control mkdir group1 cd group1 echo 10G > memory.high echo 10G > memory.max echo $$ > cgroup.procs mkfs.ext4 -F /dev/vdb mount /dev/vdb /bdi1/ /* run fio to generate dirty pages */ fio -name test -filename=/bdi1/file -size=xxx -ioengine=libaio -bs=4K \ -iodepth=1 -rw=write -direct=0 --time_based -runtime=600 -invalidate=0 When fio size is 1G, the wb is in freerun state and dirty pages are only written back when dirty inode is expired after 30 seconds. When fio size is 2G, the dirty pages keep being written back and bandwidth of fio is limited. Kemeng Shi (8): writeback: factor out wb_bg_dirty_limits to remove repeated code writeback: add general function domain_dirty_avail to calculate dirty and avail of domain writeback: factor out domain_over_bg_thresh to remove repeated code writeback: Factor out code of freerun to remove repeated code writeback: factor out wb_dirty_freerun to remove more repeated freerun code writeback: factor out balance_domain_limits to remove repeated code writeback: factor out wb_dirty_exceeded to remove repeated code writeback: factor out balance_wb_limits to remove repeated code mm/page-writeback.c | 315 ++++++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 146 deletions(-) -- 2.30.0