Skip to content

Commit 37b23e0

Browse files
kosakitorvalds
authored andcommitted
x86,mm: make pagefault killable
When an oom killing occurs, almost all processes are getting stuck at the following two points. 1) __alloc_pages_nodemask 2) __lock_page_or_retry 1) is not very problematic because TIF_MEMDIE leads to an allocation failure and getting out from page allocator. 2) is more problematic. In an OOM situation, zones typically don't have page cache at all and memory starvation might lead to greatly reduced IO performance. When a fork bomb occurs, TIF_MEMDIE tasks don't die quickly, meaning that a fork bomb may create new process quickly rather than the oom-killer killing it. Then, the system may become livelocked. This patch makes the pagefault interruptible by SIGKILL. Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Minchan Kim <minchan.kim@gmail.com> Cc: Matthew Wilcox <willy@linux.intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f62e00c commit 37b23e0

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎arch/x86/mm/fault.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
965965
struct mm_struct *mm;
966966
int fault;
967967
int write = error_code & PF_WRITE;
968-
unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
968+
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
969969
(write ? FAULT_FLAG_WRITE : 0);
970970

971971
tsk = current;
@@ -1138,6 +1138,16 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
11381138
return;
11391139
}
11401140

1141+
/*
1142+
* Pagefault was interrupted by SIGKILL. We have no reason to
1143+
* continue pagefault.
1144+
*/
1145+
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
1146+
if (!(error_code & PF_USER))
1147+
no_context(regs, error_code, address);
1148+
return;
1149+
}
1150+
11411151
/*
11421152
* Major/minor page fault accounting is only done on the
11431153
* initial attempt. If we go through a retry, it is extremely

‎include/linux/mm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ extern pgprot_t protection_map[16];
153153
#define FAULT_FLAG_MKWRITE 0x04 /* Fault was mkwrite of existing pte */
154154
#define FAULT_FLAG_ALLOW_RETRY 0x08 /* Retry fault if blocking */
155155
#define FAULT_FLAG_RETRY_NOWAIT 0x10 /* Don't drop mmap_sem and wait when retrying */
156+
#define FAULT_FLAG_KILLABLE 0x20 /* The fault task is in SIGKILL killable region */
156157

157158
/*
158159
* This interface is used by x86 PAT code to identify a pfn mapping that is

‎mm/filemap.c‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,32 @@ EXPORT_SYMBOL_GPL(__lock_page_killable);
654654
int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
655655
unsigned int flags)
656656
{
657-
if (!(flags & FAULT_FLAG_ALLOW_RETRY)) {
658-
__lock_page(page);
659-
return 1;
660-
} else {
661-
if (!(flags & FAULT_FLAG_RETRY_NOWAIT)) {
662-
up_read(&mm->mmap_sem);
657+
if (flags & FAULT_FLAG_ALLOW_RETRY) {
658+
/*
659+
* CAUTION! In this case, mmap_sem is not released
660+
* even though return 0.
661+
*/
662+
if (flags & FAULT_FLAG_RETRY_NOWAIT)
663+
return 0;
664+
665+
up_read(&mm->mmap_sem);
666+
if (flags & FAULT_FLAG_KILLABLE)
667+
wait_on_page_locked_killable(page);
668+
else
663669
wait_on_page_locked(page);
664-
}
665670
return 0;
671+
} else {
672+
if (flags & FAULT_FLAG_KILLABLE) {
673+
int ret;
674+
675+
ret = __lock_page_killable(page);
676+
if (ret) {
677+
up_read(&mm->mmap_sem);
678+
return 0;
679+
}
680+
} else
681+
__lock_page(page);
682+
return 1;
666683
}
667684
}
668685

0 commit comments

Comments
 (0)