Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4844539iob; Mon, 9 May 2022 03:01:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGWT8F85dPR+kt83SEClD+ThIQshPbk9WR3AFFnuKk7gFv3FhcA+kFKq1RJPiRBpcCML2F X-Received: by 2002:a17:90a:db95:b0:1d9:782f:a4c8 with SMTP id h21-20020a17090adb9500b001d9782fa4c8mr25141866pjv.154.1652090497091; Mon, 09 May 2022 03:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652090497; cv=none; d=google.com; s=arc-20160816; b=HBiJebkluVuXdSCo6OdUkFFo1kK9lq1XF+tU0SnSINGMQRxonhFpBk9zXo729P/mJh jKlKfRJ/T73VPDy3w0YA7bdc7lhriJob6bryVxW/mFBg2Ab3mN5HbBELmunQQUwpzuWN x7wXzTDqb0wb+piUupWPmeA09iw9P/ZrW9vVb42YkFPFomlfFjMhfP2t4e0s/2483dxk lP083zpdLDgada8aCGkAuGWXe4IJz4d7X74hOxPrL6JCaKPveUnitxPQaH6SJiyMYJK0 AbiBC4kC4ele5Pv5EjbhuZadZUQBwVTfGZlHwSxHjh4HBdZ/xNY+58fz0bpqnBukMY26 3AJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=LjY/bDJbSkyVfi2RxsFxTMMP4zTXsbWnQWtizGFqad0=; b=dBuAyXXHFYxttNt/QObqFxo4WL8Y8rs/P4eorTaAN8Ablk32GpyGDDxWH3vZg9U3Rk nvCSgFnOJeeZleK5nWlUsS3mn+NXf6q4eEXmSYpW8BEgBFntJRKTqp8RjpE5pjBeMB3e 7h1KbqCRKhS0Cj3x9gNolRHv2rBkRgtl8RjjE7oS8vcO2orWVFdOhr4ma5gypGMgtApT 0Zo4wjLgNZhpKUnyNA61CjKq7TjhlWEc0mjcfQYgA1xlLqLZHjpJMa2lxHc8AHUpslEz 1GRiIZ0OtzD3SZ9InlmYqrkXieCwqWt1h6QWXEknwHPGNRooLenhJaJsrHU74ZzZuqZG 1CFA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s3-20020a17090aad8300b001d8f3569fb9si19315632pjq.165.2022.05.09.03.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:01:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6387D18B944; Mon, 9 May 2022 02:44:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbiEICBq (ORCPT + 99 others); Sun, 8 May 2022 22:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234093AbiEIB4b (ORCPT ); Sun, 8 May 2022 21:56:31 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21760433BF; Sun, 8 May 2022 18:52:35 -0700 (PDT) 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-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable 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 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.