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 X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4BD1C433DB for ; Mon, 28 Dec 2020 16:41:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 469D32245C for ; Mon, 28 Dec 2020 16:41:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 469D32245C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 665946B00A3; Mon, 28 Dec 2020 11:41:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 616166B00AE; Mon, 28 Dec 2020 11:41:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 505746B00CF; Mon, 28 Dec 2020 11:41:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 3950F6B00A3 for ; Mon, 28 Dec 2020 11:41:47 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 03C7D181AEF07 for ; Mon, 28 Dec 2020 16:41:47 +0000 (UTC) X-FDA: 77643257454.19.peace42_2b056ec27495 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id D6B701AD1B5 for ; Mon, 28 Dec 2020 16:41:46 +0000 (UTC) X-HE-Tag: peace42_2b056ec27495 X-Filterd-Recvd-Size: 7447 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Dec 2020 16:41:46 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id b8so5888568plx.0 for ; Mon, 28 Dec 2020 08:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9BSdNC8lHN68aG8S1wMx9ZgOFQWuy+oQNc4t7FQtAYE=; b=JCYWpHOzrc0moPNkbT4K1+8ejthEgyO6J+0H5rLuTnRgqihY4K8EhTtP+EVmWbPcFR SM7d3vlwF1uregFJzL88mMfEgzxWPySQMav0rGrq2KbjIKi9z6NsdGFpenHQyBHrG15Q s2zNXzxrf3uruZ6May8QER0dm9ZwgtH1Bw19ePcMnU0bT8yLCiLsRpSoA6a+Ee9uy80a VTXp4hvFo5LyOivbl+eL4I9B5I1N1RPJlKFswoJegcrbaR06PqMguSQZH7Q5apu8Zx+e IAJ5rjKcRFa1h+DzzYqVMqzYAsITA8GkCzfxMfOYD7VaBybB+Pi8J6qBO53r3G0QVr13 h6LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9BSdNC8lHN68aG8S1wMx9ZgOFQWuy+oQNc4t7FQtAYE=; b=MXxFDCeu1j+rrVYNqzNBTJiXPlfyGNToZTjpMozx9dLnn3fXHXtu0vgDxwlRJ1CIF2 9uAqI5FEkzXMCsxPS1V0YGftnAuLT9U2CDn9RdLXedc8QSPZukMWRO2vwG93MnAYpZDt 9kFy6DaYgipH9K3sl9uRFAzvruBLY3GrwyEXhx8v1spV7ugoIheaWqsmGS7X2ayE3yLt bBkmC+0MPWNkZBgRg6GP1SQeIZq6HK6KoCctav+2TIhC2aQ7e2V4dInBI3wu5NFqxD1r IGDyko6IEAMQeQnTJFpCj7q8BzQ9dJ2fsKkfHVOiyFM5zSHxSjXoOD/uHz2XUQnN+aAs oaWA== X-Gm-Message-State: AOAM533d4VAO9WoYnYEQ7fmC7eLzKGfksVCgid5lT0yIiETL6FFdUJws koW0rCv64eOlIkLb3HlafyEUQQ== X-Google-Smtp-Source: ABdhPJxAsU7Sl6jwmVE3eF9OBJcHYEzT4YfT0iEa1UE3vbAPHhVTqkxccOtN05cA6OtQKkHz+belZQ== X-Received: by 2002:a17:90a:f687:: with SMTP id cl7mr21932851pjb.38.1609173704721; Mon, 28 Dec 2020 08:41:44 -0800 (PST) Received: from localhost.bytedance.net ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id r68sm36686306pfr.113.2020.12.28.08.41.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Dec 2020 08:41:44 -0800 (PST) From: Muchun Song To: gregkh@linuxfoundation.org, rafael@kernel.org, adobriyan@gmail.com, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, hughd@google.com, shakeelb@google.com, guro@fb.com, samitolvanen@google.com, feng.tang@intel.com, neilb@suse.de, iamjoonsoo.kim@lge.com, rdunlap@infradead.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Muchun Song Subject: [PATCH v6 0/7] Convert all THP vmstat counters to pages Date: Tue, 29 Dec 2020 00:41:03 +0800 Message-Id: <20201228164110.2838-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: This patch series is aimed to convert all THP vmstat counters to pages. The unit of some vmstat counters are pages, some are bytes, some are HPAGE_PMD_NR, and some are KiB. When we want to expose these vmstat counters to the userspace, we have to know the unit of the vmstat counter= s is which one. When the unit is bytes or kB, both clearly distinguishable by the B/KB suffix. But for the THP vmstat counters, we may make mistakes= . For example, the below is some bug fix for the THP vmstat counters: - 7de2e9f195b9 ("mm: memcontrol: correct the NR_ANON_THPS counter of hi= erarchical memcg") - The first commit in this series ("fix NR_ANON_THPS accounting in char= ge moving") This patch series can make the code clear. And make all the unit of the T= HP vmstat counters in pages. Finally, the unit of the vmstat counters are pages, kB and bytes. The B/KB suffix can tell us that the unit is bytes or kB. The rest which is without suffix are pages. In this series, I changed the following vmstat counters unit from HPAGE_P= MD_NR to pages. However, there is no change to the print format of output to us= er space. - NR_ANON_THPS - NR_FILE_THPS - NR_SHMEM_THPS - NR_SHMEM_PMDMAPPED - NR_FILE_PMDMAPPED Doing this also can make the statistics more accuracy for the THP vmstat counters. This series is consistent with 8f182270dfec ("mm/swap.c: flush = lru pvecs on compound page arrival"). Because we use struct per_cpu_nodestat to cache the vmstat counters, whic= h leads to inaccurate statistics especially THP vmstat counters. In the sys= tems with hundreds of processors it can be GBs of memory. For example, for a 9= 6 CPUs system, the threshold is the maximum number of 125. And the per cpu counters can cache 23.4375 GB in total. The THP page is already a form of batched addition (it will add 512 worth= of memory in one go) so skipping the batching seems like sensible. Although = every THP stats update overflows the per-cpu counter, resorting to atomic globa= l updates. But it can make the statistics more accuracy for the THP vmstat counters. From this point of view, I think that do this converting is reasonable. Thanks Hugh for mentioning this. This was inspired by Johannes and Roman. Thanks to them. Changes in v5 -> v6: - Fix compiler errors when CONFIG_TRANSPARENT_HUGEPAGE is not set/enabl= ed reported by Randy Dunlap . Thanks. - Fix typo in the commit message. Changes in v4 -> v5: - Add motivation to each patch. Thanks to Michal. - Replace some HPAGE_PMD_NR to thp_nr_pages(). Thanks to Matthew. Changes in v3 -> v4: - Rename the first commit subject to "mm: memcontrol: fix NR_ANON_THPS accounting in charge moving". - Fix /proc/vmstat printing. Thanks to Johannes points out that. Changes in v2 -> v3: - Change the series subject from "Convert all vmstat counters to pages = or bytes" to "Convert all THP vmstat counters to pages". - Remove convert of KB to B. Changes in v1 -> v2: - Change the series subject from "Convert all THP vmstat counters to pa= ges" to "Convert all vmstat counters to pages or bytes". - Convert NR_KERNEL_SCS_KB account to bytes. - Convert vmstat slab counters to bytes. - Remove {global_}node_page_state_pages. Muchun Song (7): mm: memcontrol: fix NR_ANON_THPS accounting in charge moving mm: memcontrol: convert NR_ANON_THPS account to pages mm: memcontrol: convert NR_FILE_THPS account to pages mm: memcontrol: convert NR_SHMEM_THPS account to pages mm: memcontrol: convert NR_SHMEM_PMDMAPPED account to pages mm: memcontrol: convert NR_FILE_PMDMAPPED account to pages mm: memcontrol: make the slab calculation consistent drivers/base/node.c | 27 +++++----- fs/proc/meminfo.c | 10 ++-- include/linux/mmzone.h | 17 +++++++ mm/filemap.c | 4 +- mm/huge_memory.c | 11 +++-- mm/khugepaged.c | 6 ++- mm/memcontrol.c | 132 +++++++++++++++++++++++--------------------= ------ mm/page_alloc.c | 7 ++- mm/rmap.c | 26 ++++++---- mm/shmem.c | 2 +- mm/vmstat.c | 11 ++++- 11 files changed, 142 insertions(+), 111 deletions(-) --=20 2.11.0