Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp113813imm; Tue, 17 Jul 2018 15:06:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeScv69D3svQpo+QMcImovY5Q3ST+yJMbJbsdNhn1I8ohruKOf7hvx4aYQIV6Iq2gahDMJZ X-Received: by 2002:a17:902:301:: with SMTP id 1-v6mr3245024pld.127.1531865206830; Tue, 17 Jul 2018 15:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531865206; cv=none; d=google.com; s=arc-20160816; b=XCTjSkv5l/N3I1iCGxOL6zK/sDrLoD2qK87gyHTwimBdiOd28wlYEDcSej9v2UzBXh FcAhBFIptBRLEuYRhTmuBHO30PWIQ9LS69zDHiEpe4GO/bgzv5MnJ9/Dbh6ZHayG7TLo sYgcOi7ovXr6qXh90Dwdnl8s66SpAiksDpZvLfAQhwjILFbUVBiy5TJi9q+3NhrF5p0e 5XIV/C4qnRqfaXjKWV7kzd3DobAaIM5haXlvUd4uxAJYVhXtTR1sSEISKGRqUyTbMc71 dFdiOrguCOXZvvuOP06/uvmyzQaAXvGIrGOxKxS/BbCZwgfvGbAKLsLNBddhuhcDn9xQ yVbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:arc-authentication-results; bh=gVc9/SwrD0wOpNy0dv/dzywV/jODsF2EEvTo002I830=; b=i0CNxCnceLhXpTqLaNkzSQvZa4T7BbX5O1QopvVMo6WImuSsxPbxH2YhrHdQ+jGYYk H69eKUOAv7hJE3lDcu2bmatH6n4nzCNbp7E2Z2JEZfzXQ59nflyiOWUoJ11KFBZyi13P y7EWeQxmnxptSS+F/6Im5DcC3q9xTKC1zye0BSXd0hFY2ZzJwH7vrml32WytdgAZ7wvq yszfPXfLwNNgCe4IxeqbJ/9VH0Vg6X7Fi3EcgK78VKBopC68G3NJyk4M3YEEkIk2FXl4 TPGRf9MUNZqd1wjKCDWjYdzPBspXzbGQ4sp/bHJYimiRbhYTJmOm3Gp6Jrov0QH6b6pg tuMQ== 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 e17-v6si1832532pgm.671.2018.07.17.15.06.32; Tue, 17 Jul 2018 15:06:46 -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 S1731194AbeGQWj7 (ORCPT + 99 others); Tue, 17 Jul 2018 18:39:59 -0400 Received: from shelob.surriel.com ([96.67.55.147]:60930 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730043AbeGQWj7 (ORCPT ); Tue, 17 Jul 2018 18:39:59 -0400 Received: from [2620:10d:c091:200::1:463b] (helo=[IPv6:2620:10d:c0a3:10fb:4c:7ee9:b6e2:d1d5]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ffY5k-0005L7-Am; Tue, 17 Jul 2018 18:05:08 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: [PATCH 4/7] x86,tlb: make lazy TLB mode lazier From: Rik van Riel In-Reply-To: Date: Tue, 17 Jul 2018 18:05:05 -0400 Cc: LKML , X86 ML , Mike Galbraith , kernel-team , Ingo Molnar , Dave Hansen Content-Transfer-Encoding: 7bit Message-Id: References: <20180716190337.26133-1-riel@surriel.com> <20180716190337.26133-5-riel@surriel.com> To: Andy Lutomirski X-Mailer: Apple Mail (2.3445.9.1) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jul 17, 2018, at 5:29 PM, Andy Lutomirski wrote: > > On Tue, Jul 17, 2018 at 1:16 PM, Rik van Riel wrote: >> Can I skip both the cr4 and let switches when the TLB contents >> are no longer valid and got reloaded? >> >> If the TLB contents are still valid, either because we never went >> into lazy TLB mode, or because no invalidates happened while >> we were lazy, we immediately return. >> >> The cr4 and ldt reloads only happen if the TLB was invalidated >> while we were in lazy TLB mode. > > Yes, since the only events that would change the LDT or the required > CR4 value will unconditionally broadcast to every CPU in mm_cpumask > regardless of whether they're lazy. The interesting case is that you > go lazy, you miss an invalidation IPI because you were lazy, then you > go unlazy, notice the tlb_gen change, and flush. If this happens, you > know that you only missed a page table update and not an LDT update or > a CR4 update, because the latter would have sent the IPI even though > you were lazy. So you should skip the CR4 and LDT updates. > > I suppose a different approach would be to fix the issue below and to > try to track when the LDT actually needs reloading. But that latter > part seems a bit complicated for minimal gain. > > (Do you believe me? If not, please argue back!) > I believe you :) >>> Hmm. load_mm_cr4() should bypass itself when mm == &init_mm. Want to >>> fix that part or should I? >> >> I would be happy to send in a patch for this, and one for >> the above optimization you pointed out. >> > > Yes please! > There is a third optimization left to do. Currently every time we switch into lazy tlb mode, we take a refcount on the mm, even when switching from one kernel thread to another, or when repeatedly switching between the same mm and kernel threads. We could keep that refcount (on a per cpu basis) from the time we first switch to that mm in lazy tlb mode, to when we switch the CPU to a different mm. That would allow us to not bounce the cache line with the mm_struct reference count on every lazy TLB context switch. Does that seem like a reasonable optimization? Am I overlooking anything? I'll try to get all three optimizations working, and will run them through some testing here before posting upstream.