Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4979250imm; Tue, 9 Oct 2018 08:01:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV631n4UVFCyQ0LkOtXoz4dUmEA9GUojL/tMKw0rWleedefCtYwai0GhfM+EsxPtSkjgl5+5E X-Received: by 2002:a62:c05a:: with SMTP id x87-v6mr30249617pff.149.1539097263252; Tue, 09 Oct 2018 08:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539097263; cv=none; d=google.com; s=arc-20160816; b=JFstoHDyXr3Sd3aOzU3FZhbvoeRc4ixEB6Ni1eIkwuaKgoLkwwvjOzKuQwBs5m3k8l vsB1hkUHTd7I6UW0I1dyQ7fossj08H7iYmOYeStJbRZ2UaHgSzJ0nwoTSogT8lNQgU4V g7LpREKUJfF8V9fz4v5Nt0LjVOT3oCUixBKYqdtcsshhRPazdwp07pwA8JEskggcBLfQ kpGnOTl4FOGJWR0Xr1hKkh9tHZQOQrYWBySHL98vQQG0GnxhnGHryMOdqSbMTBttJDn/ T8E+OTAuvc06sx2WyPJS2D0pD340UjtTwBzkle8TeZB/n/29D6rIB24tyk5tHEzKOdgP DEJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=ES4Ll0s1GsVxXjGF2xYJ2/nLTc+a8otMmxSEZH95wS8=; b=IWRgQhrk4H3pJz3j18p63ZkplhF8J03nmtWFAyURd2gzEnfAKPY/AJcG6KjQVFrXYR 5Fc/M21sidegRfKfsLmLT3wNdwJ0x1sVQDigDPExUkmv4KOJcerPK2528ciykQfuQX8f ZnTs1ieUWMGhb5OUmuum7xt3sz5LuUsBKytKty5qMkeIKwEu0SqkQXveqrLiibc+IsWi EGZEU/2s//RnmCfiX6rkq7V3+5rRX7lmnFtH//LGplVFAU5bu9BmMQIA2uLbT483x+cf dSj6LaAdnUCB/iqFdgi/9tpYpoxAojY9kdGPHGHP3NAyzZLc7AduTzmlruAvhlPX//j5 qOYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5-v6si21382096ple.392.2018.10.09.08.00.45; Tue, 09 Oct 2018 08:01:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727216AbeJIWPz (ORCPT + 99 others); Tue, 9 Oct 2018 18:15:55 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39657 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJIWPy (ORCPT ); Tue, 9 Oct 2018 18:15:54 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w99Ew9g21080852 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 9 Oct 2018 07:58:09 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w99Ew9qw1080849; Tue, 9 Oct 2018 07:58:09 -0700 Date: Tue, 9 Oct 2018 07:58:09 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Rik van Riel Message-ID: Cc: songliubraving@fb.com, tglx@linutronix.de, peterz@infradead.org, dave.hansen@intel.com, torvalds@linux-foundation.org, riel@surriel.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com Reply-To: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, riel@surriel.com, torvalds@linux-foundation.org, dave.hansen@intel.com, peterz@infradead.org, tglx@linutronix.de, songliubraving@fb.com In-Reply-To: <20180716190337.26133-7-riel@surriel.com> References: <20180716190337.26133-7-riel@surriel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm/tlb: Always use lazy TLB mode Git-Commit-ID: 5462bc3a9a3c38328bbbd276d51164c7cf21d6a8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5462bc3a9a3c38328bbbd276d51164c7cf21d6a8 Gitweb: https://git.kernel.org/tip/5462bc3a9a3c38328bbbd276d51164c7cf21d6a8 Author: Rik van Riel AuthorDate: Tue, 25 Sep 2018 23:58:38 -0400 Committer: Peter Zijlstra CommitDate: Tue, 9 Oct 2018 16:51:11 +0200 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 Cc: Thomas Gleixner Cc: kernel-team@fb.com Cc: hpa@zytor.com Cc: luto@kernel.org Tested-by: Song Liu Signed-off-by: Rik van Riel (cherry picked from commit 95b0e6357d3e4e05349668940d7ff8f3b7e7e11e) Acked-by: Dave Hansen Signed-off-by: Ingo Molnar Signed-off-by: Peter Zijlstra (Intel) Link: http://lkml.kernel.org/r/20180716190337.26133-7-riel@surriel.com --- arch/x86/include/asm/tlbflush.h | 16 ---------------- arch/x86/mm/tlb.c | 15 +-------------- 2 files changed, 1 insertion(+), 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) #define __flush_tlb_one_user(addr) __native_flush_tlb_one_user(addr) #endif -static inline bool tlb_defer_switch_to_init_mm(void) -{ - /* - * If we have PCID, then switching to init_mm is reasonably - * fast. If we don't have PCID, then switching to init_mm is - * quite slow, so we try to defer it in the hopes that we can - * avoid it entirely. The latter approach runs the risk of - * receiving otherwise unnecessary IPIs. - * - * This choice is just a heuristic. The tlb code can handle this - * function returning true or false regardless of whether we have - * PCID. - */ - return !static_cpu_has(X86_FEATURE_PCID); -} - struct tlb_context { u64 ctx_id; 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) if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) return; - if (tlb_defer_switch_to_init_mm()) { - /* - * There's a significant optimization that may be possible - * here. We have accurate enough TLB flush tracking that we - * don't need to maintain coherence of TLB per se when we're - * lazy. We do, however, need to maintain coherence of - * paging-structure caches. We could, in principle, leave our - * old mm loaded and only switch to init_mm when - * tlb_remove_page() happens. - */ - this_cpu_write(cpu_tlbstate.is_lazy, true); - } else { - switch_mm(NULL, &init_mm, NULL); - } + this_cpu_write(cpu_tlbstate.is_lazy, true); } /*