From 2ae4bb582a7086711ee658c8133d35ba4053d225 Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Wed, 30 Oct 2024 06:17:51 +0000 Subject: [PATCH 1/2] mm: memcg: don't periodically flush stats when memcg is disabled mainline inclusion from mainline-v6.9-rc1 commit 13ef7424577ff9b663aeaa4fda67e186d9856df3 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IB0CT3 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=13ef7424577ff9b663aeaa4fda67e186d9856df3 ---------------------------------------------------------------------- The root memcg is onlined even when memcg is disabled. When it's onlined a 2 second periodic stat flush is started, but no stat flushing is required when memcg is disabled because there can be no child memcgs. Most calls to flush memcg stats are avoided when memcg is disabled as a result of the mem_cgroup_disabled check added in 7d7ef0a4686a ("mm: memcg: restore subtree stats flushing"), but the periodic flushing started in mem_cgroup_css_online is not. Skip it. Link: https://lkml.kernel.org/r/20240126211927.1171338-1-tjmercier@google.com Fixes: aa48e47e3906 ("memcg: infrastructure to flush memcg stats") Signed-off-by: T.J. Mercier Acked-by: Shakeel Butt Acked-by: Johannes Weiner Acked-by: Chris Li Reported-by: Minchan Kim Reviewed-by: Yosry Ahmed Cc: Michal Hocko Cc: Muchun Song Cc: Roman Gushchin Cc: Michal Koutn Signed-off-by: Andrew Morton Signed-off-by: Chen Ridong --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6675f98296d2..cd9bd7dd149d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6661,7 +6661,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) if (alloc_shrinker_info(memcg)) goto offline_kmem; - if (unlikely(mem_cgroup_is_root(memcg))) + if (unlikely(mem_cgroup_is_root(memcg)) && !mem_cgroup_disabled()) queue_delayed_work(system_unbound_wq, &stats_flush_dwork, FLUSH_TIME); lru_gen_online_memcg(memcg); -- Gitee From 1fa38ca8efa6a3300b0d280df0d61c71bd704004 Mon Sep 17 00:00:00 2001 From: Shakeel Butt Date: Wed, 30 Oct 2024 06:17:52 +0000 Subject: [PATCH 2/2] mm: writeback: ratelimit stat flush from mem_cgroup_wb_stats mainline inclusion from mainline-v6.9-rc1 commit d9b3ce8769e371554a669f262bbc61c02a40efcc category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IB0CT3 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d9b3ce8769e371554a669f262bbc61c02a40efcc ---------------------------------------------------------------------- One of our workloads (Postgres 14) has regressed when migrated from 5.10 to 6.1 upstream kernel. The regression can be reproduced by sysbench's oltp_write_only benchmark. It seems like the always on rstat flush in mem_cgroup_wb_stats() is causing the regression. So, rate limit that specific rstat flush. One potential consequence would be the dirty throttling might be decided on stale memcg stats. However from our benchmarks and production traffic we have not observed any change in the dirty throttling behavior of the application. Link: https://lkml.kernel.org/r/20240118184235.618164-1-shakeelb@google.com Fixes: 2d146aa3aa84 ("mm: memcontrol: switch to rstat") Signed-off-by: Shakeel Butt Acked-by: Johannes Weiner Acked-by: Roman Gushchin Cc: Jan Kara Cc: Jens Axboe Cc: Michal Hocko Cc: Muchun Song Cc: Tejun Heo Signed-off-by: Andrew Morton Conflicts: mm/memcontrol.c [patch set:mm: memcg: restore subtree stats flushing was not merged, kabi is changed if merge this patchset] Signed-off-by: Chen Ridong --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cd9bd7dd149d..9bc081962934 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5398,7 +5398,7 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, struct mem_cgroup *memcg = mem_cgroup_from_css(wb->memcg_css); struct mem_cgroup *parent; - mem_cgroup_flush_stats(); + mem_cgroup_flush_stats_ratelimited(); *pdirty = memcg_page_state(memcg, NR_FILE_DIRTY); *pwriteback = memcg_page_state(memcg, NR_WRITEBACK); -- Gitee