Skip to content

Commit

Permalink
mm, oom: do not schedule if current has been killed
Browse files Browse the repository at this point in the history
The oom killer currently schedules away from current in an uninterruptible
sleep if it does not have access to memory reserves.  It's possible that
current was killed because it shares memory with the oom killed thread or
because it was killed by the user in the interim, however.

This patch only schedules away from current if it does not have a pending
kill, i.e.  if it does not share memory with the oom killed thread.  It's
possible that it will immediately retry its memory allocation and fail,
but it will immediately be given access to memory reserves if it calls the
oom killer again.

This prevents the delay of memory freeing when threads that share memory
with the oom killed thread get unnecessarily scheduled.

Signed-off-by: David Rientjes <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Acked-by: KOSAKI Motohiro <[email protected]>
Acked-by: KAMEZAWA Hiroyuki <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rientjes authored and torvalds committed Aug 1, 2012
1 parent 7575468 commit 4f774b9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,11 +745,11 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
read_unlock(&tasklist_lock);

/*
* Give "p" a good chance of killing itself before we
* retry to allocate memory unless "p" is current
* Give the killed threads a good chance of exiting before trying to
* allocate memory again.
*/
if (killed && !test_thread_flag(TIF_MEMDIE))
schedule_timeout_uninterruptible(1);
if (killed)
schedule_timeout_killable(1);
}

/*
Expand All @@ -764,6 +764,5 @@ void pagefault_out_of_memory(void)
out_of_memory(NULL, 0, 0, NULL, false);
clear_system_oom();
}
if (!test_thread_flag(TIF_MEMDIE))
schedule_timeout_uninterruptible(1);
schedule_timeout_killable(1);
}

0 comments on commit 4f774b9

Please sign in to comment.