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 0A89AC433F5 for ; Mon, 9 May 2022 01:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38AAE6B0071; Sun, 8 May 2022 21:34:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 339B66B0073; Sun, 8 May 2022 21:34:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 201436B0074; Sun, 8 May 2022 21:34:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 117046B0071 for ; Sun, 8 May 2022 21:34:17 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id D7EA7120C4D for ; Mon, 9 May 2022 01:34:16 +0000 (UTC) X-FDA: 79444484112.11.189536A Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 2D95E4005E for ; Mon, 9 May 2022 01:33:58 +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=e01e04426;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VCc6dHr_1652060050; Received: from 30.32.96.14(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VCc6dHr_1652060050) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 May 2022 09:34:11 +0800 Message-ID: <97bb8f7e-38ce-4a21-fb76-4bd040ec00b7@linux.alibaba.com> Date: Mon, 9 May 2022 09:34:51 +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: Muchun Song 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 Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2D95E4005E X-Stat-Signature: gnqn4eg6dfr5fobs5x1px5q9brpjo9gy X-HE-Tag: 1652060038-262264 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/8/2022 11:26 PM, Muchun Song wrote: > On Sun, May 08, 2022 at 04:58:51PM +0800, Baolin Wang wrote: >> Hi, >> >> 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. > > IIUC, we could get the page size by page_size(pte_page(pte)). > So, how about the following implementation of huge_ptep_get()? > Does this work for you? > > pte_t huge_ptep_get(pte_t *ptep) > { > int ncontig, i; > size_t pgsize; > pte_t orig_pte = ptep_get(ptep); > > if (!pte_present(orig_pte) || !pte_cont(orig_pte)) > return orig_pte; > > ncontig = num_contig_ptes(page_size(pte_page(orig_pte)), &pgsize); > > for (i = 0; i < ncontig; i++, ptep++) { > pte_t pte = ptep_get(ptep); > > if (pte_dirty(pte)) > orig_pte = pte_mkdirty(orig_pte); > > if (pte_young(pte)) > orig_pte = pte_mkyoung(orig_pte); > } > > return orig_pte; > } Thanks for your suggestion, and I think this works for me and looks more straight forward in case some functions using huge_ptep_get() will care about the young or dirty bits in future. My only concern is that all the functions using huge_ptep_get() will set a contPTE dirty or accessed bit, however most functions do not care about the dirty and accessed bit, which becomes a bit more expensive for them? Also mentioned by Matthew in his comments. Anyway, I still think your suggestion is straight forward and I can change in next version if no other objections.