summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRik van Riel <riel@surriel.com>2018-09-25 23:58:38 -0400
committerPeter Zijlstra <peterz@infradead.org>2018-10-09 10:51:11 -0400
commit5462bc3a9a3c38328bbbd276d51164c7cf21d6a8 (patch)
tree2581f1146d6bfca6fec8a02a3133049950550ab6
parenta31acd3ee8f7dbc0370bdf4a4bfef7a8c13c7542 (diff)
x86/mm/tlb: Always use lazy TLB mode
On most workloads, the number of context switches far exceeds the number of TLB flushes sent. Optimizing the context switches, by always using lazy TLB mode, speeds up those workloads. This patch results in about a 1% reduction in CPU use on a two socket Broadwell system running a memcache like workload. Cc: npiggin@gmail.com Cc: efault@gmx.de Cc: will.deacon@arm.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: kernel-team@fb.com Cc: hpa@zytor.com Cc: luto@kernel.org Tested-by: Song Liu <songliubraving@fb.com> Signed-off-by: Rik van Riel <riel@surriel.com> (cherry picked from commit 95b0e6357d3e4e05349668940d7ff8f3b7e7e11e) Acked-by: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180716190337.26133-7-riel@surriel.com
-rw-r--r--arch/x86/include/asm/tlbflush.h16
-rw-r--r--arch/x86/mm/tlb.c15
2 files changed, 1 insertions, 30 deletions
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 671f65309ce7..d6c0cd9e9591 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -148,22 +148,6 @@ static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
148#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr) 148#define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr)
149#endif 149#endif
150 150
151static inline bool tlb_defer_switch_to_init_mm(void)
152{
153 /*
154 * If we have PCID, then switching to init_mm is reasonably
155 * fast. If we don't have PCID, then switching to init_mm is
156 * quite slow, so we try to defer it in the hopes that we can
157 * avoid it entirely. The latter approach runs the risk of
158 * receiving otherwise unnecessary IPIs.
159 *
160 * This choice is just a heuristic. The tlb code can handle this
161 * function returning true or false regardless of whether we have
162 * PCID.
163 */
164 return !static_cpu_has(X86_FEATURE_PCID);
165}
166
167struct tlb_context { 151struct tlb_context {
168 u64 ctx_id; 152 u64 ctx_id;
169 u64 tlb_gen; 153 u64 tlb_gen;
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 6aa195796dec..54a5870190a6 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -368,20 +368,7 @@ void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
368 if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) 368 if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm)
369 return; 369 return;
370 370
371 if (tlb_defer_switch_to_init_mm()) { 371 this_cpu_write(cpu_tlbstate.is_lazy, true);
372 /*
373 * There's a significant optimization that may be possible
374 * here. We have accurate enough TLB flush tracking that we
375 * don't need to maintain coherence of TLB per se when we're
376 * lazy. We do, however, need to maintain coherence of
377 * paging-structure caches. We could, in principle, leave our
378 * old mm loaded and only switch to init_mm when
379 * tlb_remove_page() happens.
380 */
381 this_cpu_write(cpu_tlbstate.is_lazy, true);
382 } else {
383 switch_mm(NULL, &init_mm, NULL);
384 }
385} 372}
386 373
387/* 374/*