Skip to contentSkip to conversation

riscv: mm: try VMA lock-based page fault handling first

PATCH Applied Jisheng Zhang 6 participants 9 messages May 23, 2023 – Jun 21, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: 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.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
 	select ARCH_SUPPORTS_HUGETLBFS if MMU
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
 	select ARCH_USE_MEMTEST
 	select ARCH_USE_QUEUED_RWLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +33 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
 		flags |= FAULT_FLAG_WRITE;
 	else if (cause == EXC_INST_PAGE_FAULT)
 		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
 	mmap_read_lock(mm);
 	vma = find_vma(mm, addr);
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
 	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif
 	if (unlikely(fault & VM_FAULT_ERROR)) {
 		tsk->thread.bad_cause = cause;
 		mm_fault_error(regs, addr, fault);
Signature · 1 line
2.40.1
#1 lore raw
Quoted 8 lines · Jisheng Zhang

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

Quoted 7 lines

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

PS: run ebizzy as below:
./ebizzy -mTt your_nr_cpus

Quoted 76 lines
 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
 	select ARCH_SUPPORTS_HUGETLBFS if MMU
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
 	select ARCH_USE_MEMTEST
 	select ARCH_USE_QUEUED_RWLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +33 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
 		flags |= FAULT_FLAG_WRITE;
 	else if (cause == EXC_INST_PAGE_FAULT)
 		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
 	mmap_read_lock(mm);
 	vma = find_vma(mm, addr);
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
 	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif
 	if (unlikely(fault & VM_FAULT_ERROR)) {
 		tsk->thread.bad_cause = cause;
 		mm_fault_error(regs, addr, fault);
Signature · 7 lines
2.40.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 12 lines · Jisheng Zhang
Quoted 11 lines · Jisheng Zhang

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

Quoted 7 lines
Quoted 4 lines

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

PS: run ebizzy as below:
./ebizzy -mTt your_nr_cpus

Sorry, should be ./ebizzy -mTt 2*your_nr_cpus

Quoted 76 lines
Quoted 76 lines
 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
 	select ARCH_SUPPORTS_HUGETLBFS if MMU
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
 	select ARCH_USE_MEMTEST
 	select ARCH_USE_QUEUED_RWLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +33 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
 		flags |= FAULT_FLAG_WRITE;
 	else if (cause == EXC_INST_PAGE_FAULT)
 		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
 	mmap_read_lock(mm);
 	vma = find_vma(mm, addr);
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
 	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif
 	if (unlikely(fault & VM_FAULT_ERROR)) {
 		tsk->thread.bad_cause = cause;
 		mm_fault_error(regs, addr, fault);
Signature · 7 lines
2.40.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jisheng Zhang
Quoted 5 lines

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In

Good improvement, I think VMA lock is worth to support in riscv.

Please give more details about ebizzy, Is it
https://github.com/linux-test-project/ltp/blob/master/utils/benchmark/ebizzy-0.3/ebizzy.c
?

Quoted 6 lines

theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

How about add Link tag here:

Quoted 63 lines

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
 	select ARCH_SUPPORTS_HUGETLBFS if MMU
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
 	select ARCH_USE_MEMTEST
 	select ARCH_USE_QUEUED_RWLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +30 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
 		flags |= FAULT_FLAG_WRITE;
 	else if (cause == EXC_INST_PAGE_FAULT)
 		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
 	mmap_read_lock(mm);
 	vma = find_vma(mm, addr);

arch/riscv/mm/fault.c void handle_page_fault(struct pt_regs *regs) · line 390

Quoted 6 lines
arch/riscv/mm/fault.c +3 -0
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
 	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif

It's very close to cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first"), and I didn't find any problem. So:

F.Y.I Huacai Chen, maybe he also would be interesting this new feature.

Quoted 5 lines
arch/riscv/mm/fault.c +0 -0
 	if (unlikely(fault & VM_FAULT_ERROR)) {
 		tsk->thread.bad_cause = cause;
 		mm_fault_error(regs, addr, fault);
Signature · 1 line
2.40.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by
#4 lore raw
Quoted 88 lines · On Tue, May 23, 2023 at 10:03 PM <[email protected]> wrote:
Quoted 6 lines

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In

Good improvement, I think VMA lock is worth to support in riscv.

Please give more details about ebizzy, Is it
https://github.com/linux-test-project/ltp/blob/master/utils/benchmark/ebizzy-0.3/ebizzy.c
?

Quoted 6 lines

theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

How about add Link tag here:

Quoted 66 lines

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
      select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
      select ARCH_SUPPORTS_HUGETLBFS if MMU
      select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+     select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
      select ARCH_USE_MEMTEST
      select ARCH_USE_QUEUED_RWLOCKS
      select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +30 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
              flags |= FAULT_FLAG_WRITE;
      else if (cause == EXC_INST_PAGE_FAULT)
              flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+     if (!(flags & FAULT_FLAG_USER))
+             goto lock_mmap;
+
+     vma = lock_vma_under_rcu(mm, addr);
+     if (!vma)
+             goto lock_mmap;
+
+     if (unlikely(access_error(cause, vma))) {
+             vma_end_read(vma);
+             goto lock_mmap;
+     }
+
+     fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+     vma_end_read(vma);
+
+     if (!(fault & VM_FAULT_RETRY)) {
+             count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+             goto done;
+     }
+     count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+     if (fault_signal_pending(fault, regs)) {
+             if (!user_mode(regs))
+                     no_context(regs, addr);
+             return;
+     }
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
      mmap_read_lock(mm);
      vma = find_vma(mm, addr);
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
      mmap_read_unlock(mm);
 
Quoted 7 lines

arch/riscv/mm/fault.c void handle_page_fault(struct pt_regs *regs) · line 390

Quoted 3 lines
arch/riscv/mm/fault.c +3 -0
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif

It's very close to cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first"), and I didn't find any problem. So:

Looks correct to me.

Quoted 9 lines

F.Y.I Huacai Chen, maybe he also would be interesting this new feature.

Quoted 5 lines
arch/riscv/mm/fault.c +0 -1
      if (unlikely(fault & VM_FAULT_ERROR)) {
              tsk->thread.bad_cause = cause;
              mm_fault_error(regs, addr, fault);
--

2.40.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw
In reply to [email protected]
Quoted 10 lines · On Wed, May 24, 2023 at 01:02:59AM -0400, [email protected] wrote:
Quoted 5 lines

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In

Good improvement, I think VMA lock is worth to support in riscv.

Please give more details about ebizzy, Is it
https://github.com/linux-test-project/ltp/blob/master/utils/benchmark/ebizzy-0.3/ebizzy.c
?

yeah it's one of ltp benchmark utils.

Quoted 93 lines
Quoted 7 lines

theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

How about add Link tag here:

Quoted 63 lines

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

 arch/riscv/Kconfig    |  1 +
 arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
arch/riscv/Kconfig +1 -0
index 62e84fee2cfd..b958f67f9a12 100644
@@ -42,6 +42,7 @@ config RISCV
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
 	select ARCH_SUPPORTS_HUGETLBFS if MMU
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
 	select ARCH_USE_MEMTEST
 	select ARCH_USE_QUEUED_RWLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +30 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
 		flags |= FAULT_FLAG_WRITE;
 	else if (cause == EXC_INST_PAGE_FAULT)
 		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
 retry:
 	mmap_read_lock(mm);
 	vma = find_vma(mm, addr);

arch/riscv/mm/fault.c void handle_page_fault(struct pt_regs *regs) · line 390

Quoted 6 lines
arch/riscv/mm/fault.c +3 -0
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
 	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif

It's very close to cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first"), and I didn't find any problem. So:

F.Y.I Huacai Chen, maybe he also would be interesting this new feature.

Quoted 5 lines
arch/riscv/mm/fault.c +0 -0
 	if (unlikely(fault & VM_FAULT_ERROR)) {
 		tsk->thread.bad_cause = cause;
 		mm_fault_error(regs, addr, fault);
Signature · 1 line
2.40.1
#6 lore raw
In reply to Jisheng Zhang
Quoted 9 lines · Jisheng Zhang

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

[...]

Applied, thanks!

[1/1] riscv: mm: try VMA lock-based page fault handling first

      https://git.kernel.org/palmer/c/648321fa0d97

Best regards,

Signature · 1 line
Palmer Dabbelt <[email protected]>
#7 lore raw
In reply to Jisheng Zhang
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 9 lines · On Wed, 24 May 2023 00:59:42 +0800 you wrote:

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

[...]

Here is the summary with links:
- riscv: mm: try VMA lock-based page fault handling first

    https://git.kernel.org/riscv/c/648321fa0d97

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Reviewed-by on v1 1/1
#8 lore raw
In reply to Jisheng Zhang
Quoted 25 lines · Jisheng Zhang

Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails.

A simple running the ebizzy benchmark on Lichee Pi 4A shows that PER_VMA_LOCK can improve the ebizzy benchmark by about 32.68%. In theory, the more CPUs, the bigger improvement, but I don't have any HW platform which has more than 4 CPUs.

This is the riscv variant of "x86/mm: try VMA lock-based page fault handling first".

---
Any performance numbers are welcome! Especially the numbers on HW platforms with 8 or more CPUs.

  arch/riscv/Kconfig    |  1 +
  arch/riscv/mm/fault.c | 33 +++++++++++++++++++++++++++++++++
  2 files changed, 34 insertions(+)
arch/riscv/Kconfig +0 -0
index 62e84fee2cfd..b958f67f9a12 100644

arch/riscv/Kconfig config RISCV · line 45

Quoted 4 lines
arch/riscv/Kconfig +1 -0
@@ -42,6 +42,7 @@ config RISCV
  	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
  	select ARCH_SUPPORTS_HUGETLBFS if MMU
  	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
+	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU

no need if mmu, see PER_VMA_LOCK

config PER_VMA_LOCK
bool "allow VMA lock-based page fault" def_bool y
depends on ARCH_SUPPORTS_PER_VMA_LOCK && MMU && SMP

Quoted 54 lines
arch/riscv/Kconfig +0 -0
  	select ARCH_USE_MEMTEST
  	select ARCH_USE_QUEUED_RWLOCKS
  	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
arch/riscv/mm/fault.c +33 -0
index 8685f85a7474..eccdddf26f4b 100644
@@ -286,6 +286,36 @@ void handle_page_fault(struct pt_regs *regs)
  		flags |= FAULT_FLAG_WRITE;
  	else if (cause == EXC_INST_PAGE_FAULT)
  		flags |= FAULT_FLAG_INSTRUCTION;
+#ifdef CONFIG_PER_VMA_LOCK
+	if (!(flags & FAULT_FLAG_USER))
+		goto lock_mmap;
+
+	vma = lock_vma_under_rcu(mm, addr);
+	if (!vma)
+		goto lock_mmap;
+
+	if (unlikely(access_error(cause, vma))) {
+		vma_end_read(vma);
+		goto lock_mmap;
+	}
+
+	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
+	vma_end_read(vma);
+
+	if (!(fault & VM_FAULT_RETRY)) {
+		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
+		goto done;
+	}
+	count_vm_vma_lock_event(VMA_LOCK_RETRY);
+
+	if (fault_signal_pending(fault, regs)) {
+		if (!user_mode(regs))
+			no_context(regs, addr);
+		return;
+	}
+lock_mmap:
+#endif /* CONFIG_PER_VMA_LOCK */
+
  retry:
  	mmap_read_lock(mm);
  	vma = find_vma(mm, addr);
@@ -355,6 +385,9 @@ void handle_page_fault(struct pt_regs *regs)
 
  	mmap_read_unlock(mm);
 
+#ifdef CONFIG_PER_VMA_LOCK
+done:
+#endif
  	if (unlikely(fault & VM_FAULT_ERROR)) {
  		tsk->thread.bad_cause = cause;
  		mm_fault_error(regs, addr, fault);