Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp696211rwb; Wed, 26 Jul 2023 00:59:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlHGiGNpujGO85iiUvI7sgbLBiB1clxRpj909Md/UFMeQnBOIl5tetxw7ij5hVrdS968C/yQ X-Received: by 2002:a05:6358:7249:b0:134:c859:d32a with SMTP id i9-20020a056358724900b00134c859d32amr1687780rwa.25.1690358384732; Wed, 26 Jul 2023 00:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690358384; cv=none; d=google.com; s=arc-20160816; b=dT9WLbkaB2DQj1jmBJDDgc/PTNHJo3xXNRViB3anEeud/RZewgTOb51Vbu1t00qDGk ofA7bHF5HGwL1xmC7tp8g8ovJ1uD3kI3urV34PvMrSPGker7Q6PES9rKYCbsntlVn6gT U9Jf4nomwMONTWf4VGiZwO4Ghem2WOWhYS8SJdQeBAED57bs/R6VKiPVUaUz16P9+KIP vhht2zwQ1V/sHrtU3UGQI0Jf59nZHPnqoCcDDezaFsksZa/S5lq6oSP/C/xa0wu6gT28 I+WrMxQgE4FWQMeJE5fhgXHy0V3Opj8mUpQSg5P30V+ImFq5IIzs6mZzxS9uqXM2sci/ R/2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=YSdWl6wNEr9ybpm3m+mDG8ufve26P+MxdGuyv5egikY=; fh=83Kw27EQzHBVWelIw0jozTWsf2k3JlnM5i+bulVuF9o=; b=iPc7j/WnRfPweFEuD+3UncdBCy9y8focw42K0sfG/OequWe+HlvGI4qdFXEnsYfObD qRY9X2CDljCziFfTxnme8BGG5LxrL8WB/A9zl5SA0mVm317c93CD3aqrioES+fRH9QK3 oyn7vueS83IvlpIxgLV1hByHU4mpm4dYepYkfxmjt9AK6AWbshXNZPIynSH+HnkC6ARw +GuS0Q5Yt/uaS3574aE1QOsqojbrsdfxLKKsL8GD1oxa2IbT6eogGk6fx3ij51mhEQm4 SgBltQQRUol5WCeOTclXBnkpvUdhgcqqFQEj7tnH3SaUULtMcgqSOcUlyR1cp6eqpF2N 8fXQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb21-20020a056a004c9500b00661759efb4esi12581491pfb.229.2023.07.26.00.59.31; Wed, 26 Jul 2023 00:59:44 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbjGZHiY (ORCPT + 99 others); Wed, 26 Jul 2023 03:38:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232550AbjGZHht (ORCPT ); Wed, 26 Jul 2023 03:37:49 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 339CE449A; Wed, 26 Jul 2023 00:35:47 -0700 (PDT) Received: from kwepemm600016.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R9lwZ58g1ztRpc; Wed, 26 Jul 2023 15:32:30 +0800 (CST) Received: from huawei.com (10.175.124.27) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 26 Jul 2023 15:35:44 +0800 From: liubo To: CC: , , , , , Subject: [PATCH] smaps: Fix the abnormal memory statistics obtained through /proc/pid/smaps Date: Wed, 26 Jul 2023 15:34:09 +0800 Message-ID: <20230726073409.631838-1-liubo254@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 In commit 474098edac26 ("mm/gup: replace FOLL_NUMA by gup_can_follow_protnone()"), FOLL_NUMA was removed and replaced by the gup_can_follow_protnone interface. However, for the case where the user-mode process uses transparent huge pages, when analyzing the memory usage through /proc/pid/smaps_rollup, the obtained memory usage is not consistent with the RSS in /proc/pid/status. Related examples are as follows: cat /proc/15427/status VmRSS: 20973024 kB RssAnon: 20971616 kB RssFile: 1408 kB RssShmem: 0 kB cat /proc/15427/smaps_rollup 00400000-7ffcc372d000 ---p 00000000 00:00 0 [rollup] Rss: 14419432 kB Pss: 14418079 kB Pss_Dirty: 14418016 kB Pss_Anon: 14418016 kB Pss_File: 63 kB Pss_Shmem: 0 kB Anonymous: 14418016 kB LazyFree: 0 kB AnonHugePages: 14417920 kB The root cause is that the traversal In the page table, the number of pages obtained by smaps_pmd_entry does not include the pages corresponding to PROTNONE,resulting in a different situation. Therefore, when obtaining pages through the follow_trans_huge_pmd interface, add the FOLL_FORCE flag to count the pages corresponding to PROTNONE to solve the above problem. Signed-off-by: liubo Fixes: 474098edac26 ("mm/gup: replace FOLL_NUMA by gup_can_follow_protnone()") --- fs/proc/task_mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index c1e6531cb02a..ed08f9b869e2 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -571,8 +571,10 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, bool migration = false; if (pmd_present(*pmd)) { - /* FOLL_DUMP will return -EFAULT on huge zero page */ - page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP); + /* FOLL_DUMP will return -EFAULT on huge zero page + * FOLL_FORCE follow a PROT_NONE mapped page + */ + page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP | FOLL_FORCE); } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry = pmd_to_swp_entry(*pmd); -- 2.27.0