Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4843573iob; Mon, 9 May 2022 03:00:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEOxQ2e8XwsL0qu6PzB5f3cD5pZOKFxFiZPtrpJYHcznaLA9OkjdTCh88I4bifFNFgG9Jv X-Received: by 2002:a63:d504:0:b0:3c6:ab6b:fd2b with SMTP id c4-20020a63d504000000b003c6ab6bfd2bmr4937269pgg.437.1652090432736; Mon, 09 May 2022 03:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652090432; cv=none; d=google.com; s=arc-20160816; b=mLDiFGtv37PmV3E006ZluuoJIB8qRtqKJQ7un1tY3KswIJBct10B94iSYZnjl6GQMU 7PbyDoFEWhOZc1StoQ4k2ZZZYdW7W/AbmTXA+UCAm0WTzzjEbOp67Dxbk5Nrk3HYkKLb xYp1uE92oJBR1/eg0hp2CuCpSce+qG1QG3u8Cq38RYQrA9bc4iYQDTWNqv2FB0SBaEm9 q7CljiPLo9fg1nl10kpJy5Muan8nJxPcIuTj/FfANXma6mc9xmSkXtBqiS+e8ZHsnc12 uHkSwn3K19bF2EbSVAVW5sY6IjKfIoaHvjDIvJNH7VWMBE4EK+BjlEqDnHsCKwN6Wvpy PFTg== 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=hHxgUoZkoq1iSOP+0c8QaatKIJeI0SnJ7IlHoxp8qX4=; b=KRCcSylmWNBUqn8qeA8Xuq3b8ixx1dUsMuPOplc/F36nFcDJiFzC6ABBWk+4OjAj3J TZXly9Dl3qWH/nnqrmrnPX+aFq4caOOBaBPAeNuhuWeEC/AsyO6Hp3U2LJYb7+EFwB5f RVziUz5M7NKX0He4GN82naHz5+U/jw+gbdhbh/ayiOBS8pZSEjDOAao8+qWECPKmATFU cW7on/O+Etv14fXNZQLas49b2M1FZXZxFB0ejSdAgz7UGopumm4dXyd0fPuORvIJhHE7 hWXtRz3eWPtRtP1PPSGfRQJsBbC/9+VhtfkVNSHgGFbFRIpWdFNwPv+nMNOzQJwoNxD8 g4lQ== 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 q12-20020a170902f78c00b0015e8cab9951si12031461pln.296.2022.05.09.03.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:00:32 -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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 05C3116D5C0; Mon, 9 May 2022 02:43:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232252AbiEIBrC (ORCPT + 99 others); Sun, 8 May 2022 21:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233813AbiEIBlb (ORCPT ); Sun, 8 May 2022 21:41:31 -0400 Received: from out199-17.us.a.mail.aliyun.com (out199-17.us.a.mail.aliyun.com [47.90.199.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44C3E36172; Sun, 8 May 2022 18:37:33 -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=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 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/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.