diff mbox series

MIPS: smp: optimization for flush_tlb_mm when exiting

Message ID 20220510114441.2959886-1-maobibo@loongson.cn (mailing list archive)
State Accepted
Commit 84595f450a8fc773a5543e2a0cca55067db38a8d
Headers show
Series MIPS: smp: optimization for flush_tlb_mm when exiting | expand

Commit Message

Bibo Mao May 10, 2022, 11:44 a.m. UTC
When process exits or execute new binary, it will call function
exit_mmap with old mm, there is such function call trace:
  exit_mmap(struct mm_struct *mm)
      --> tlb_finish_mmu(&tlb, 0, -1)
         --> arch_tlb_finish_mmu(tlb, start, end, force)
	    --> tlb_flush_mmu(tlb);
               --> tlb_flush(struct mmu_gather *tlb)
                  --> flush_tlb_mm(tlb->mm)

It is not necessary to flush tlb since oldmm is not used anymore
by the process, there is similar operations on IA64/ARM64 etc,
this patch adds such optimization on MIPS.

Signed-off-by: Mao Bibo <maobibo@loongson.cn>
---
 arch/mips/kernel/smp.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Thomas Bogendoerfer May 12, 2022, 4:11 p.m. UTC | #1
On Tue, May 10, 2022 at 07:44:41PM +0800, Mao Bibo wrote:
> When process exits or execute new binary, it will call function
> exit_mmap with old mm, there is such function call trace:
>   exit_mmap(struct mm_struct *mm)
>       --> tlb_finish_mmu(&tlb, 0, -1)
>          --> arch_tlb_finish_mmu(tlb, start, end, force)
> 	    --> tlb_flush_mmu(tlb);
>                --> tlb_flush(struct mmu_gather *tlb)
>                   --> flush_tlb_mm(tlb->mm)
> 
> It is not necessary to flush tlb since oldmm is not used anymore
> by the process, there is similar operations on IA64/ARM64 etc,
> this patch adds such optimization on MIPS.
> 
> Signed-off-by: Mao Bibo <maobibo@loongson.cn>
> ---
>  arch/mips/kernel/smp.c | 6 ++++++
>  1 file changed, 6 insertions(+)

applied to mips-next.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 1986d1309410..1d93b85271ba 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -518,6 +518,12 @@  static inline void smp_on_each_tlb(void (*func) (void *info), void *info)
 
 void flush_tlb_mm(struct mm_struct *mm)
 {
+	if (!mm)
+		return;
+
+	if (atomic_read(&mm->mm_users) == 0)
+		return;		/* happens as a result of exit_mmap() */
+
 	preempt_disable();
 
 	if (cpu_has_mmid) {