Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5676273imm; Tue, 26 Jun 2018 15:58:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIiWLwHT7Qsrj4icafSM0mHq1fISTyqmrAqaCdfXvnTQrpt0byxCizVDDtMNl40SZMB2R3b X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr3445266plg.135.1530053899766; Tue, 26 Jun 2018 15:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530053899; cv=none; d=google.com; s=arc-20160816; b=djxGByC9sV4HBEkb+IsixmpW0EDxggBaIhNJCXrrQS6R4vuD64/J+SAxWw2K8ZU4/i k4LXQoPaSb3QWpbF7DdSDhnnntyNlFBhxvIiSml65GpUmwBjKWARjnio7Mt1e6CUogs2 6cBnz0Ng2TLzLkC+42C25OtSLXYP6HiRMQCdO0rU1E9SGx45PzgOrjkos2t4i/xVZSQf Sb7z1dJyDsdw+9RzAyjDnMEla+gCAmUrHnjLdZgashyyhG+HSvEjaNzWxXGwRx/Bna5g 0l/j8IWzVRZiDQYU+6xMz/vxzvucNAcmwsXbusE0Zxo45ypDgRN4cHDbfVecqcC0KkJj q0JQ== 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=lvEZNEJjQQGv089dvAFUHIebfyUUpBEOXfVTkrKXX4M=; b=qzp9BUJJTG23Vq39ci0twmOY+O4FdDwQwR2TBd5DEW1u5BT53POv1kVGORnyEZOUnV JqxoxAgvEt81SKrnuyMojB8T0grI2rpRVhuUWzwiN2cve61UfEQNK5MzALfWGuf3lItg AixSVzTRtmqui2ettXauWYXtoMzxAohJYkpl96U8Rq3H3tqsWuMN9JRZGQreN/Nolc6V wbnIrjYxIwWcpniUzcDIfO3eCy0FmCAtjUQXaO3RPUmD3TMTNn0SHFJS3hFjJKnj/CRV tRLn38ZczeNBQcgXPeUIJE9Frw01VMibe6vF4Snsl8dQVl6JW/dItahJp+R5JN6v4qOn +HrQ== 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 v38-v6si2467477plg.283.2018.06.26.15.58.05; Tue, 26 Jun 2018 15:58:19 -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 S933756AbeFZRbq (ORCPT + 99 others); Tue, 26 Jun 2018 13:31:46 -0400 Received: from shelob.surriel.com ([96.67.55.147]:36922 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933734AbeFZRbn (ORCPT ); Tue, 26 Jun 2018 13:31:43 -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 1fXroS-0005n2-Lz; Tue, 26 Jun 2018 13:31:32 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, luto@kernel.org, dave.hansen@linux.intel.com, mingo@kernel.org, kernel-team@fb.com, tglx@linutronix.de, efault@gmx.de, songliubraving@fb.com, Rik van Riel Subject: [PATCH 6/6] x86,switch_mm: skip atomic operations for init_mm Date: Tue, 26 Jun 2018 13:31:26 -0400 Message-Id: <20180626173126.12296-7-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180626173126.12296-1-riel@surriel.com> References: <20180626173126.12296-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.` Skipping cpumask_clear_cpu and cpumask_set_cpu for init_mm (mostly the idle task) reduced CPU use of switch_mm_irqs_off from 1.8% of the CPU to 0.9% of the CPU, with the following netperf commandline: ./super_netperf 300 -P 0 -t TCP_RR -p 8888 -H -l 30 \ -- -r 300,300 -o -s 1M,1M -S 1M,1M w/o patchset: Throughput: 1.71264e+06 perf profile: 0.95% swapper [kernel.vmlinux] [k] switch_mm_irqs_off 0.77% netserver [kernel.vmlinux] [k] switch_mm_irqs_off w/ patchset: Throughput: 1.74075e+06 0.87% swapper [kernel.vmlinux] [k] switch_mm_irqs_off CPU use by enter_lazy_tlb is negligible. The bulk of the savings from switch_mm_irqs_off seem to go towards higher netperf throughput. Signed-off-by: Rik van Riel Reported-and-tested-by: Song Liu --- arch/x86/mm/tlb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 96ab4eacda95..ab3992d82c40 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -300,12 +300,15 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *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)); + 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. */ - cpumask_set_cpu(cpu, mm_cpumask(next)); + if (next != &init_mm) + cpumask_set_cpu(cpu, mm_cpumask(next)); } /* Read the tlb_gen to check whether a flush is needed. */ -- 2.14.4