Skip to content

Commit

Permalink
oom: task->mm == NULL doesn't mean the memory was freed
Browse files Browse the repository at this point in the history
exit_mm() sets ->mm == NULL then it does mmput()->exit_mmap() which
frees the memory.

However select_bad_process() checks ->mm != NULL before TIF_MEMDIE,
so it continues to kill other tasks even if we have the oom-killed
task freeing its memory.

Change select_bad_process() to check ->mm after TIF_MEMDIE, but skip
the tasks which have already passed exit_notify() to ensure a zombie
with TIF_MEMDIE set can't block oom-killer. Alternatively we could
probably clear TIF_MEMDIE after exit_mmap().

Signed-off-by: Oleg Nesterov <[email protected]>
Reviewed-by: KOSAKI Motohiro <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Aug 2, 2011
1 parent cfe2234 commit c027a47
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
do_each_thread(g, p) {
unsigned int points;

if (!p->mm)
if (p->exit_state)
continue;
if (oom_unkillable_task(p, mem, nodemask))
continue;
Expand All @@ -319,6 +319,8 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
*/
if (test_tsk_thread_flag(p, TIF_MEMDIE))
return ERR_PTR(-1UL);
if (!p->mm)
continue;

if (p->flags & PF_EXITING) {
/*
Expand Down

0 comments on commit c027a47

Please sign in to comment.