Skip to content

Commit 06717a7

Browse files
leitaoakpm00
authored andcommitted
memcg: always call cond_resched() after fn()
I am seeing soft lockup on certain machine types when a cgroup OOMs. This is happening because killing the process in certain machine might be very slow, which causes the soft lockup and RCU stalls. This happens usually when the cgroup has MANY processes and memory.oom.group is set. Example I am seeing in real production: [462012.244552] Memory cgroup out of memory: Killed process 3370438 (crosvm) .... .... [462037.318059] Memory cgroup out of memory: Killed process 4171372 (adb) .... [462037.348314] watchdog: BUG: soft lockup - CPU#64 stuck for 26s! [stat_manager-ag:1618982] .... Quick look at why this is so slow, it seems to be related to serial flush for certain machine types. For all the crashes I saw, the target CPU was at console_flush_all(). In the case above, there are thousands of processes in the cgroup, and it is soft locking up before it reaches the 1024 limit in the code (which would call the cond_resched()). So, cond_resched() in 1024 blocks is not sufficient. Remove the counter-based conditional rescheduling logic and call cond_resched() unconditionally after each task iteration, after fn() is called. This avoids the lockup independently of how slow fn() is. Link: https://lkml.kernel.org/r/[email protected] Fixes: ade8147 ("memcg: fix soft lockup in the OOM process") Signed-off-by: Breno Leitao <[email protected]> Suggested-by: Rik van Riel <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Michael van der Westhuizen <[email protected]> Cc: Usama Arif <[email protected]> Cc: Pavel Begunkov <[email protected]> Cc: Chen Ridong <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 113ed54 commit 06717a7

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

mm/memcontrol.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,6 @@ void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
11681168
{
11691169
struct mem_cgroup *iter;
11701170
int ret = 0;
1171-
int i = 0;
11721171

11731172
BUG_ON(mem_cgroup_is_root(memcg));
11741173

@@ -1178,10 +1177,9 @@ void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
11781177

11791178
css_task_iter_start(&iter->css, CSS_TASK_ITER_PROCS, &it);
11801179
while (!ret && (task = css_task_iter_next(&it))) {
1181-
/* Avoid potential softlockup warning */
1182-
if ((++i & 1023) == 0)
1183-
cond_resched();
11841180
ret = fn(task, arg);
1181+
/* Avoid potential softlockup warning */
1182+
cond_resched();
11851183
}
11861184
css_task_iter_end(&it);
11871185
if (ret) {

0 commit comments

Comments
 (0)