When a mechine has hundreds of memory cgroups, and some cgroups generate more or less dirty pages, but a cgroup of them has lots of memory pressure and always tries to reclaim dirty page, then it will trigger all cgroups to writeback, which is less efficient, since other cgroups can wait more time to merge write request. so replace the full flush with flushing writeback of memory cgroup whose tasks tries to reclaim memory and trigger writeback Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx> --- fs/fs-writeback.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index abafc9bd4622..75adf7343666 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1976,8 +1976,20 @@ static void __wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, if (!bdi_has_dirty_io(bdi)) return; - list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) - wb_start_writeback(wb, reason); + list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) { +#ifdef CONFIG_CGROUP_WRITEBACK + if (reason == WB_REASON_VMSCAN) { + struct cgroup_subsys_state *memcg_css; + + memcg_css = task_css(current, memory_cgrp_id); + if (!memcg_css->parent || memcg_css == wb->memcg_css) + wb_start_writeback(wb, reason); + } + else +#endif + wb_start_writeback(wb, reason); + + } } void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, -- 2.16.2