Commit 609838cf authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

mm: invoke oom-killer from remaining unconverted page fault handlers

A few remaining architectures directly kill the page faulting task in an
out of memory situation.  This is usually not a good idea since that
task might not even use a significant amount of memory and so may not be
the optimal victim to resolve the situation.

Since 2.6.29's 1c0fe6e3 ("mm: invoke oom-killer from page fault") there
is a hook that architecture page fault handlers are supposed to call to
invoke the OOM killer and let it pick the right task to kill.  Convert
the remaining architectures over to this hook.

To have the previous behavior of simply taking out the faulting task the
vm.oom_kill_allocating_task sysctl can be set to 1.
Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Reviewed-by: default avatarMichal Hocko <mhocko@suse.cz>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Acked-by: Vineet Gupta <vgupta@synopsys.com>   [arch/arc bits]
Cc: James Hogan <james.hogan@imgtec.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Chen Liqin <liqin.chen@sunplusct.com>
Cc: Lennox Wu <lennox.wu@gmail.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 54f72fe0
...@@ -207,8 +207,10 @@ void do_page_fault(struct pt_regs *regs, unsigned long address) ...@@ -207,8 +207,10 @@ void do_page_fault(struct pt_regs *regs, unsigned long address)
} }
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
if (user_mode(regs)) if (user_mode(regs)) {
do_group_exit(SIGKILL); /* This will never return */ pagefault_out_of_memory();
return;
}
goto no_context; goto no_context;
......
...@@ -224,8 +224,10 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -224,8 +224,10 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,
*/ */
out_of_memory: out_of_memory:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
if (user_mode(regs)) if (user_mode(regs)) {
do_group_exit(SIGKILL); pagefault_out_of_memory();
return 1;
}
no_context: no_context:
/* Are we prepared to handle this kernel fault? */ /* Are we prepared to handle this kernel fault? */
......
...@@ -345,9 +345,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long fault_code, ...@@ -345,9 +345,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long fault_code,
*/ */
out_of_memory: out_of_memory:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
printk(KERN_ALERT "VM: killing process %s\n", tsk->comm); if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR) {
if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR) pagefault_out_of_memory();
do_exit(SIGKILL); return;
}
goto no_context; goto no_context;
do_sigbus: do_sigbus:
......
...@@ -267,10 +267,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -267,10 +267,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long address,
__asm__ __volatile__("l.nop 1"); __asm__ __volatile__("l.nop 1");
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
printk("VM: killing process %s\n", tsk->comm); if (!user_mode(regs))
if (user_mode(regs)) goto no_context;
do_exit(SIGKILL); pagefault_out_of_memory();
goto no_context; return;
do_sigbus: do_sigbus:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
......
...@@ -172,10 +172,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, ...@@ -172,10 +172,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
goto survive; goto survive;
} }
printk("VM: killing process %s\n", tsk->comm); if (!user_mode(regs))
if (user_mode(regs)) goto no_context;
do_group_exit(SIGKILL); pagefault_out_of_memory();
goto no_context; return;
do_sigbus: do_sigbus:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
......
...@@ -573,10 +573,10 @@ static int handle_page_fault(struct pt_regs *regs, ...@@ -573,10 +573,10 @@ static int handle_page_fault(struct pt_regs *regs,
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
goto survive; goto survive;
} }
pr_alert("VM: killing process %s\n", tsk->comm); if (is_kernel_mode)
if (!is_kernel_mode) goto no_context;
do_group_exit(SIGKILL); pagefault_out_of_memory();
goto no_context; return 0;
do_sigbus: do_sigbus:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment