Skip to content

Commit 96f3a5c

Browse files
author
Ley Foon Tan
committed
nios2: Port OOM changes to do_page_fault()
Commit d065bd8 ("mm: retry page fault when blocking on disk transfer") and and commit 37b23e0 ("x86,mm: make pagefault killable") The above commits introduced changes into the nios2 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. Signed-off-by: Ley Foon Tan <lftan@altera.com>
1 parent ad7ef26 commit 96f3a5c

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

‎arch/nios2/mm/fault.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,
4747
struct mm_struct *mm = tsk->mm;
4848
int code = SEGV_MAPERR;
4949
int fault;
50-
unsigned int flags = 0;
50+
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
5151

5252
cause >>= 2;
5353

@@ -86,6 +86,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,
8686
if (!down_read_trylock(&mm->mmap_sem)) {
8787
if (!user_mode(regs) && !search_exception_tables(regs->ea))
8888
goto bad_area_nosemaphore;
89+
retry:
8990
down_read(&mm->mmap_sem);
9091
}
9192

@@ -132,6 +133,10 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,
132133
* the fault.
133134
*/
134135
fault = handle_mm_fault(mm, vma, address, flags);
136+
137+
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
138+
return;
139+
135140
if (unlikely(fault & VM_FAULT_ERROR)) {
136141
if (fault & VM_FAULT_OOM)
137142
goto out_of_memory;
@@ -141,10 +146,32 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,
141146
goto do_sigbus;
142147
BUG();
143148
}
144-
if (fault & VM_FAULT_MAJOR)
145-
tsk->maj_flt++;
146-
else
147-
tsk->min_flt++;
149+
150+
/*
151+
* Major/minor page fault accounting is only done on the
152+
* initial attempt. If we go through a retry, it is extremely
153+
* likely that the page will be found in page cache at that point.
154+
*/
155+
if (flags & FAULT_FLAG_ALLOW_RETRY) {
156+
if (fault & VM_FAULT_MAJOR)
157+
current->maj_flt++;
158+
else
159+
current->min_flt++;
160+
if (fault & VM_FAULT_RETRY) {
161+
/* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
162+
* of starvation. */
163+
flags &= ~FAULT_FLAG_ALLOW_RETRY;
164+
flags |= FAULT_FLAG_TRIED;
165+
166+
/*
167+
* No need to up_read(&mm->mmap_sem) as we would
168+
* have already released it in __lock_page_or_retry
169+
* in mm/filemap.c.
170+
*/
171+
172+
goto retry;
173+
}
174+
}
148175

149176
up_read(&mm->mmap_sem);
150177
return;

0 commit comments

Comments
 (0)