Skip to content

Commit 892979b

Browse files
opsiffchenhuacai
authored andcommitted
LoongArch: Try VMA lock-based page fault handling first
Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. The "ebizzy -mTRp" test on Loongson-3A6000 shows that PER_VMA_LOCK can improve the benchmark by about 17.9% (97837.7 to 115430.8). This is the LoongArch variant of "x86/mm: try VMA lock-based page fault handling first". Signed-off-by: Wentao Guan <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent c8168b4 commit 892979b

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ config LOONGARCH
6969
select ARCH_SUPPORTS_LTO_CLANG_THIN
7070
select ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS
7171
select ARCH_SUPPORTS_NUMA_BALANCING
72+
select ARCH_SUPPORTS_PER_VMA_LOCK
7273
select ARCH_SUPPORTS_RT
7374
select ARCH_USE_BUILTIN_BSWAP
7475
select ARCH_USE_CMPXCHG_LOCKREF

arch/loongarch/mm/fault.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,58 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
215215
flags |= FAULT_FLAG_USER;
216216

217217
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
218+
219+
if (!(flags & FAULT_FLAG_USER))
220+
goto lock_mmap;
221+
222+
vma = lock_vma_under_rcu(mm, address);
223+
if (!vma)
224+
goto lock_mmap;
225+
226+
if (write) {
227+
flags |= FAULT_FLAG_WRITE;
228+
if (!(vma->vm_flags & VM_WRITE)) {
229+
vma_end_read(vma);
230+
si_code = SEGV_ACCERR;
231+
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
232+
goto bad_area_nosemaphore;
233+
}
234+
} else {
235+
if (!(vma->vm_flags & VM_EXEC) && address == exception_era(regs)) {
236+
vma_end_read(vma);
237+
si_code = SEGV_ACCERR;
238+
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
239+
goto bad_area_nosemaphore;
240+
}
241+
if (!(vma->vm_flags & (VM_READ | VM_WRITE)) && address != exception_era(regs)) {
242+
vma_end_read(vma);
243+
si_code = SEGV_ACCERR;
244+
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
245+
goto bad_area_nosemaphore;
246+
}
247+
}
248+
249+
fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
250+
if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
251+
vma_end_read(vma);
252+
253+
if (!(fault & VM_FAULT_RETRY)) {
254+
count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
255+
goto done;
256+
}
257+
258+
count_vm_vma_lock_event(VMA_LOCK_RETRY);
259+
if (fault & VM_FAULT_MAJOR)
260+
flags |= FAULT_FLAG_TRIED;
261+
262+
/* Quick path to respond to signals */
263+
if (fault_signal_pending(fault, regs)) {
264+
if (!user_mode(regs))
265+
no_context(regs, write, address);
266+
return;
267+
}
268+
lock_mmap:
269+
218270
retry:
219271
vma = lock_mm_and_find_vma(mm, address, regs);
220272
if (unlikely(!vma))
@@ -276,8 +328,10 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
276328
*/
277329
goto retry;
278330
}
331+
mmap_read_unlock(mm);
332+
333+
done:
279334
if (unlikely(fault & VM_FAULT_ERROR)) {
280-
mmap_read_unlock(mm);
281335
if (fault & VM_FAULT_OOM) {
282336
do_out_of_memory(regs, write, address);
283337
return;
@@ -290,8 +344,6 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
290344
}
291345
BUG();
292346
}
293-
294-
mmap_read_unlock(mm);
295347
}
296348

297349
asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,

0 commit comments

Comments
 (0)