Commit f3f09d5a authored by Kautuk Consul's avatar Kautuk Consul Committed by Guan Xuetao

unicore32/mm/fault.c: Port OOM changes to do_pf

Commit d065bd81
(mm: retry page fault when blocking on disk transfer) and
commit 37b23e05
(x86,mm: make pagefault killable)

The above commits introduced changes into the x86 pagefault handler
for making the page fault handler retryable as well as killable.

These changes reduce the mmap_sem hold time, which is crucial
during OOM killer invocation.

Port these changes to unicore32.
Signed-off-by: default avatarKautuk Consul <consul.kautuk@gmail.com>
Acked-by: default avatarGuan Xuetao <gxt@mprc.pku.edu.cn>
parent 0e4a43ed
...@@ -168,7 +168,7 @@ static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma) ...@@ -168,7 +168,7 @@ static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
} }
static int __do_pf(struct mm_struct *mm, unsigned long addr, unsigned int fsr, static int __do_pf(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
struct task_struct *tsk) unsigned int flags, struct task_struct *tsk)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
int fault; int fault;
...@@ -194,14 +194,7 @@ static int __do_pf(struct mm_struct *mm, unsigned long addr, unsigned int fsr, ...@@ -194,14 +194,7 @@ static int __do_pf(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
* If for any reason at all we couldn't handle the fault, make * If for any reason at all we couldn't handle the fault, make
* sure we exit gracefully rather than endlessly redo the fault. * sure we exit gracefully rather than endlessly redo the fault.
*/ */
fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, flags);
(!(fsr ^ 0x12)) ? FAULT_FLAG_WRITE : 0);
if (unlikely(fault & VM_FAULT_ERROR))
return fault;
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
return fault; return fault;
check_stack: check_stack:
...@@ -216,6 +209,8 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -216,6 +209,8 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
struct task_struct *tsk; struct task_struct *tsk;
struct mm_struct *mm; struct mm_struct *mm;
int fault, sig, code; int fault, sig, code;
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
((!(fsr ^ 0x12)) ? FAULT_FLAG_WRITE : 0);
tsk = current; tsk = current;
mm = tsk->mm; mm = tsk->mm;
...@@ -236,6 +231,7 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -236,6 +231,7 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
if (!user_mode(regs) if (!user_mode(regs)
&& !search_exception_tables(regs->UCreg_pc)) && !search_exception_tables(regs->UCreg_pc))
goto no_context; goto no_context;
retry:
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
} else { } else {
/* /*
...@@ -251,7 +247,28 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -251,7 +247,28 @@ static int do_pf(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
#endif #endif
} }
fault = __do_pf(mm, addr, fsr, tsk); fault = __do_pf(mm, addr, fsr, flags, tsk);
/* If we need to retry but a fatal signal is pending, handle the
* signal first. We do not need to release the mmap_sem because
* it would already be released in __lock_page_or_retry in
* mm/filemap.c. */
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
return 0;
if (!(fault & VM_FAULT_ERROR) && (flags & FAULT_FLAG_ALLOW_RETRY)) {
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
if (fault & VM_FAULT_RETRY) {
/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
* of starvation. */
flags &= ~FAULT_FLAG_ALLOW_RETRY;
goto retry;
}
}
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