linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched,x86: optimize switch_mm for multi-threaded workloads
@ 2013-07-31 21:43 Rik van Riel
  2013-07-31 21:46 ` Paul Turner
  2013-07-31 22:07 ` Linus Torvalds
  0 siblings, 2 replies; 20+ messages in thread
From: Rik van Riel @ 2013-07-31 21:43 UTC (permalink / raw)
  To: torvalds; +Cc: mingo, linux-kernel, jmario, dzickus, hpa

Don Zickus and Joe Mario have been working on improvements to
perf, and noticed heavy cache line contention on the mm_cpumask,
running linpack on a 60 core / 120 thread system.

The cause turned out to be unnecessary atomic accesses to the
mm_cpumask. When in lazy TLB mode, the CPU is only removed from
the mm_cpumask if there is a TLB flush event.

Most of the time, no such TLB flush happens, and the kernel
skips the TLB reload.  It can also skip the atomic memory
set & test.

Here is a summary of Joe's test results:

 * The __schedule function dropped from 24% of all program cycles down
   to 5.5%.
 * The cacheline contention/hotness for accesses to that bitmask went
   from being the 1st/2nd hottest - down to the 84th hottest (0.3% of
   all shared misses which is now quite cold)
 * The average load latency for the bit-test-n-set instruction in
   __schedule dropped from 10k-15k cycles down to an average of 600 cycles.
 * The linpack program results improved from 133 GFlops to 144 GFlops.
   Peak GFlops rose from 133 to 153. 

Reported-by: Don Zickus <dzickus@redhat.com>
Reported-by: Joe Mario <jmario@redhat.com>
Tested-by: Joe Mario <jmario@redhat.com>
Signed-off-by: Rik van Riel <riel@redhat.com>
---
 arch/x86/include/asm/mmu_context.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index cdbf367..987eb3d 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -59,11 +59,12 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
 		this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
 		BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
 
-		if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next))) {
+		if (!cpumask_test_cpu(cpu, mm_cpumask(next))) {
 			/* We were in lazy tlb mode and leave_mm disabled
 			 * tlb flush IPI delivery. We must reload CR3
 			 * to make sure to use no freed page tables.
 			 */
+			cpumask_set_cpu(cpu, mm_cpumask(next));
 			load_cr3(next->pgd);
 			load_LDT_nolock(&next->context);
 		}

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

end of thread, other threads:[~2013-08-03  1:26 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-31 21:43 [PATCH] sched,x86: optimize switch_mm for multi-threaded workloads Rik van Riel
2013-07-31 21:46 ` Paul Turner
2013-07-31 22:07 ` Linus Torvalds
2013-07-31 22:16   ` Rik van Riel
     [not found]     ` <CA+55aFwj+6P4y8MgGTGbiK_EtfY7LJ_bL_7k9zFYLx4S8F0rJQ@mail.gmail.com>
2013-07-31 22:39       ` Rik van Riel
     [not found]         ` <CA+55aFxKSEHSkdsCkTvjwwo4MnEpN0TwJrek2jd1QJCyUTb-=Q@mail.gmail.com>
2013-07-31 23:12           ` Rik van Riel
2013-07-31 23:14             ` Paul Turner
2013-08-01  0:41               ` Linus Torvalds
2013-08-01  1:58                 ` Rik van Riel
2013-08-01  2:14                   ` Linus Torvalds
2013-08-01  2:14                 ` [PATCH -v2] " Rik van Riel
2013-08-01  2:25                   ` Linus Torvalds
2013-08-01  7:04                     ` Ingo Molnar
2013-08-02  9:07                   ` [tip:sched/core] sched/x86: Optimize switch_mm() " tip-bot for Rik van Riel
2013-08-02  9:12                     ` Ingo Molnar
2013-08-02 12:44                       ` Joe Mario
2013-08-03  1:18                       ` Greg KH
2013-08-01 15:37             ` [PATCH] sched,x86: optimize switch_mm " Jörn Engel
2013-08-01 17:45               ` Linus Torvalds
2013-08-01 17:54                 ` Jörn Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).