Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp9953iog; Thu, 16 Jun 2022 20:06:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1szbrSWWJxDPthbk0aJ+S5ydI1tARmpzRxjD1rcF08/sy9q+VxO2+2fwPxMtvlyx27ocitW X-Received: by 2002:a17:90b:1c12:b0:1ea:d742:f317 with SMTP id oc18-20020a17090b1c1200b001ead742f317mr8388588pjb.174.1655435170624; Thu, 16 Jun 2022 20:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655435170; cv=none; d=google.com; s=arc-20160816; b=pzwE7gBKOfCg3u7LQ8SdoDleXR88DEMvNd7WuguGUOHyLtsTlgiyHJCGO2DWbppzDV gyUMB0qCsUO9UumJnCY6l7sd5i2u8Ae986anBhD1myKhcTqiPzRmstj7qGJdVICa3St5 GDC2cjNLIgS3idBWPWUfGOkzT6rcbh3xVCLFPlZQTGs5WHfxmDK1Ooxkp/xWfQ9Jbiyc bwy0LiLdqBIRZJEDRfQoIWpwNnzu/gUTY21LctWP8q/+932yqkz3zUT2gqipYfLjp8AR YhMAwjimLpe2c6f4gODaRWdLANkOA83bmFqzcf4T8xEeJtMY+dYAx+qDrF8AJQcxIUQu y/CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R6Hc91+se229HD5l7HXDZ+HfW8CTebpMh8HfmhUTOpA=; b=dnziPgSV/92VhrPPOHphe1BXguvKWntBbe4OQPpmG3JPrFlMAl/AdgdneiUyzblhom 8m6U3teNA7zk1W9J4czJM/DD15CJ6AJ+FP+WY189L5khf0jFU3Hivt5rbxt9jYRN4U1H zsuOhixa/fTzRONb/gm5bBIgIgEC5R5CWhrNRFEknyVB9jcQGvG6hti0+Wmff9Y2aafQ selZ2BdsLY8l4F99cd4nmtJMdMpL7vzthUelr1hryo0kcseKbJq5CQP98DlYjVH4rx9h C+O7BvF/XVH4UuSnZQzOqIuZr0m5oHv4Q3puL3k2JjW1E4yAzC0bQ3U+1Bl1jdjYB5Rm UKcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rioKHEIX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a17090ab94a00b001e08d589a2dsi3928771pjw.75.2022.06.16.20.05.56; Thu, 16 Jun 2022 20:06:10 -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=@google.com header.s=20210112 header.b=rioKHEIX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379917AbiFQDEO (ORCPT + 99 others); Thu, 16 Jun 2022 23:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379748AbiFQDEL (ORCPT ); Thu, 16 Jun 2022 23:04:11 -0400 Received: from mail-vs1-xe2a.google.com (mail-vs1-xe2a.google.com [IPv6:2607:f8b0:4864:20::e2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E35F366226 for ; Thu, 16 Jun 2022 20:04:08 -0700 (PDT) Received: by mail-vs1-xe2a.google.com with SMTP id n4so2927720vsm.6 for ; Thu, 16 Jun 2022 20:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R6Hc91+se229HD5l7HXDZ+HfW8CTebpMh8HfmhUTOpA=; b=rioKHEIXDdxpnd/mle8IERdGydANcz3zdHn0l4i2x1RpmqCSnw9KTj9jkZZMwplNDn hMqUfoVr2OqKjQuUuidCzs3LijuS6mdh05jK0teI86Oia85a5Sm19d0LyGe7L/vKbbXk 9BIRpRnklRBsVO3ko6z9LDwebm/KS9e4ArmqWzS9uo1ruIW5wN79d12SSrm0X6BSpVQd cDC9czJBLgFS/tpSc73Nko1xNA6EXFpqDISPLKvovY/Hf0q3HnQ4dfYLpG/KalzrW98H V4MBOZR99I/7fsZSRQnjknyRpAP9Th9JlHfIGgOoT7RhuLx9p5zXIPCaKH6EpGUV9LEM jIVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R6Hc91+se229HD5l7HXDZ+HfW8CTebpMh8HfmhUTOpA=; b=s5F+qUQ3FcZ1PrC3t8vOzdMNx1C+Xlh9hw68kqELu4Yft6CwZKU5iQXFifCW6FtWdK Xus5jWlKoy9ybXzH7IbPrB1rR8nWLMVGVCo4aOt4g5sZF6o9QYqeIyNbYqgbJP6NCkEM 8TjRfKX+d49L32Xi1y/TeR3ShVBbrVqC9T2X3cmbU53uXGmF9yqanjEIzji+VGxRs7rN kFpZml4C/sczgqCuRjFd6bUkx8Q28/UefY7CcG6mfuzsLl5v+hTCiOP8jS+DdCCj0Cm/ bdgnpb5P6efTHp+Sba7mg8y38ymg7HzQFN0zDYZhrNRAOrBNkI1Mebvs/JzpDrQy0Egy fo7Q== X-Gm-Message-State: AJIora/mfmL782yZWKm8iLuw1NafLaZBc8CdAduaSftAvB1NU+rIAocl QmF67+NKUHqxHP7ZFpeVo5CuG+tETkHGfmGWP6HksA== X-Received: by 2002:a05:6102:214c:b0:34b:b31d:1a50 with SMTP id h12-20020a056102214c00b0034bb31d1a50mr3610381vsg.41.1655435047846; Thu, 16 Jun 2022 20:04:07 -0700 (PDT) MIME-Version: 1.0 References: <20220518014632.922072-1-yuzhao@google.com> <20220518014632.922072-8-yuzhao@google.com> <20220607102135.GA32448@willie-the-truck> <20220607104358.GA32583@willie-the-truck> In-Reply-To: From: Yu Zhao Date: Thu, 16 Jun 2022 21:03:31 -0600 Message-ID: Subject: Re: [PATCH v11 07/14] mm: multi-gen LRU: exploit locality in rmap To: Barry Song <21cnbao@gmail.com> Cc: Linus Torvalds , Will Deacon , Andrew Morton , Linux-MM , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Johannes Weiner , Jonathan Corbet , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Peter Zijlstra , Tejun Heo , Vlastimil Babka , LAK , Linux Doc Mailing List , LKML , x86 , Kernel Page Reclaim v2 , Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=C3=A4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain , huzhanyuan@oppo.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Jun 16, 2022 at 8:01 PM Barry Song <21cnbao@gmail.com> wrote: > > On Fri, Jun 17, 2022 at 1:43 PM Yu Zhao wrote: > > > > On Thu, Jun 16, 2022 at 5:29 PM Yu Zhao wrote: > > > > > > On Thu, Jun 16, 2022 at 4:33 PM Barry Song <21cnbao@gmail.com> wrote: > > > > > > > > On Fri, Jun 17, 2022 at 9:56 AM Yu Zhao wrote: > > > > > > > > > > On Wed, Jun 8, 2022 at 4:46 PM Barry Song <21cnbao@gmail.com> wrote: > > > > > > > > > > > > On Thu, Jun 9, 2022 at 3:52 AM Linus Torvalds > > > > > > wrote: > > > > > > > > > > > > > > On Tue, Jun 7, 2022 at 5:43 PM Barry Song <21cnbao@gmail.com> wrote: > > > > > > > > > > > > > > > > Given we used to have a flush for clear pte young in LRU, right now we are > > > > > > > > moving to nop in almost all cases for the flush unless the address becomes > > > > > > > > young exactly after look_around and before ptep_clear_flush_young_notify. > > > > > > > > It means we are actually dropping flush. So the question is, were we > > > > > > > > overcautious? we actually don't need the flush at all even without mglru? > > > > > > > > > > > > > > We stopped flushing the TLB on A bit clears on x86 back in 2014. > > > > > > > > > > > > > > See commit b13b1d2d8692 ("x86/mm: In the PTE swapout page reclaim case > > > > > > > clear the accessed bit instead of flushing the TLB"). > > > > > > > > > > > > This is true for x86, RISC-V, powerpc and S390. but it is not true for > > > > > > most platforms. > > > > > > > > > > > > There was an attempt to do the same thing in arm64: > > > > > > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1793830.html > > > > > > but arm64 still sent a nosync tlbi and depent on a deferred to dsb : > > > > > > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1794484.html > > > > > > > > > > Barry, you've already answered your own question. > > > > > > > > > > Without commit 07509e10dcc7 arm64: pgtable: Fix pte_accessible(): > > > > > #define pte_accessible(mm, pte) \ > > > > > - (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid_young(pte)) > > > > > + (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid(pte)) > > > > > > > > > > You missed all TLB flushes for PTEs that have gone through > > > > > ptep_test_and_clear_young() on the reclaim path. But most of the time, > > > > > you got away with it, only occasional app crashes: > > > > > https://lore.kernel.org/r/CAGsJ_4w6JjuG4rn2P=d974wBOUtXUUnaZKnx+-G6a8_mSROa+Q@mail.gmail.com/ > > > > > > > > > > Why? > > > > > > > > Yes. On the arm64 platform, ptep_test_and_clear_young() without flush > > > > can cause random > > > > App to crash. > > > > ptep_test_and_clear_young() + flush won't have this kind of crashes though. > > > > But after applying commit 07509e10dcc7 arm64: pgtable: Fix > > > > pte_accessible(), on arm64, > > > > ptep_test_and_clear_young() without flush won't cause App to crash. > > > > > > > > ptep_test_and_clear_young(), with flush, without commit 07509e10dcc7: OK > > > > ptep_test_and_clear_young(), without flush, with commit 07509e10dcc7: OK > > > > ptep_test_and_clear_young(), without flush, without commit 07509e10dcc7: CRASH > > > > > > I agree -- my question was rhetorical :) > > > > > > I was trying to imply this logic: > > > 1. We cleared the A-bit in PTEs with ptep_test_and_clear_young() > > > 2. We missed TLB flush for those PTEs on the reclaim path, i.e., case > > > 3 (case 1 & 2 guarantee flushes) > > > 3. We saw crashes, but only occasionally > > > > > > Assuming TLB cached those PTEs, we would have seen the crashes more > > > often, which contradicts our observation. So the conclusion is TLB > > > didn't cache them most of the time, meaning flushing TLB just for the > > > sake of the A-bit isn't necessary. > > > > > > > do you think it is safe to totally remove the flush code even for > > > > the original > > > > LRU? > > > > > > Affirmative, based on not only my words, but 3rd parties': > > > 1. Your (indirect) observation > > > 2. Alexander's benchmark: > > > https://lore.kernel.org/r/BYAPR12MB271295B398729E07F31082A7CFAA0@BYAPR12MB2712.namprd12.prod.outlook.com/ > > > 3. The fundamental hardware limitation in terms of the TLB scalability > > > (Fig. 1): https://www.usenix.org/legacy/events/osdi02/tech/full_papers/navarro/navarro.pdf > > > > 4. Intel's commit b13b1d2d8692 ("x86/mm: In the PTE swapout page > > reclaim case clear the accessed bit instead of flushing the TLB") > > Hi Yu, > I am going to send a RFC based on the above discussion. > > diff --git a/mm/rmap.c b/mm/rmap.c > index 5bcb334cd6f2..7ce6f0b6c330 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -830,7 +830,7 @@ static bool folio_referenced_one(struct folio *folio, > } > > if (pvmw.pte) { > - if (ptep_clear_flush_young_notify(vma, address, > + if (ptep_clear_young_notify(vma, address, > pvmw.pte)) { > /* > * Don't treat a reference through Thanks! This might make a difference on my 64 core Altra -- I'll test after you post the RFC.