Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1909171imm; Thu, 19 Jul 2018 09:47:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfGZbNjEv25h7/kCVzcIm3xFIqPNOaDYAcl2NydNFuBCyruvApL9U2fKrlkxD9bS2juQC+z X-Received: by 2002:a62:be03:: with SMTP id l3-v6mr10228023pff.138.1532018822566; Thu, 19 Jul 2018 09:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532018822; cv=none; d=google.com; s=arc-20160816; b=L7/jVRnaDKkvZBvypgVWSyK6bJX0x0ZjQPF42Sq7c6x2l0mFFuW7qMMNZEWrXZy58/ JnNXuwu8i3+ps2YT9U9NlJ1SKrv7pKmU+/aHVERN52x3dnP1aavwHMgwZt9tqfpvNl5c a3EaGetNWvHr/28vss7eBK524x+LOHfc6ktvg29etPSTUMeZj5bW3nijXYRnE+WWOMs4 Jb3sLBZebi16eSa2MRC1Tm99rjj/ftYL4+2zm326KThGEkvvthdeDP+F58VfFujnU2sm 2KWBgSN/NY9HpNH8YdTU6ZhFw+6E8MkFekXsSzCoJWy6FIHWnt8aYocUSmGt7cCncvsh mr5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=UqH2mx9zECHZcoLTWUxO23zzKNIwduMXdg89ScoUhDE=; b=Jg9+eEz9elqb7bfrAYKDUchODdxU/Nuqlf3xh0I8wFQ0Oxg9Azr2bjfnUVOeFMAo6o SwEPlJciVAS25U99Sxr0Uy6a+MPOR4k11pTVBh8Bydh9D4Sh4PVDeIeJd9KHaiyyw/Rt ykRKIhPwgy9eyerLuIWd6n6tGgwQA+stYMG6dW97yv3LCZ40uhYJGvyvKmh0jXWY7nRv ZF+UIdYZWN4aKi0NMYZexpFJfqOFgCNw7GV3jtINQ6U/VwmQpBLUHwn+soCgF+mo8LuY 0fR1K174rOzIPCE5W1If3h/JjBPCpudbfr3svn88eyRy/gBflGuMKbafsq+0/N2itVfV f04Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=vq6+0RIM; 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 184-v6si6065104pfe.249.2018.07.19.09.46.47; Thu, 19 Jul 2018 09:47:02 -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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=vq6+0RIM; 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 S1731960AbeGSRaK (ORCPT + 99 others); Thu, 19 Jul 2018 13:30:10 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:55664 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731625AbeGSRaK (ORCPT ); Thu, 19 Jul 2018 13:30:10 -0400 Received: by mail-wm0-f66.google.com with SMTP id f21-v6so6886280wmc.5 for ; Thu, 19 Jul 2018 09:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UqH2mx9zECHZcoLTWUxO23zzKNIwduMXdg89ScoUhDE=; b=vq6+0RIMvXhmO1JRvf2RH/v50e23TaMavZt8BhFaGpA3QQF50NCHngtHlnoSgVEgGX fLv470OTuZRJAOqnasPTHEwilP+34ps0xtH4crVqxtIACPvO0L9sBg6CPvcTEs77PvBy ijWGfsuCNiSX6K9FAfSxAHUBeLhZ4hc1aawD/FN9zEYVICy92W1maMcOpRNhv6FezR9p pEJiIJNgy6o1tywEaLv+myaP+NiyZiKBWUxmriQ/bwe4DNjF0cjgtoMdDpTegEPbAMlC IaP5jHCVE9F7K3bf8hxhH2KfATURYHy0xZBWZeBCtj2DdZPeTOxtJKiB6fT3/R5TF1cV MvRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UqH2mx9zECHZcoLTWUxO23zzKNIwduMXdg89ScoUhDE=; b=EOWCMvtlNsAUiaWqH3PP0llQ20CmkrUqybEZH5iTZAGIn85U503ol/5rZlf+re+1c7 H2xugYKRYXTAW6sbH9IAof0g2j6muDGZTOhvh+12XjMlHXv32vsKh60O8kzlSxden0zF cse646tEiodz1lRlNEAen+UEAYiebgDqaxpihh5iACjbWc3LSrg6Ghw+NIMv4q2eivss eD5yRkHDcAI9mcItjE3/p5HESLr9XLPu7yYmN0V+fQlCEMrcemWvsxTeSFq1/9oIzlmI WTTZLS4252Z/ZxX5DCP6HdY7u6oJOl6D54ANqfPXqavWY+All4b66RLVBC7IQZz9pQWH PjwA== X-Gm-Message-State: AOUpUlEzitaga4BWcgvR2MrfA8K90nVzdDg9sybYNcEJ/kz+jOCJcKmt P7t2FYRmmQ4cuD0XU+Xb0CJEz+TvaE+h7TQ/zMcBTw== X-Received: by 2002:a1c:8313:: with SMTP id f19-v6mr4504932wmd.144.1532018768394; Thu, 19 Jul 2018 09:46:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:d548:0:0:0:0:0 with HTTP; Thu, 19 Jul 2018 09:45:47 -0700 (PDT) In-Reply-To: References: <20180716190337.26133-1-riel@surriel.com> <20180716190337.26133-5-riel@surriel.com> From: Andy Lutomirski Date: Thu, 19 Jul 2018 09:45:47 -0700 Message-ID: Subject: Re: [PATCH 4/7] x86,tlb: make lazy TLB mode lazier To: Rik van Riel , Peter Zijlstra , Vitaly Kuznetsov Cc: Andy Lutomirski , LKML , X86 ML , Mike Galbraith , kernel-team , Ingo Molnar , Dave Hansen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [I added PeterZ and Vitaly -- can you see any way in which this would break something obscure? I don't.] On Thu, Jul 19, 2018 at 7:14 AM, Rik van Riel wrote: > I guess we can skip both switch_ldt and load_mm_cr4 if real_prev equals > next? Yes, AFAICS. > > On to the lazy TLB mm_struct refcounting stuff :) > >> >> Which refcount? mm_users shouldn=E2=80=99t be hot, so I assume you=E2= =80=99re talking about >> mm_count. My suggestion is to get rid of mm_count instead of trying to >> optimize it. > > > Do you have any suggestions on how? :) > > The TLB shootdown sent at __exit_mm time does not get rid of the > kernelthread->active_mm > pointer pointing at the mm that is exiting. > Ah, but that's conceptually very easy to fix. Add a #define like ARCH_NO_TASK_ACTIVE_MM. Then just get rid of active_mm if that #define is set. After some grepping, there are very few users. The only nontrivial ones are the ones in kernel/ and mm/mmu_context.c that are involved in the rather complicated dance of refcounting active_mm. If that field goes away, it doesn't need to be refcounted. Instead, I think the refcounting can get replaced with something like: /* * Release any arch-internal references to mm. Only called when mm_users is zero * and all tasks using mm have either been switch_mm()'d away or have had * enter_lazy_tlb() called. */ extern void arch_shoot_down_dead_mm(struct mm_struct *mm); which the kernel calls in __mmput() after tearing down all the page tables. The body can be something like: if (WARN_ON(cpumask_any_but(mm_cpumask(...), ...)) { /* send an IPI. Maybe just call tlb_flush_remove_tables() */ } (You'll also have to fix up the highly questionable users in arch/x86/platform/efi/efi_64.c, but that's easy.) Does all that make sense? Basically, as I understand it, the expensive atomic ops you're seeing are all pointless because they're enabling an optimization that hasn't actually worked for a long time, if ever.