All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: smp: optimization for flush_tlb_mm when exiting
@ 2022-05-10 11:44 Mao Bibo
  2022-05-12 16:11 ` Thomas Bogendoerfer
  0 siblings, 1 reply; 2+ messages in thread
From: Mao Bibo @ 2022-05-10 11:44 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel

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(+)

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) {
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MIPS: smp: optimization for flush_tlb_mm when exiting
  2022-05-10 11:44 [PATCH] MIPS: smp: optimization for flush_tlb_mm when exiting Mao Bibo
@ 2022-05-12 16:11 ` Thomas Bogendoerfer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Bogendoerfer @ 2022-05-12 16:11 UTC (permalink / raw)
  To: Mao Bibo; +Cc: linux-mips, linux-kernel

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.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-12 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 11:44 [PATCH] MIPS: smp: optimization for flush_tlb_mm when exiting Mao Bibo
2022-05-12 16:11 ` Thomas Bogendoerfer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.