[Devel] [PATCH RH7 5/9] mm/memcg: fix refcount error while moving and swapping
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Wed Jul 5 09:39:48 MSK 2023
From: Hugh Dickins <hughd at google.com>
It was hard to keep a test running, moving tasks between memcgs with
move_charge_at_immigrate, while swapping: mem_cgroup_id_get_many()'s
refcount is discovered to be 0 (supposedly impossible), so it is then
forced to REFCOUNT_SATURATED, and after thousands of warnings in quick
succession, the test is at last put out of misery by being OOM killed.
This is because of the way moved_swap accounting was saved up until the
task move gets completed in __mem_cgroup_clear_mc(), deferred from when
mem_cgroup_move_swap_account() actually exchanged old and new ids.
Concurrent activity can free up swap quicker than the task is scanned,
bringing id refcount down 0 (which should only be possible when
offlining).
Just skip that optimization: do that part of the accounting immediately.
Fixes: 615d66c37c75 ("mm: memcontrol: fix memcg id ref counter on swap charge move")
Signed-off-by: Hugh Dickins <hughd at google.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Reviewed-by: Alex Shi <alex.shi at linux.alibaba.com>
Cc: Johannes Weiner <hannes at cmpxchg.org>
Cc: Alex Shi <alex.shi at linux.alibaba.com>
Cc: Shakeel Butt <shakeelb at google.com>
Cc: Michal Hocko <mhocko at suse.com>
Cc: <stable at vger.kernel.org>
Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2007071431050.4726@eggly.anvils
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
https://jira.vzint.dev/browse/PSBM-147036
(cherry picked from commit 8d22a9351035ef2ff12ef163a1091b8b8cf1e49c)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
mm/memcontrol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 8b78c7c8d3e3..8c14585f5e86 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -7465,7 +7465,6 @@ static void __mem_cgroup_clear_mc(void)
page_counter_uncharge(&mc.to->memory, mc.moved_swap);
}
- mem_cgroup_id_get_many(mc.to, mc.moved_swap);
mc.moved_swap = 0;
}
@@ -7625,7 +7624,8 @@ put: /* get_mctgt_type() gets the page */
ent = target.ent;
if (!mem_cgroup_move_swap_account(ent, mc.from, mc.to)) {
mc.precharge--;
- /* we fixup refcnts and charges later. */
+ mem_cgroup_id_get_many(mc.to, 1);
+ /* we fixup other refcnts and charges later. */
mc.moved_swap++;
}
break;
--
2.40.1
More information about the Devel
mailing list