Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1402590iof; Tue, 7 Jun 2022 05:05:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMuokdIC4BFUyEaZSsu2Ir1LR+NkSFP8KaPdX7Mia3K4/vUNCXsJm+GryxliU+p3FlSpcx X-Received: by 2002:a05:6402:510e:b0:42d:f887:b142 with SMTP id m14-20020a056402510e00b0042df887b142mr32913930edd.291.1654603514933; Tue, 07 Jun 2022 05:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654603514; cv=none; d=google.com; s=arc-20160816; b=j4Ti3d6I2sx00hBddR/OPxvfAO83or2pr3V0qN0X37ugHDs+gnZKi6LDY1zgBNuaiS v9/FleZOgJFDOa6JiwzksQ+Fk4BOvJgRH+p0P83rsE+9RFSOwHKyexgpJHuQ984wF7s2 bXDF5+IVsjzK5WcwaFdpvrmhA/rNxpPuFwlmmgFt1DBRFQxx24Ao0hF18FNoPdNwH90d 7+V9R0AWUCf+9PAwG4hgyE/zYEo2q30/tpayGK/+3xMhcMT/Lgt+UEsBvHao1f6KpPRs bb/lWeTTfLa3RAq7kP8YYaUSVA71cgaM9lMdq+GbddDMVvHWHcgvUrt8vUQr6BqJmYEg KR4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=PWtwZMJcB8ZGE99bUSF0DtBeF3aIrmN+X0NYY/wLznA=; b=OKR/twOpKSEUfyJ8dThJ/scsvINvc7uRnMQ9rjc9MSoflXfQ1aN0wWzFlYsRgMt2sq fgjXrrWcDWlAidLkAdjSOtzuHgGSUqg1j4pNy+tTY0iHtH9R4UXW1gycnzaUejxy7fU9 QdfX0sKwQpetPVt0C10ib3m7IqI8Uo1LoCqKuEtZrbN6U2r2KX/tpWe7A3AtTXQdGUDT DIymPEIDyznG25VAIDcBt2Mv5PyzttKTDRzoB/I6O8NXX7TGYUrCMz8uB1rGi5VpzISH xlvL60opxok/i663HH6st7pBV7yb/bZtGAeX64IrQHWxzxvm6yzwi2fQ7+svAFJ9/Ogt b5JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KoHdDKky; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056402270700b0043169fcf02asi6031983edd.325.2022.06.07.05.04.46; Tue, 07 Jun 2022 05:05:14 -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=@kernel.org header.s=k20201202 header.b=KoHdDKky; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241349AbiFGKo0 (ORCPT + 99 others); Tue, 7 Jun 2022 06:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241436AbiFGKoU (ORCPT ); Tue, 7 Jun 2022 06:44:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FAA331525; Tue, 7 Jun 2022 03:44:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 41E2DB81EF1; Tue, 7 Jun 2022 10:44:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CED0C34119; Tue, 7 Jun 2022 10:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654598649; bh=nfhDJ6GngF8XvKMVRBe5yZml/Bij47qErsn7ksIcrqE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KoHdDKkyuckDx5pSqItebxhU46zBZqhQHomsHausLkCsqN6+q54WWdJzH3Cm0flO0 F9fV0/66aX7znXvR0NEsQjgAfYG+p5crwv/6kA1mJrwFkUmkVjBW5oH/mpIo7EJNRz HUHWRYUCrhF4yi5MWePnMKrO9WnCAZIaWWzZnIF3jVx3ORZ8ZIq0vu5aKuUjmPr8gt EQ2Elys6X55LuWU1ea/ad2e7G0HwJo815xuuNNL2iUjvCOHnWohMG2Y/Ndv6fJMv3M kEgV+yKqmvfiAHExjbwt2ItT6EIkCZEHLJ+yj6SDpPtp8PAr/YzqtciRTJ4OuGeg3N D4MmMCUIZg31w== Date: Tue, 7 Jun 2022 11:43:58 +0100 From: Will Deacon To: Barry Song <21cnbao@gmail.com> Cc: Yu Zhao , Andrew Morton , Linux-MM , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Johannes Weiner , Jonathan Corbet , Linus Torvalds , 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 , Holger =?iso-8859-1?Q?Hoffst=E4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain , huzhanyuan@oppo.com Subject: Re: [PATCH v11 07/14] mm: multi-gen LRU: exploit locality in rmap Message-ID: <20220607104358.GA32583@willie-the-truck> References: <20220518014632.922072-1-yuzhao@google.com> <20220518014632.922072-8-yuzhao@google.com> <20220607102135.GA32448@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Tue, Jun 07, 2022 at 10:37:46AM +1200, Barry Song wrote: > On Tue, Jun 7, 2022 at 10:21 PM Will Deacon wrote: > > On Tue, Jun 07, 2022 at 07:37:10PM +1200, Barry Song wrote: > > > I can't really explain why we are getting a random app/java vm crash in monkey > > > test by using ptep_test_and_clear_young() only in lru_gen_look_around() on an > > > armv8-a machine without hardware PTE young support. > > > > > > Moving to ptep_clear_flush_young() in look_around can make the random > > > hang disappear according to zhanyuan(Cc-ed). > > > > > > On x86, ptep_clear_flush_young() is exactly ptep_test_and_clear_young() > > > after > > > 'commit b13b1d2d8692 ("x86/mm: In the PTE swapout page reclaim case clear > > > the accessed bit instead of flushing the TLB")' > > > > > > But on arm64, they are different. according to Will's comments in this > > > thread which > > > tried to make arm64 same with x86, > > > https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1793881.html > > > > > > " > > > This is blindly copied from x86 and isn't true for us: we don't invalidate > > > the TLB on context switch. That means our window for keeping the stale > > > entries around is potentially much bigger and might not be a great idea. > > > > > > If we roll a TLB invalidation routine without the trailing DSB, what sort of > > > performance does that get you? > > > " > > > We shouldn't think ptep_clear_flush_young() is safe enough in LRU to > > > clear PTE young? Any comments from Will? > > > > Given that this issue is specific to the multi-gen LRU work, I think Yu is > > the best person to comment. However, looking quickly at your analysis above, > > I wonder if the code is relying on this sequence: > > > > > > ptep_test_and_clear_young(vma, address, ptep); > > ptep_clear_flush_young(vma, address, ptep); > > > > > > to invalidate the TLB. On arm64, that won't be the case, as the invalidation > > in ptep_clear_flush_young() is predicated on the pte being young (and this > > patches the generic implementation in mm/pgtable-generic.c. In fact, that > > second function call is always going to be a no-op unless the pte became > > young again in the middle. > > thanks for your reply, sorry for failing to let you understand my question. > my question is actually as below, > right now lru_gen_look_around() is using ptep_test_and_clear_young() > only without flush to clear pte for a couple of pages including the specific > address: > void lru_gen_look_around(struct page_vma_mapped_walk *pvmw) > { > ... > > for (i = 0, addr = start; addr != end; i++, addr += PAGE_SIZE) { > ... > > if (!ptep_test_and_clear_young(pvmw->vma, addr, pte + i)) > continue; > > ... > } > > I wonder if it is safe to arm64. Do we need to move to ptep_clear_flush_young() > in the loop? I don't know what this code is doing, so Yu is the best person to answer that. There's nothing inherently dangerous about eliding the TLB maintenance; it really depends on the guarantees needed by the caller. However, the snippet you posted from folio_referenced_one(): | if (pvmw.pte) { | + if (lru_gen_enabled() && pte_young(*pvmw.pte) && | + !(vma->vm_flags & (VM_SEQ_READ | VM_RAND_READ))) { | + lru_gen_look_around(&pvmw); | + referenced++; | + } | + | if (ptep_clear_flush_young_notify(vma, address, Does seem to call lru_gen_look_around() *and* ptep_clear_flush_young_notify(), which is what prompted my question as it looks pretty suspicious to me. Will