Skip to content

Commit 855b018

Browse files
Michal Hockotorvalds
authored andcommitted
oom, oom_reaper: disable oom_reaper for oom_kill_allocating_task
Tetsuo has reported that oom_kill_allocating_task=1 will cause oom_reaper_list corruption because oom_kill_process doesn't follow standard OOM exclusion (aka ignores TIF_MEMDIE) and allows to enqueue the same task multiple times - e.g. by sacrificing the same child multiple times. This patch fixes the issue by introducing a new MMF_OOM_KILLED mm flag which is set in oom_kill_process atomically and oom reaper is disabled if the flag was already set. Signed-off-by: Michal Hocko <mhocko@suse.com> Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: David Rientjes <rientjes@google.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0304926 commit 855b018

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/linux/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ static inline int get_dumpable(struct mm_struct *mm)
512512
#define MMF_HAS_UPROBES 19 /* has uprobes */
513513
#define MMF_RECALC_UPROBES 20 /* MMF_HAS_UPROBES can be wrong */
514514

515+
#define MMF_OOM_KILLED 21 /* OOM killer has chosen this mm */
516+
515517
#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
516518

517519
struct sighand_struct {

mm/oom_kill.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
680680
unsigned int victim_points = 0;
681681
static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
682682
DEFAULT_RATELIMIT_BURST);
683-
bool can_oom_reap = true;
683+
bool can_oom_reap;
684684

685685
/*
686686
* If the task is already exiting, don't alarm the sysadmin or kill
@@ -742,6 +742,10 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
742742
/* Get a reference to safely compare mm after task_unlock(victim) */
743743
mm = victim->mm;
744744
atomic_inc(&mm->mm_count);
745+
746+
/* Make sure we do not try to oom reap the mm multiple times */
747+
can_oom_reap = !test_and_set_bit(MMF_OOM_KILLED, &mm->flags);
748+
745749
/*
746750
* We should send SIGKILL before setting TIF_MEMDIE in order to prevent
747751
* the OOM victim from depleting the memory reserves from the user

0 commit comments

Comments
 (0)