Skip to contentSkip to conversation

arm: fault.c: Port OOM changes into do_page_fault

PATCH Superseded Kautuk Consul 2 participants 5 messages Nov 22, 2011 – Nov 23, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 arm: fault.c: Port OOM changes into do_page_fault

From: Kautuk <kautuk@ubuntu.(none)>

Commit d065bd810b6deb67d4897a14bfe21f8eb526ba99 (mm: retry page fault when blocking on disk transfer) and commit 37b23e0525d393d48a7d59f870b3bc061a30ccdb (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 ARM.

Without these changes, my ARM board encounters many hang and livelock scenarios.
After applying this patch, OOM feature performance improves according to my testing.

---
 arch/arm/mm/fault.c |   58 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 39 insertions(+), 19 deletions(-)
arch/arm/mm/fault.c +39 -19
index aa33949..4aabeae 100644
@@ -231,7 +231,7 @@ static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
 
 static int __kprobes
 __do_page_fault(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;
 	int fault;
@@ -253,18 +253,7 @@ good_area:
 		goto out;
 	}
 
-	/*
-	 * If for any reason at all we couldn't handle the fault, make
-	 * sure we exit gracefully rather than endlessly redo the fault.
-	 */
-	fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & FSR_WRITE) ? 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 handle_mm_fault(mm, vma, addr & PAGE_MASK, flags);
 
 check_stack:
 	if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr))
@@ -279,6 +268,9 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	struct task_struct *tsk;
 	struct mm_struct *mm;
 	int fault, sig, code;
+	int write = fsr & FSR_WRITE;
+	unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
+				(write ? FAULT_FLAG_WRITE : 0);
 
 	if (notify_page_fault(regs, fsr))
 		return 0;
@@ -305,6 +297,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	if (!down_read_trylock(&mm->mmap_sem)) {
 		if (!user_mode(regs) && !search_exception_tables(regs->ARM_pc))
 			goto no_context;
+retry:
 		down_read(&mm->mmap_sem);
 	} else {
 		/*
@@ -320,14 +313,41 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 #endif
 	}
 
-	fault = __do_page_fault(mm, addr, fsr, tsk);
-	up_read(&mm->mmap_sem);
+	fault = __do_page_fault(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;
+
+	/*
+	 * Major/minor page fault accounting is only done on the
+	 * initial attempt. If we go through a retry, it is extremely
+	 * likely that the page will be found in page cache at that point.
+	 */
 
 	perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
-	if (fault & VM_FAULT_MAJOR)
-		perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr);
-	else if (fault & VM_FAULT_MINOR)
-		perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, addr);
+	if (flags & FAULT_FLAG_ALLOW_RETRY) {
+		if (fault & VM_FAULT_MAJOR) {
+			tsk->maj_flt++;
+			perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
+					regs, addr);
+		} else {
+			tsk->min_flt++;
+			perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
+					regs, addr);
+		}
+		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);
 
 	/*
 	 * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR
Signature · 1 line
1.7.5.4
#1 lore raw

Please disregard this one due to the following line :
From: Kautuk <kautuk@ubuntu.(none)>

There was something wrong in my git configuration.

Quoted 128 lines · Kautuk Consul

From: Kautuk <kautuk@ubuntu.(none)>

Commit d065bd810b6deb67d4897a14bfe21f8eb526ba99 (mm: retry page fault when blocking on disk transfer) and commit 37b23e0525d393d48a7d59f870b3bc061a30ccdb (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 ARM.

Without these changes, my ARM board encounters many hang and livelock scenarios.
After applying this patch, OOM feature performance improves according to my testing.

---
?arch/arm/mm/fault.c | ? 58 ++++++++++++++++++++++++++++++++++---------------- ?1 files changed, 39 insertions(+), 19 deletions(-)

arch/arm/mm/fault.c +0 -0
index aa33949..4aabeae 100644
@@ -231,7 +231,7 @@ static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
 

?static int __kprobes
?__do_page_fault(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;
? ? ? ?int fault;

arch/arm/mm/fault.c +1 -12
@@ -253,18 +253,7 @@ good_area:
 ? ? ? ? ? ? ? ?goto out;
 ? ? ? ?}
 
- ? ? ? /*
- ? ? ? ?* If for any reason at all we couldn't handle the fault, make
- ? ? ? ?* sure we exit gracefully rather than endlessly redo the fault.
- ? ? ? ?*/
- ? ? ? fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & FSR_WRITE) ? 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 handle_mm_fault(mm, vma, addr & PAGE_MASK, flags);
 

?check_stack:
? ? ? ?if (vma->vm_flags & VM_GROWSDOWN && !expand_stack(vma, addr))

arch/arm/mm/fault.c +4 -0
@@ -279,6 +268,9 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 ? ? ? ?struct task_struct *tsk;
 ? ? ? ?struct mm_struct *mm;
 ? ? ? ?int fault, sig, code;
+ ? ? ? int write = fsr & FSR_WRITE;
+ ? ? ? unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (write ? FAULT_FLAG_WRITE : 0);
 
 ? ? ? ?if (notify_page_fault(regs, fsr))
 ? ? ? ? ? ? ? ?return 0;
@@ -305,6 +297,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 ? ? ? ?if (!down_read_trylock(&mm->mmap_sem)) {
 ? ? ? ? ? ? ? ?if (!user_mode(regs) && !search_exception_tables(regs->ARM_pc))
 ? ? ? ? ? ? ? ? ? ? ? ?goto no_context;
+retry:
 ? ? ? ? ? ? ? ?down_read(&mm->mmap_sem);
 ? ? ? ?} else {

? ? ? ? ? ? ? ?/*

arch/arm/mm/fault.c +0 -0
@@ -320,14 +313,41 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)

?#endif
? ? ? ?}

- ? ? ? fault = __do_page_fault(mm, addr, fsr, tsk);
- ? ? ? up_read(&mm->mmap_sem);
+ ? ? ? fault = __do_page_fault(mm, addr, fsr, flags, tsk);

arch/arm/mm/fault.c +13 -0
+
+ ? ? ? /* 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;
+
+ ? ? ? /*
+ ? ? ? ?* Major/minor page fault accounting is only done on the
+ ? ? ? ?* initial attempt. If we go through a retry, it is extremely
+ ? ? ? ?* likely that the page will be found in page cache at that point.
+ ? ? ? ?*/

? ? ? ?perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
- ? ? ? if (fault & VM_FAULT_MAJOR)
- ? ? ? ? ? ? ? perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr);
- ? ? ? else if (fault & VM_FAULT_MINOR)
- ? ? ? ? ? ? ? perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, addr);
+ ? ? ? if (flags & FAULT_FLAG_ALLOW_RETRY) {
+ ? ? ? ? ? ? ? if (fault & VM_FAULT_MAJOR) {
+ ? ? ? ? ? ? ? ? ? ? ? tsk->maj_flt++;
+ ? ? ? ? ? ? ? ? ? ? ? perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regs, addr);
+ ? ? ? ? ? ? ? } else {
+ ? ? ? ? ? ? ? ? ? ? ? tsk->min_flt++;
+ ? ? ? ? ? ? ? ? ? ? ? perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? regs, addr);
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? 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);

? ? ? ?/*
? ? ? ? * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR --
1.7.5.4

#2 lore raw
Quoted 4 lines · On Tue, Nov 22, 2011 at 01:33:42PM -0500, kautuk.c @samsung.com wrote:

Please disregard this one due to the following line :
From: Kautuk <kautuk@ubuntu.(none)>

There was something wrong in my git configuration.

Which is the correct one? The first?

#3 lore raw

Hi,

Quoted 8 lines · Russell King - ARM Linux
Quoted 4 lines · On Tue, Nov 22, 2011 at 01:33:42PM -0500, kautuk.c @samsung.com wrote:

Please disregard this one due to the following line :
From: Kautuk <kautuk@ubuntu.(none)>

There was something wrong in my git configuration.

Which is the correct one? ?The first?

This one is correct, i.e., this email chain you have replied to.

#4 lore raw

Sorry, this is actually the same email chain as the subject is the same.

Please review the second v5 patch not the first, i.e., the one without the "From: Kautuk <kautuk@ubuntu.(none)>" line in it.

Quoted 15 lines · On Wed, Nov 23, 2011 at 8:53 AM, kautuk.c @samsung.com…

Hi,

Quoted 8 lines · Russell King - ARM Linux
Quoted 4 lines · On Tue, Nov 22, 2011 at 01:33:42PM -0500, kautuk.c @samsung.com wrote:

Please disregard this one due to the following line :
From: Kautuk <kautuk@ubuntu.(none)>

There was something wrong in my git configuration.

Which is the correct one? ?The first?

This one is correct, i.e., this email chain you have replied to.