Skip to contentSkip to conversation

oom: keep mm of the killed task available

PATCH New [email protected] 1 participant 1 message Oct 8, 2016

Subsystems (5)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 41/127 oom: keep mm of the killed task available

From: Michal Hocko <[email protected]>
Subject: oom: keep mm of the killed task available

oom_reap_task has to call exit_oom_victim in order to make sure that the oom vicim will not block the oom killer for ever. This is, however, opening new problems (e.g oom_killer_disable exclusion - see 74070542099c ("oom, suspend: fix oom_reaper vs. oom_killer_disable race")). exit_oom_victim should be only called from the victim's context ideally.

One way to achieve this would be to rely on per mm_struct flags. We already have MMF_OOM_REAPED to hide a task from the oom killer since "mm, oom: hide mm which is shared with kthread or global init". The problem is that the exit path:
do_exit
exit_mm

    tsk->mm = NULL;
    mmput
      __mmput
    exit_oom_victim

doesn't guarantee that exit_oom_victim will get called in a bounded amount of time. At least exit_aio depends on IO which might get blocked due to lack of memory and who knows what else is lurking there.

This patch takes a different approach. We remember tsk->mm into the signal_struct and bind it to the signal struct life time for all oom victims. __oom_reap_task_mm as well as oom_scan_process_thread do not have to rely on find_lock_task_mm anymore and they will have a reliable reference to the mm struct. As a result all the oom specific communication inside the OOM killer can be done via tsk->signal->oom_mm.

Increasing the signal_struct for something as unlikely as the oom killer is far from ideal but this approach will make the code much more reasonable and long term we even might want to move task->mm into the signal_struct anyway. In the next step we might want to make the oom killer exclusion and access to memory reserves completely independent which would be also nice.

---

 include/linux/sched.h |    2 +
 kernel/fork.c         |    2 +
 mm/oom_kill.c         |   51 ++++++++++++++--------------------------
 3 files changed, 23 insertions(+), 32 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~oom-keep-mm-of-the-killed-task-available +2 -0
diff -puN include/linux/sched.h~oom-keep-mm-of-the-killed-task-available include/linux/sched.h
@@ -805,6 +805,8 @@ struct signal_struct {
 	short oom_score_adj;		/* OOM kill score adjustment */
 	short oom_score_adj_min;	/* OOM kill score adjustment min value.
 					 * Only settable by CAP_SYS_RESOURCE. */
+	struct mm_struct *oom_mm;	/* recorded mm when the thread group got
+					 * killed by the oom killer */
 
 	struct mutex cred_guard_mutex;	/* guard against foreign influences on
 					 * credential calculations
kernel/fork.c renamed from kernel/fork.c~oom-keep-mm-of-the-killed-task-available +2 -0
diff -puN kernel/fork.c~oom-keep-mm-of-the-killed-task-available kernel/fork.c
@@ -359,6 +359,8 @@ static inline void free_signal_struct(st
 {
 	taskstats_tgid_free(sig);
 	sched_autogroup_exit(sig);
+	if (sig->oom_mm)
+		mmdrop(sig->oom_mm);
 	kmem_cache_free(signal_cachep, sig);
 }
 
mm/oom_kill.c renamed from mm/oom_kill.c~oom-keep-mm-of-the-killed-task-available +19 -32

97 lines not on this page · raw message

_