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 767DCC433EF for ; Mon, 9 May 2022 01:52:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDD176B0071; Sun, 8 May 2022 21:52:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8DB66B0073; Sun, 8 May 2022 21:52:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A54BF6B0074; Sun, 8 May 2022 21:52:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 962B86B0071 for ; Sun, 8 May 2022 21:52:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6F63F60E31 for ; Mon, 9 May 2022 01:52:38 +0000 (UTC) X-FDA: 79444530396.28.9848FB0 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf15.hostedemail.com (Postfix) with ESMTP id E1F61A0080 for ; Mon, 9 May 2022 01:52:25 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VCc7SF0_1652061151; Received: from 30.32.96.14(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VCc7SF0_1652061151) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 May 2022 09:52:32 +0800 Message-ID: <31e0001e-5274-742b-0cd9-318f5c2e068f@linux.alibaba.com> Date: Mon, 9 May 2022 09:53:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [RFC PATCH 0/3] Introduce new huge_ptep_get_access_flags() interface To: Matthew Wilcox Cc: catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, mike.kravetz@oracle.com, akpm@linux-foundation.org, sj@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: w7o1rpj87bwtx5y7uabbyk1me8trx6jb Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E1F61A0080 X-HE-Tag: 1652061145-459398 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 5/9/2022 1:08 AM, Matthew Wilcox wrote: > On Sun, May 08, 2022 at 04:58:51PM +0800, Baolin Wang wrote: >> As Mike pointed out [1], the huge_ptep_get() will only return one specific >> pte value for the CONT-PTE or CONT-PMD size hugetlb on ARM64 system, which >> will not take into account the subpages' dirty or young bits of a CONT-PTE/PMD >> size hugetlb page. That will make us miss dirty or young flags of a CONT-PTE/PMD >> size hugetlb page for those functions that want to check the dirty or >> young flags of a hugetlb page. For example, the gather_hugetlb_stats() will >> get inaccurate dirty hugetlb page statistics, and the DAMON for hugetlb monitoring >> will also get inaccurate access statistics. >> >> To fix this issue, one approach is that we can define an ARM64 specific huge_ptep_get() >> implementation, which will take into account any subpages' dirty or young bits. >> However we should add a new parameter for ARM64 specific huge_ptep_get() to check >> how many continuous PTEs or PMDs in this CONT-PTE/PMD size hugetlb, that means we >> should convert all the places using huge_ptep_get(), meanwhile most places using >> huge_ptep_get() did not care about the dirty or young flags at all. >> >> So instead of changing the prototype of huge_ptep_get(), this patch set introduces >> a new huge_ptep_get_access_flags() interface and define an ARM64 specific implementation, >> that will take into account any subpages' dirty or young bits for CONT-PTE/PMD size >> hugetlb page. And we can only change to use huge_ptep_get_access_flags() for those >> functions that care about the dirty or young flags of a hugetlb page. > > I question whether this is the right approach. I understand that > different hardware implementations have different requirements here, > but at least one that I'm aware of (AMD Zen 2/3) requires that all > PTEs that are part of a contig PTE must have identical A/D bits. Now, > you could say that's irrelevant because it's x86 and we don't currently > support contPTE on x86, but I wouldn't be surprised to see that other > hardware has the same requirement. Yes, so on x86, we can use the default huge_ptep_get(). But for ARM64, unfortunately the A/D bits of a contig PTE is independent, that's why we want a ARM64 specific huge_ptep_get(). > So what if we make that a Linux requirement? Setting a contPTE dirty or > accessed becomes a bit more expensive (although still one/two cachelines, > so not really much more expensive than a single write). Then there's no > need to change the "get" side of things because they're always identical. > > It does mean that we can't take advantage of hardware setting A/D bits, > unless hardware can be persuaded to behave this way. I don't have any > ARM specs in front of me to check. I hope the hardware can make sure the contPTE are always identical, however in fact like I said the A/D bits setting of a contig PTE by hardware is independent in a contig-PTE size hugetlb page, they are not always identical. From my testing, if I monitored a contig-PTE size hugetlb page with DAMON, and I only modified the subpages of the contig-PTE size hugetlb page. The result is I can not monitor any accesses, but actually there are. So I think an ARM64 specific huge_ptep_get() implementation seems the right way as Muchun suggested? Thanks.