Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2674643imm; Mon, 16 Jul 2018 12:04:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdNzhiCQif++ctNBQWgaVkoLeTUMldsaxawm9bQOWR78Jc1rjPgmiHfYDpJFjTtXvGTjTM9 X-Received: by 2002:a63:b349:: with SMTP id x9-v6mr16545155pgt.337.1531767888220; Mon, 16 Jul 2018 12:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531767888; cv=none; d=google.com; s=arc-20160816; b=a8gOOeYk98tu6P7HZewLyWMd33BIuTlDKpgx+VZDTB5hkev/Sz1KVHeu4B/u0VjFlO m9oC57DXcyN9mR8gnyVwq8GqEgNgCfmmcsrXVuipNIQDOBu3uCRxYWynGGfVyJjlXhRY QuYpWQizZRIuNSTn48rix1MPICSoHsHi12dGZWJhOPuq93V3rIgEzaW1SQVDMW2j9DBl /UHoQsEYnfThCWqKgu9XJy+D+zqhDeMFBq+i3nlOsgho9vA4kxM6lqFcSviBIqiNJFlk wOeCKiydZ3BiwtuFLtuLS0yS2yCXORa+WnT7IVpG5CtVZ9jjHEmZuHuizSIyZ02xxZRd PAtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=KaKe/pj4kSEJzMfUpBhuMku3w7vz06NxM5Qbs0bNpNs=; b=LUyCYWZA+0ASvf23mBiDz6VZ6YsFYK7C4G3+xe1gob89RZUYFvu//n8o851CD4gKaS FczWsQ+L9xmeduqIXY/eFreLMzHcTKlzZNED4iaZvb+bKaoNJTd1eJhTcdUFfSSpX53t GlrqXHNnhRQW/sstspgxpVQCt3NSJfLLzoSeodftfQMxi1ezvJSV5InO/wHOzkNjRcEq thpOmEH1kHW35Ptr3uZgQY8+vmuEpVATk7YCIoUk2qRyvrcnXfBdWMafydsr7iIlV4Lq 6KYZszl+Cdm9BTwNBeUETcJwWwCW/qwZ7rANI12pq0HjgACUyGGmnZIUtl5OOvEc8GW7 ohSQ== 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 j10-v6si27173086pgi.500.2018.07.16.12.04.33; Mon, 16 Jul 2018 12:04:48 -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 S1730667AbeGPTcj (ORCPT + 99 others); Mon, 16 Jul 2018 15:32:39 -0400 Received: from shelob.surriel.com ([96.67.55.147]:36138 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728470AbeGPTch (ORCPT ); Mon, 16 Jul 2018 15:32:37 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ff8ma-0003RH-Lc; Mon, 16 Jul 2018 15:03:40 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, luto@kernel.org, efault@gmx.de, kernel-team@fb.com, mingo@kernel.org, dave.hansen@intel.com, Rik van Riel Subject: [PATCH 7/7] x86,switch_mm: skip atomic operations for init_mm Date: Mon, 16 Jul 2018 15:03:37 -0400 Message-Id: <20180716190337.26133-8-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716190337.26133-1-riel@surriel.com> References: <20180716190337.26133-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Song 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. Signed-off-by: Rik van Riel Acked-by: Dave Hansen Reported-and-tested-by: Song Liu --- 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); -- 2.14.4