oom, suspend: fix oom_reaper vs. oom_killer_disable race
Subsystems (3)
PATCH 1/1 oom, suspend: fix oom_reaper vs. oom_killer_disable race
From: Michal Hocko <[email protected]>
Tetsuo has reported the following potential oom_killer_disable vs. oom_reaper race:
(1) freeze_processes() starts freezing user space threads.
(2) Somebody (maybe a kenrel thread) calls out_of_memory().
(3) The OOM killer calls mark_oom_victim() on a user space thread P1 which is already in __refrigerator().
(4) oom_killer_disable() sets oom_killer_disabled = true.
(5) P1 leaves __refrigerator() and enters do_exit().
(6) The OOM reaper calls exit_oom_victim(P1) before P1 can call
exit_oom_victim(P1).
(7) oom_killer_disable() returns while P1 not yet finished
(8) P1 perform IO/interfere with the freezer.
This situation is unfortunate. We cannot move oom_killer_disable after all the freezable kernel threads are frozen because the oom victim might depend on some of those kthreads to make a forward progress to exit so we could deadlock. It is also far from trivial to teach the oom_reaper to not call exit_oom_victim() because then we would lose a guarantee of the OOM killer and oom_killer_disable forward progress because exit_mm->mmput might block and never call exit_oom_victim.
It seems the easiest way forward is to workaround this race by calling try_to_freeze_tasks again after oom_killer_disable. This will make sure that all the tasks are frozen or it bails out.
---
Hi,
this is a temporal fix that is easy enough for the current 4.7 cycle. Even though I suspect PM suspend race with the OOM killer is super unlikely it is better to not risk it considering the patch is quite trivial. I plan to come up with a proper solution later on after some other OOM killer/reaper changes settle down. It is really desirable that oom_killer_disable() is a full "barrier" rather than working around potential issues.
So if this looks like a proper fix to you Rafael I would route this via Andrew. What do you think?
kernel/power/process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
kernel/power/process.c +12 -0
@@ -146,6 +146,18 @@ int freeze_processes(void)if (!error && !oom_killer_disable ()) error = -EBUSY ; +/* +* There is a hard to fix race between oom_reaper kernel thread +* and oom_killer_disable. oom_reaper calls exit_oom_victim +* before the victim reaches exit_mm so try to freeze all the tasks +* again and catch such a left over task. +*/ +if (!error) { +pr_info ("Double checking all user space processes after OOM killer disable... " ); + error =try_to_freeze_tasks (true); +pr_cont ("\n" ); + } +if (error)thaw_processes ();return error;
Signature · 7 lines
2.8.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>