Skip to content

Commit 8496afa

Browse files
Tetsuo Handatorvalds
authored andcommitted
mm,oom_reaper: do not attempt to reap a task twice
"mm, oom_reaper: do not attempt to reap a task twice" tried to give the OOM reaper one more chance to retry using MMF_OOM_NOT_REAPABLE flag. But the usefulness of the flag is rather limited and actually never shown in practice. If the flag is set, it means that the holder of mm->mmap_sem cannot call up_write() due to presumably being blocked at unkillable wait waiting for other thread's memory allocation. But since one of threads sharing that mm will queue that mm immediately via task_will_free_mem() shortcut (otherwise, oom_badness() will select the same mm again due to oom_score_adj value unchanged), retrying MMF_OOM_NOT_REAPABLE mm is unlikely helpful. Let's always set MMF_OOM_REAPED. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Tetsuo Handa <[email protected]> Signed-off-by: Michal Hocko <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: David Rientjes <[email protected]> Cc: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7ebffa4 commit 8496afa

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

include/linux/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ static inline int get_dumpable(struct mm_struct *mm)
525525
#define MMF_HAS_UPROBES 19 /* has uprobes */
526526
#define MMF_RECALC_UPROBES 20 /* MMF_HAS_UPROBES can be wrong */
527527
#define MMF_OOM_REAPED 21 /* mm has been already reaped */
528-
#define MMF_OOM_NOT_REAPABLE 22 /* mm couldn't be reaped */
529528

530529
#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
531530

mm/oom_kill.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,11 @@ static void oom_reap_task(struct task_struct *tsk)
578578
if (attempts <= MAX_OOM_REAP_RETRIES)
579579
goto done;
580580

581+
/* Ignore this mm because somebody can't call up_write(mmap_sem). */
582+
set_bit(MMF_OOM_REAPED, &mm->flags);
583+
581584
pr_info("oom_reaper: unable to reap pid:%d (%s)\n",
582585
task_pid_nr(tsk), tsk->comm);
583-
584-
/*
585-
* If we've already tried to reap this task in the past and
586-
* failed it probably doesn't make much sense to try yet again
587-
* so hide the mm from the oom killer so that it can move on
588-
* to another task with a different mm struct.
589-
*/
590-
if (test_and_set_bit(MMF_OOM_NOT_REAPABLE, &mm->flags)) {
591-
pr_info("oom_reaper: giving up pid:%d (%s)\n",
592-
task_pid_nr(tsk), tsk->comm);
593-
set_bit(MMF_OOM_REAPED, &mm->flags);
594-
}
595586
debug_show_all_locks();
596587

597588
done:

0 commit comments

Comments
 (0)