Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3312083imm; Tue, 17 Jul 2018 02:38:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdUhNfpVr4kAH5q4YqVKBEguJ1os4wTkitj6WDifWE3m6Gm60/VykB9PeHl7CK54c2dzfl7 X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr889570pln.307.1531820321289; Tue, 17 Jul 2018 02:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531820321; cv=none; d=google.com; s=arc-20160816; b=hj43+ErZNZp5GUlLfUBQAZo+e/CLqf1Tx1uYpNaoCUktrW2WqZhlVveq2vyJZ6JOU3 n/CqHugw8sIh0+pDody0IovkmGxgbrLyZvJQVM66cgrdvQ7Cz5ZChhzyp868BfGbIViS Zg0pTqOWyPb6ijclKEHMxN8rRI+m6+PmEIr2wCb6O1KL9v51zUplHEHehupj98ydVBX7 NRDrjMFldW9MBIcFxaqwPI7FffBr/OydJzPqwDcL8sdmOot4UT895nmsSkSystKBBl7y +3pP6auGMpvrEpb2TkM90TAR9MLhRq64EVMqueT1QXcUtZbp4tWeVWUTGRCECbRkQOFv WX0w== 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:arc-authentication-results; bh=JYbQ11IT/xlCvdcvXe6EGfpE4tvSvGldq3XiFD14YJE=; b=apdNKSFjj5vhJbhRa16lIdm2lMsac4TIqf3VKccjRkU/tHn20EvOp+rZOps4xagkf7 dUPok7Gpke3uUkjrwikEppe6wRR1TlN6BW2fOdSAL2LPW7k/5rMk1wsiPdPQsT5HIAvK xIqWqYsL52DS/nFXOTL9skWNhQKix3yOesu9o02hAt/z+Skt8ltKM6bNRkhDc+khRsT6 CZBJPpZNWAwZ0kMpETUbOBoRfOSO+6ERm4M4irX7KY32KXfDb2PvIz1THzb2exfFRTmW nMxOL0W44UvQuSf9DU/rqZqdB+b10ZP86L4XPH+5W5oN+PGIhp9v4WlXXNXpijzNt7mN qYdQ== 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 m11-v6si474781plt.284.2018.07.17.02.38.26; Tue, 17 Jul 2018 02:38:41 -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 S1730731AbeGQKIu (ORCPT + 99 others); Tue, 17 Jul 2018 06:08:50 -0400 Received: from terminus.zytor.com ([198.137.202.136]:51177 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729640AbeGQKIt (ORCPT ); Tue, 17 Jul 2018 06:08:49 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6H9aiBB1463713 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 17 Jul 2018 02:36:44 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6H9ahFF1463710; Tue, 17 Jul 2018 02:36:44 -0700 Date: Tue, 17 Jul 2018 02:36:44 -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: tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, torvalds@linux-foundation.org, riel@surriel.com, songliubraving@fb.com, mingo@kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com Reply-To: tglx@linutronix.de, linux-kernel@vger.kernel.org, dave.hansen@intel.com, hpa@zytor.com, peterz@infradead.org, mingo@kernel.org, songliubraving@fb.com, torvalds@linux-foundation.org, riel@surriel.com In-Reply-To: <20180716190337.26133-8-riel@surriel.com> References: <20180716190337.26133-8-riel@surriel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm/tlb: Skip atomic operations for 'init_mm' in switch_mm_irqs_off() Git-Commit-ID: e9d8c61557687b7126101e9550bdf243223f0d8f 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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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: e9d8c61557687b7126101e9550bdf243223f0d8f Gitweb: https://git.kernel.org/tip/e9d8c61557687b7126101e9550bdf243223f0d8f Author: Rik van Riel AuthorDate: Mon, 16 Jul 2018 15:03:37 -0400 Committer: Ingo Molnar CommitDate: Tue, 17 Jul 2018 09:35:34 +0200 x86/mm/tlb: Skip atomic operations for 'init_mm' in switch_mm_irqs_off() Song Liu noticed switch_mm_irqs_off() taking a lot of CPU time in recent kernels,using 1.8% of a 48 CPU system during a netperf to localhost run. Digging into the profile, we noticed that cpumask_clear_cpu and cpumask_set_cpu together take about half of the CPU time taken by switch_mm_irqs_off(). However, the CPUs running netperf end up switching back and forth between netperf and the idle task, which does not require changes to the mm_cpumask. Furthermore, the init_mm cpumask ends up being the most heavily contended one in the system. Simply skipping changes to mm_cpumask(&init_mm) reduces overhead. Reported-and-tested-by: Song Liu Signed-off-by: Rik van Riel Acked-by: Dave Hansen Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: efault@gmx.de Cc: kernel-team@fb.com Cc: luto@kernel.org Link: http://lkml.kernel.org/r/20180716190337.26133-8-riel@surriel.com Signed-off-by: Ingo Molnar --- arch/x86/mm/tlb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 493559cae2d5..f086195f644c 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -310,15 +310,22 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, sync_current_stack_to_mm(next); } - /* Stop remote flushes for the previous mm */ - VM_WARN_ON_ONCE(!cpumask_test_cpu(cpu, mm_cpumask(real_prev)) && - real_prev != &init_mm); - cpumask_clear_cpu(cpu, mm_cpumask(real_prev)); + /* + * Stop remote flushes for the previous mm. + * Skip kernel threads; we never send init_mm TLB flushing IPIs, + * but the bitmap manipulation can cause cache line contention. + */ + if (real_prev != &init_mm) { + VM_WARN_ON_ONCE(!cpumask_test_cpu(cpu, + mm_cpumask(real_prev))); + cpumask_clear_cpu(cpu, mm_cpumask(real_prev)); + } /* * Start remote flushes and then read tlb_gen. */ - cpumask_set_cpu(cpu, mm_cpumask(next)); + if (next != &init_mm) + cpumask_set_cpu(cpu, mm_cpumask(next)); next_tlb_gen = atomic64_read(&next->context.tlb_gen); choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush);