Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1378671rwi; Thu, 27 Oct 2022 15:10:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WoDBvgr5u/vaxZJoDPDIX1DTJ/OcKUgD2s5lGyhTlHTa22Se6LMWJFV/YQtcd//Dq1PEH X-Received: by 2002:a05:6a00:124e:b0:565:ba3c:58bf with SMTP id u14-20020a056a00124e00b00565ba3c58bfmr51516119pfi.82.1666908632565; Thu, 27 Oct 2022 15:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666908632; cv=none; d=google.com; s=arc-20160816; b=ewyPMTsknWk1XWwZO1QB85phavga7WOfCUtPtAjUx7y2H64pi4Pj3ehaRP20HvQ/8E AdsjF2JmPhkV05/8Vm1XEaRs6OFdC/J1EY6Md8XofMIf15yVo7Pc6Y6FxAPaEOkoheEH axlfxyi9DZz64JRUq8dk/NuvIgx6dKsRyLkiw5VruQfovQt0peBiFR4Tk1ilh2XyZ+3H qK2QBZgFz9lRFi7zGC60vp1VAWD5YSguJeaUXC4fl+tmXObUHduT0Uu8+dgFMBTHl3SD 9fvN0/mUrfVvXdNVHF7Dq56TmOOSa4B1LLqe8lbJ3bP/VtAmX28KXWV3meM3NyRhPbTi RbJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=1SmucxEaYv462cDhUuWHbqENmtRj5EFJFsejZah/7ns=; b=YO6xhTsd0GZVJpeiPv3hkS7y0tnsROXB9RD9woYCqyxLVlT/4djbNXD25tbWIYeQuS Avh4sSr7xmnl/pL22Q6AWNmkBPO9PpxN8pr9wd6YahD336yO21eziFDHji1ywqJV2Pz1 d2Y7KDqYxElrXPyy0uu8mJeN9Sbr0XMgpqeG1rp0yDmf0AakBwbcpa7ju6CTMIIJsx5l meJwc/H+f7YcAcqLdSeGUSMfo0CMF2VMvr1AGsrMBSQ2ph4htH3eQO5l0VN0LYKjnvq6 ASJ+dCCaarEI2XKk2XsykCWT8UuhDAGVGyP73/qq/RlpiooegKvhwbQtQzx+24uhxtJI 7wmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g0FRESr+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a170902788200b00186b3cb49basi2658203pll.202.2022.10.27.15.10.19; Thu, 27 Oct 2022 15:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g0FRESr+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236813AbiJ0Voy (ORCPT + 99 others); Thu, 27 Oct 2022 17:44:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236117AbiJ0Vow (ORCPT ); Thu, 27 Oct 2022 17:44:52 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C503D5AB for ; Thu, 27 Oct 2022 14:44:49 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id 4so3055503pli.0 for ; Thu, 27 Oct 2022 14:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1SmucxEaYv462cDhUuWHbqENmtRj5EFJFsejZah/7ns=; b=g0FRESr+JzZQ6RWf4EVze5xqLA4Ba57sN9s5bYeQSEcmq1ESoV0OgMbslUIXTLlK9Z IwgDww9Z2P7g5HJ+UMcQAJtr8IVUt0fb2vcldKTrzRligsUdszod3BwgYyofJNRCJX16 mJkFiuJCGN4rzu9umDOaSxr1of/fTbFBVYeTcPXMeNxPjstpECua4fLrW79NYNiNnDPC zvs8PkY6UzdGsdP7BlhdPPOyHvpB/Fa41GSAyNo1vkqKEaZOiv1whR4HprvLg1ILwv8i sD3U+OGImOH6Hd8qDJv235BmKjoGCHnO6w+rAhGeu08bo8Bwd1yRhRz3m8NWZoPgBfsP 5BJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1SmucxEaYv462cDhUuWHbqENmtRj5EFJFsejZah/7ns=; b=y/csqn4TVRPRygb+YQVToTOLxIpCdzaGEhKTrIsel/6yZFOwbrchdIy9Nz/3RiwLEu FJYfe3M91ONUFLm7TrUaZNALYLVa2/bvZfYuFS4TDDnJtYw2218JX4ZJwN4gFlmz6eXE 8N87f/0ZMgWkNINn99TP/xbxps390L1oKUIH0QagnDNHFRHB/xhpuB8oZtqYtaYH6ccz /WAajNHib+v+gWN1j+e3rLwNVDYufuXcDF3+2cTrXYonjkcbfQ99gALgbcwGDDY1YLTz BEKCEqopwjpd/uGD922HnT+jF2rVFWYdM/1RdEY0xSB+u2Ihgtv7ymhZprt8neRYC+iJ 7uPg== X-Gm-Message-State: ACrzQf16uPFBoMtSiTDVLDTXM86ssgSr4xIdq8U8FFDAv2JtwCoeqZNi 6uKgrVnVjvGIbnvo64pNm0A= X-Received: by 2002:a17:902:d2c1:b0:186:9e90:6ad with SMTP id n1-20020a170902d2c100b001869e9006admr25862913plc.2.1666907089086; Thu, 27 Oct 2022 14:44:49 -0700 (PDT) Received: from smtpclient.apple ([66.170.99.95]) by smtp.gmail.com with ESMTPSA id j6-20020a17090a840600b001fb1de10a4dsm1394712pjn.33.2022.10.27.14.44.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2022 14:44:48 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment From: Nadav Amit In-Reply-To: Date: Thu, 27 Oct 2022 14:44:46 -0700 Cc: Peter Zijlstra , Jann Horn , John Hubbard , x86@kernel.org, willy@infradead.org, Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrea Arcangeli , kirill.shutemov@linux.intel.com, jroedel@suse.de, ubizjak@gmail.com Content-Transfer-Encoding: quoted-printable Message-Id: References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> <6C548A9A-3AF3-4EC1-B1E5-47A7FFBEB761@gmail.com> To: Linus Torvalds X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Oct 27, 2022, at 1:31 PM, Linus Torvalds = wrote: > So there are two levels of tlb flush optimizations >=20 > (a) avoiding them entirely in the first place >=20 > (b) the whole "once you have to flush, keep track of lazy modes and > TLB generations, and flush ranges" >=20 > And honestly, I think you ignored (a), and that's where we do exactly > those kinds of "this case doesn't need to flush AT ALL" things. I did try to avoid TLB flushes by introducing pte_needs_flush() and = avoiding flushes based on the architectural PTE changes. There are even more x86 arch-based opportunities to further avoid TLB flushes (and then only = flush the TLB if spurious #PF occurs). Personally, I still think that making decisions on flushes based on = (mostly) only the arch state makes the code more robust against misuse (e.g., see various confusions between mmu_gather=E2=80=99s fullmm and = need_flush_all). Having said that, I will follow your feedback that the extra complexity worth the extra performance. Anyhow, admittedly, I need to give it more thought. For instance, in = respect to the code that you mentioned (in zap_pte_range), after reading it = again, it seems strange: how is ok to defer the TLB flush after the rmap was removed, even if it is done while the PTL is held. folio_clear_dirty_for_io() would not sync on the PTL afterwards, so the = page might be later re-dirtied using a stale cached PTE. Oh well.