diff options
author | David Rientjes <rientjes@google.com> | 2010-08-09 20:18:48 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-09 23:44:56 -0400 |
commit | 7b98c2e402eaa1f2beec18b1bde17f74948a19db (patch) | |
tree | a0d3920f84e981cca5be386e2cc5a6320c4d8bdc /mm/oom_kill.c | |
parent | c81fac5cb8c92b8b4795ac250a46c7514d1fce06 (diff) |
oom: give current access to memory reserves if it has been killed
It's possible to livelock the page allocator if a thread has mm->mmap_sem
and fails to make forward progress because the oom killer selects another
thread sharing the same ->mm to kill that cannot exit until the semaphore
is dropped.
The oom killer will not kill multiple tasks at the same time; each oom
killed task must exit before another task may be killed. Thus, if one
thread is holding mm->mmap_sem and cannot allocate memory, all threads
sharing the same ->mm are blocked from exiting as well. In the oom kill
case, that means the thread holding mm->mmap_sem will never free
additional memory since it cannot get access to memory reserves and the
thread that depends on it with access to memory reserves cannot exit
because it cannot acquire the semaphore. Thus, the page allocators
livelocks.
When the oom killer is called and current happens to have a pending
SIGKILL, this patch automatically gives it access to memory reserves and
returns. Upon returning to the page allocator, its allocation will
hopefully succeed so it can quickly exit and free its memory. If not, the
page allocator will fail the allocation if it is not __GFP_NOFAIL.
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/oom_kill.c')
-rw-r--r-- | mm/oom_kill.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 907e2c0ad7a6..64cdacad83d9 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -645,6 +645,16 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, | |||
645 | /* Got some memory back in the last second. */ | 645 | /* Got some memory back in the last second. */ |
646 | return; | 646 | return; |
647 | 647 | ||
648 | /* | ||
649 | * If current has a pending SIGKILL, then automatically select it. The | ||
650 | * goal is to allow it to allocate so that it may quickly exit and free | ||
651 | * its memory. | ||
652 | */ | ||
653 | if (fatal_signal_pending(current)) { | ||
654 | set_thread_flag(TIF_MEMDIE); | ||
655 | return; | ||
656 | } | ||
657 | |||
648 | if (sysctl_panic_on_oom == 2) { | 658 | if (sysctl_panic_on_oom == 2) { |
649 | dump_header(NULL, gfp_mask, order, NULL); | 659 | dump_header(NULL, gfp_mask, order, NULL); |
650 | panic("out of memory. Compulsory panic_on_oom is selected.\n"); | 660 | panic("out of memory. Compulsory panic_on_oom is selected.\n"); |