diff options
author | Michel Lespinasse <walken@google.com> | 2010-10-26 17:21:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-26 19:52:09 -0400 |
commit | d065bd810b6deb67d4897a14bfe21f8eb526ba99 (patch) | |
tree | f58c59075732ec4ccba336278c9bdc7ff61bef94 /arch/x86/mm/fault.c | |
parent | b522c94da5d9cbc73f708be5e530ebc3bbd4a031 (diff) |
mm: retry page fault when blocking on disk transfer
This change reduces mmap_sem hold times that are caused by waiting for
disk transfers when accessing file mapped VMAs.
It introduces the VM_FAULT_ALLOW_RETRY flag, which indicates that the call
site wants mmap_sem to be released if blocking on a pending disk transfer.
In that case, filemap_fault() returns the VM_FAULT_RETRY status bit and
do_page_fault() will then re-acquire mmap_sem and retry the page fault.
It is expected that the retry will hit the same page which will now be
cached, and thus it will complete with a low mmap_sem hold time.
Tests:
- microbenchmark: thread A mmaps a large file and does random read accesses
to the mmaped area - achieves about 55 iterations/s. Thread B does
mmap/munmap in a loop at a separate location - achieves 55 iterations/s
before, 15000 iterations/s after.
- We are seeing related effects in some applications in house, which show
significant performance regressions when running without this change.
[akpm@linux-foundation.org: fix warning & crash]
Signed-off-by: Michel Lespinasse <walken@google.com>
Acked-by: Rik van Riel <riel@redhat.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Reviewed-by: Wu Fengguang <fengguang.wu@intel.com>
Cc: Ying Han <yinghan@google.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/x86/mm/fault.c')
-rw-r--r-- | arch/x86/mm/fault.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 852b319edbdc..9b2345c9e0c3 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c | |||
@@ -956,8 +956,10 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
956 | struct task_struct *tsk; | 956 | struct task_struct *tsk; |
957 | unsigned long address; | 957 | unsigned long address; |
958 | struct mm_struct *mm; | 958 | struct mm_struct *mm; |
959 | int write; | ||
960 | int fault; | 959 | int fault; |
960 | int write = error_code & PF_WRITE; | ||
961 | unsigned int flags = FAULT_FLAG_ALLOW_RETRY | | ||
962 | (write ? FAULT_FLAG_WRITE : 0); | ||
961 | 963 | ||
962 | tsk = current; | 964 | tsk = current; |
963 | mm = tsk->mm; | 965 | mm = tsk->mm; |
@@ -1068,6 +1070,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
1068 | bad_area_nosemaphore(regs, error_code, address); | 1070 | bad_area_nosemaphore(regs, error_code, address); |
1069 | return; | 1071 | return; |
1070 | } | 1072 | } |
1073 | retry: | ||
1071 | down_read(&mm->mmap_sem); | 1074 | down_read(&mm->mmap_sem); |
1072 | } else { | 1075 | } else { |
1073 | /* | 1076 | /* |
@@ -1111,8 +1114,6 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
1111 | * we can handle it.. | 1114 | * we can handle it.. |
1112 | */ | 1115 | */ |
1113 | good_area: | 1116 | good_area: |
1114 | write = error_code & PF_WRITE; | ||
1115 | |||
1116 | if (unlikely(access_error(error_code, write, vma))) { | 1117 | if (unlikely(access_error(error_code, write, vma))) { |
1117 | bad_area_access_error(regs, error_code, address); | 1118 | bad_area_access_error(regs, error_code, address); |
1118 | return; | 1119 | return; |
@@ -1123,21 +1124,34 @@ good_area: | |||
1123 | * make sure we exit gracefully rather than endlessly redo | 1124 | * make sure we exit gracefully rather than endlessly redo |
1124 | * the fault: | 1125 | * the fault: |
1125 | */ | 1126 | */ |
1126 | fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0); | 1127 | fault = handle_mm_fault(mm, vma, address, flags); |
1127 | 1128 | ||
1128 | if (unlikely(fault & VM_FAULT_ERROR)) { | 1129 | if (unlikely(fault & VM_FAULT_ERROR)) { |
1129 | mm_fault_error(regs, error_code, address, fault); | 1130 | mm_fault_error(regs, error_code, address, fault); |
1130 | return; | 1131 | return; |
1131 | } | 1132 | } |
1132 | 1133 | ||
1133 | if (fault & VM_FAULT_MAJOR) { | 1134 | /* |
1134 | tsk->maj_flt++; | 1135 | * Major/minor page fault accounting is only done on the |
1135 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0, | 1136 | * initial attempt. If we go through a retry, it is extremely |
1136 | regs, address); | 1137 | * likely that the page will be found in page cache at that point. |
1137 | } else { | 1138 | */ |
1138 | tsk->min_flt++; | 1139 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
1139 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0, | 1140 | if (fault & VM_FAULT_MAJOR) { |
1140 | regs, address); | 1141 | tsk->maj_flt++; |
1142 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0, | ||
1143 | regs, address); | ||
1144 | } else { | ||
1145 | tsk->min_flt++; | ||
1146 | perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0, | ||
1147 | regs, address); | ||
1148 | } | ||
1149 | if (fault & VM_FAULT_RETRY) { | ||
1150 | /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk | ||
1151 | * of starvation. */ | ||
1152 | flags &= ~FAULT_FLAG_ALLOW_RETRY; | ||
1153 | goto retry; | ||
1154 | } | ||
1141 | } | 1155 | } |
1142 | 1156 | ||
1143 | check_v8086_mode(regs, address, tsk); | 1157 | check_v8086_mode(regs, address, tsk); |