From 4057964cb52fcf63896afe39787b18238d74a985 Mon Sep 17 00:00:00 2001 From: Roman Gushchin Date: Sat, 10 Oct 2020 15:40:04 +0800 Subject: [PATCH] mm: drain memcg stocks on css offlining mainline inclusion from mainline-4.20-rc1 commit 591edfb10a949d635ed770c6e85ec5286206c07e category: bugfix bugzilla: 34611 CVE: NA ------------------------------------------------- Memcg charge is batched using per-cpu stocks, so an offline memcg can be pinned by a cached charge up to a moment, when a process belonging to some other cgroup will charge some memory on the same cpu. In other words, cached charges can prevent a memory cgroup from being reclaimed for some time, without any clear need. Let's optimize it by explicit draining of all stocks on css offlining. As draining is performed asynchronously, and is skipped if any parallel draining is happening, it's cheap. Link: http://lkml.kernel.org/r/20180827162621.30187-2-guro@fb.com Signed-off-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by: Michal Hocko Cc: Johannes Weiner Cc: Konstantin Khlebnikov Cc: Tejun Heo Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit 591edfb10a949d635ed770c6e85ec5286206c07e) Signed-off-by: Kefeng Wang Signed-off-by: Liu Shixin Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- mm/memcontrol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ab33121bf706..0abfd13c4015 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4727,6 +4727,8 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) memcg_offline_kmem(memcg); wb_memcg_offline(memcg); + drain_all_stock(memcg); + mem_cgroup_id_put(memcg); } -- GitLab