Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1986992iog; Thu, 16 Jun 2022 19:22:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZgajBlTp9R9Y3tiKaE0EgTbOo7UAMAmV1bFAyd6Ycp4oWbCiimVEmSdZqEs2z1RzP91dD X-Received: by 2002:a17:903:240c:b0:169:52d:cd75 with SMTP id e12-20020a170903240c00b00169052dcd75mr5944460plo.12.1655432560453; Thu, 16 Jun 2022 19:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655432560; cv=none; d=google.com; s=arc-20160816; b=W4Rm3v+gwPgOlRonyWwPem8uzrw0uhZNrjoNcjp2k930LtjjiFPH9NyMEALSFdYrdH 4WPtU/ZSU2V8KWhnQqIK5z1s2gsayKINEkXGCeIwpxsPcM2LbZn1LG6D6/1fE0avmaCN W5bo+rgrRE6Hjhj7Zyl/PWYz9ZQEsgjJagqLhMuD1+1xbb85483bXzmNzbPryzQ72Evx Bm414pKtd/gPpvMCSM3NLKTTF8sKKIPpUJtvYXmqe8I/J9qvKHK+ZVEkVljKUYUbuAIj GlnOWH1Burot4T8jjHdAVqOn9+3iepSEq1ubtZAlgg7CJhrQCKFDPFnie/An1qeFiCBb quSw== 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=+ZWFGyn7QgVdaJhnOjMHTVAP7/rq34baWPijoUd4nzQ=; b=Zsy1L3CaEA9WpRxdcRxLKzJPn7wUkhu0NTJgSs7E1pEvZLgBebPfL1rfU0qM9YvGwg kA3C42j8Lk9iYHJzg23InzW10rj8IdoFChFYUUrmKVHekOQPkorBTJgHZwMXkcfGH+bX CbP33tZAIxmDQEA+5rvezuxIxrEjgcWIcdurFW55rRR5DGXXxEvNdfqOZqAZWxxvwRMX xJm1tZym+LORvIeFvgP6w/sQ3gL5tLQ9fYh8H+xSeHHDhr1SQzxuQWvnzhhP0pikQp6w 8pT5NGAMzrXkT6oMbdqb02RYKzuSwyJUOwsCUmnkasxMIElClR6VncCM5cBlGg2yFxgi BTlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pEQS/aUu"; 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 ix6-20020a170902f80600b0016400fa42f2si4091905plb.454.2022.06.16.19.22.27; Thu, 16 Jun 2022 19:22:40 -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="pEQS/aUu"; 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 S1379482AbiFQCB4 (ORCPT + 99 others); Thu, 16 Jun 2022 22:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbiFQCBz (ORCPT ); Thu, 16 Jun 2022 22:01:55 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E49F56161A; Thu, 16 Jun 2022 19:01:53 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id me5so6064267ejb.2; Thu, 16 Jun 2022 19:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+ZWFGyn7QgVdaJhnOjMHTVAP7/rq34baWPijoUd4nzQ=; b=pEQS/aUuATRXcBxCdHguz7Q69pwt/BR7rOMmd/wTznMuK6YcHBylUynztCs7pBAojN ICu+0dCKYlvq/7ZQ3wruORkm9uVSlW0qkNyJEzSqkP9M+PZt+5eVAidm98LV0rWslf8X TFVXNobpRGyuhIIMgLbC+PKHkgXdq89Dxzx/VR8HMinZgtgyKtLZvZpEVwaYQDAGdXNq OLFRX0j2PIdfTYHAckmQH2XJK2aQMAsGyK00lwOpW8G0dahewGDU1SPvJFcPvtlZBL0F 2LV97P1sICVcuUQ0oUPaI4apMEOSVfiAbjN0qv/wd/gOH/Lb5vpQeD2w8EIcNFmxRZ+g FGJw== 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=+ZWFGyn7QgVdaJhnOjMHTVAP7/rq34baWPijoUd4nzQ=; b=70rJwVh6T9+t4yFi1DF3Yb5vTq9fmnhTy5OWv833bWHLj6KzwoWbhY004AAZEzH6jr xOOQTrX93P5w+GWiDEVQidUFLy+ovpc6ETtj/XaP6DrfGzTwui+hPtZMnekZBVg5n621 nHeKUMR2CckFU3Z7+djyo7Jxj7D+xVAVLmnzTu/BYUcFfGZGz9S+5tjtYTtdPY8d9LRl wuT1uGP53uSPbCt9xrCyJJJe4yAbjYyYT8Ty0qXyHItQp6Qw5iu5oFsWO81NSkCoIuJv 6ODX1kRYjH1R/67XAA1woBPtZXySTTHwG1PKZl6dkdH9+8MrC/xp9kpqpHWr39J4F85s DJMQ== X-Gm-Message-State: AJIora99PXxmg6MBI5GOfY5O9gFQWbSaTD449ki+rHqyEHzO1vla8J1E KZZA4bVs1+O/LAdoQJvQ+K/FMTl2asFqDuwtz0M= X-Received: by 2002:a17:907:9715:b0:711:ca06:ca50 with SMTP id jg21-20020a170907971500b00711ca06ca50mr7101055ejc.192.1655431312299; Thu, 16 Jun 2022 19:01:52 -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: Barry Song <21cnbao@gmail.com> Date: Fri, 17 Jun 2022 14:01:41 +1200 Message-ID: Subject: Re: [PATCH v11 07/14] mm: multi-gen LRU: exploit locality in rmap To: Yu Zhao 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=-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,T_SCC_BODY_TEXT_LINE 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 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 Barry