From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D5C9C433EF for ; Sun, 19 Jun 2022 20:37:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA2C06B0071; Sun, 19 Jun 2022 16:37:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C53236B0072; Sun, 19 Jun 2022 16:37:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1B176B0073; Sun, 19 Jun 2022 16:37:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A31B76B0071 for ; Sun, 19 Jun 2022 16:37:06 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7395C20DCD for ; Sun, 19 Jun 2022 20:37:06 +0000 (UTC) X-FDA: 79596144852.17.FA2B38A Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) by imf17.hostedemail.com (Postfix) with ESMTP id 0D79C4000E for ; Sun, 19 Jun 2022 20:37:05 +0000 (UTC) Received: by mail-ua1-f53.google.com with SMTP id k19so3299891uap.7 for ; Sun, 19 Jun 2022 13:37:05 -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=mTIGwSFk5YWUK9VSbfy6N1NsIQybja1kZ/BQ9GPd0+Y=; b=l25j73P7uJr58OFr2RGZNSJFVUCIeErBN47QJRfE2KM7Uem87KOiTXbYIgXi9BxcTt sWYzpKDC6TGrQBTNQtuNdwtbaYnKJsgVaVdsFZv+IaMn2DToZeV6vPizK7ZrDQXMU+hf bdMAbun9VCUdeNKzyk74H49QlWqEeiCLPNdzifHPqxmz+bLx0QxUII9eSfw/3kU9XLNZ 4jP9lF/7w+PLBz1HxpHA6UI9U5s8bgtiXE7XVUEMHCx5c0o066pja90toaVh0LoVQ8r8 3rvDDt0Ql56kDzrOrxIKiLS6qxdHVoVpNW3A91/zB3K9qFIdJ0rxYpAOCWbW9ffeACS7 fipQ== 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=mTIGwSFk5YWUK9VSbfy6N1NsIQybja1kZ/BQ9GPd0+Y=; b=OjglLLXX8WP+9Stn55gIUlv4d3kmHR6vPo6jSAMiGz8dtFxBX5iXnUSpNCPKNRPnEK tAZTmuevbvYUSiZgCLcaqkhtKT5+gjsef5rhYO0NkeuzVCfsPvPIA0lc73KnYGoc8WgB dUOgWUTfa+eur/BSOUEgY2A/Ykc2jZaSpsqb1S5ZN8FLVrypbGK89xL0rVcVIK+x2bLY 6aSebOwj0opo8zq9DZYVpPT6wCe6HqWVsa41BGNFrBQIIobFlIOJlSqdYf0SKVih56k7 Tikigwg2MLvyaniVNqDLKSswaIYEj8Z6FEViU9TkMdqLGVXXvl5fIw2mnGQANQOVx9UU jazA== X-Gm-Message-State: AJIora/CH+5KUO1PT+pY8IjYPcTt/SO0BS1MOFpFwcad+NL+tkp6naWB GPMKF/SFIa0ZDborT/UVDEOk+kTqQnWG6hHupEMBzw== X-Google-Smtp-Source: AGRyM1uMtPky5PtZiObhqzIZShVdQHEZeFoF4ilcyHi/Ou4NXdsu8HPwWiKFza3RkKGzM6ygUE5FHweIOepNwDHpGRo= X-Received: by 2002:ab0:2695:0:b0:352:5fc9:4132 with SMTP id t21-20020ab02695000000b003525fc94132mr7178761uao.29.1655671025102; Sun, 19 Jun 2022 13:37:05 -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: Sun, 19 Jun 2022 14:36:28 -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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655671026; a=rsa-sha256; cv=none; b=m2tGT+CsRE8Pn5WoZGY78450ipjSfYKV4uCf2V/srvn2jHElEC2XKvoTn3K0L/t/LH4tqv u8vMaa5jqUuKEgX8dvPKzYgm7bbV8zZbSnx+uKSGSL1adgxCu6W4wMs+tCEEGaklB58MQh qY2PsUbrOKRDwZtf4ol1j/ke+dI34pU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=l25j73P7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of yuzhao@google.com designates 209.85.222.53 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655671026; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mTIGwSFk5YWUK9VSbfy6N1NsIQybja1kZ/BQ9GPd0+Y=; b=mpWpeaB4FKkMgxG0BulfD/lkMVa2FwG7qy2U/Q2xgmmF7aQUviyOR5YtpUCZcjj7fcKUGW jujlVvZXR0ny7w+fe1iNJC2Vja3Sad4Z9CVUYfPMhnV6HXgQXyIAlY5vv7rjvk8WIpAGQK 7c73q0ZT9Pp9M5oqT1y3SVOS/0BRWt0= X-Rspamd-Server: rspam01 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=l25j73P7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of yuzhao@google.com designates 209.85.222.53 as permitted sender) smtp.mailfrom=yuzhao@google.com X-Stat-Signature: n79i1yfetjx9hzmrwmdhfuse3ai5wyjb X-Rspamd-Queue-Id: 0D79C4000E X-HE-Tag: 1655671025-40071 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jun 16, 2022 at 9:17 PM Yu Zhao wrote: > > On Thu, Jun 16, 2022 at 9:03 PM Yu Zhao wrote: > > > > 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. > > Also, IIRC, it made no difference on POWER9 because POWER9 > flushes TBL regardless which variant is used. ^^^^^^^ doesn't flush I just verified this on POWER9. So on top of exhibit 1-4, we got: 5. 3cb1aa7aa3940 ("powerpc/64s: Implement ptep_clear_flush_young that does not flush TLBs")