Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1635552pxu; Sun, 6 Dec 2020 02:21:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeICAXGQHSU+47As6H1cWaD38RHyIBMe/ngHAsiwfp31ecR7P2NzkB7dImXjvbhcqCAgih X-Received: by 2002:a50:cd84:: with SMTP id p4mr14903284edi.81.1607250067230; Sun, 06 Dec 2020 02:21:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607250067; cv=none; d=google.com; s=arc-20160816; b=Kh8ccbsb+GNE1GnewvKBSMf1aU7GWw2STguX5lPtRGv0akJFNimRNUlM+CXtuaxHju B+MTMpF5MWYMDXZ3JaoQQXpeWGmit0quC1mX6IBzrs1WkZoRK3BPv+tp/OxHd1mdywoA FP6UkESPxgh7J5ezHJ6E+aX5QEcztwLAV9c+YOH3dxNZ2WhnvyFRQzP0b7RHDcejw6F/ /eXLV+i1Sujh9ROE606D4QezLRCRGoI1EATvMs5zNc9u4twxtvrCvOrak6akKeuFXlNB rToHMyeIchbS3YYuVe8SZTfEJ7y+qzwZgWwmiyUJxLdkgfvZbHvEqMdfqRj//lC4bvXf MrFA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tb1F00/nSlox2NKAPVic2CylQOjgm2ke+JSF79slOJI=; b=c3kQpJ59MtwI4NPlgVopW7GjzX+U59601gtHCuhtiWkoEOpBYuyTE52a2RS86kSglL 5ybxgWmeHo//5eKr0KgTWlGpgtboLbNdV43IGqG3wztZvz/AvU8uX7lUeRgBqLhu4Cx1 2bb+EtQERN5SPudG3V3S5yFfcKCJiPHtUyKFeF/UiU/5DZvxUuZvi2yCPhlS4dK6gUHp MBY/Upe7gwfVZRIt7J+gZEtLIASaSTTVsc2qltY9bcDAP07KIpAhdw5PuZQNNATYbJx9 E0nCPu7guD5twXDwcSokGAYd2BLe2hqD7ueJ6XMp2/cJr59ynsWdHJz1KbBbxMWxUUsq sENQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=uAhtAkvD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y24si6031338edl.364.2020.12.06.02.20.44; Sun, 06 Dec 2020 02:21:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=uAhtAkvD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbgLFKRz (ORCPT + 99 others); Sun, 6 Dec 2020 05:17:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbgLFKRy (ORCPT ); Sun, 6 Dec 2020 05:17:54 -0500 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92407C061A53 for ; Sun, 6 Dec 2020 02:17:08 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id v1so5664618pjr.2 for ; Sun, 06 Dec 2020 02:17:08 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=tb1F00/nSlox2NKAPVic2CylQOjgm2ke+JSF79slOJI=; b=uAhtAkvDbhKkFqddHAKBOhza/mhkmYbQ1gO6u++TYaJcsXVMyP3DxJmUjnpMeUG3SW XaMHSAVvWel0CQp+XAMCU1fy5kVW4g/nQk1Ljm3WTrKzYFBut8uMBDb529RBGkfk+A2v M/rf2Vw6BzysfA+PgBb0lHWSxh7zZIVcUHPgsevcH+FXhSayuBVPKaI2/sRJUjVwZ3sh mDVTvJagBELE8ENh8vCH8AgbeDky1F6PQf5oWry/i1XGz24pO3nc2eO7pWTPkntDwSlm P1bSiP4lHuYOVRc4yTGX5e4058PUKvlIZS8LbLvOAgCUcIs6oHfH+7dSCl4EgNqeLuj7 eYVQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=tb1F00/nSlox2NKAPVic2CylQOjgm2ke+JSF79slOJI=; b=t7n6z/vvSfxUNWy13TyNpqYRhp3FspsiUBD2fqcKAWHBw6D++WuQNARMZtUf8Wi26O F642/0U60Ykpcvx7QUOaaXhegXbvEfopg9oaINcv5z078B+gJ31nF9/k6IHNYuSjMQGi XV8cn3Q2+1+YYq8AQaxD4korEpDFv/xiw/8CZKNWL+Vix6huOOKf4L2R6pwxQG+WYEtm iUU/gn5UPJ288ff+WlwtYQ6R4iALf6BLKYBXC6+9anM29XL6SdBAbykcEZ3P6YlxsiHf dSRNe212JqJRewT99h5EuvCNy0v02nsTkk3Sm5KQ26W60s0AAM+xH5kmil9IeyrdtTRo /89w== X-Gm-Message-State: AOAM530ylUI9gONq309RZCtGXH5FO5sH7KVt45sgR+jQr8wm4R0nLF0S fKd3D2UoU/R9BJuxAk0EP5MS8Q== X-Received: by 2002:a17:90a:bd0b:: with SMTP id y11mr8078590pjr.25.1607249828160; Sun, 06 Dec 2020 02:17:08 -0800 (PST) Received: from localhost.localdomain ([103.136.221.70]) by smtp.gmail.com with ESMTPSA id g16sm10337657pfb.201.2020.12.06.02.17.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Dec 2020 02:17:07 -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, will@kernel.org, guro@fb.com, rppt@kernel.org, tglx@linutronix.de, esyr@redhat.com, peterx@redhat.com, krisman@collabora.com, surenb@google.com, avagin@openvz.org, elver@google.com, rdunlap@infradead.org, iamjoonsoo.kim@lge.com Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Muchun Song Subject: [RESEND PATCH v2 02/12] mm: memcontrol: convert NR_ANON_THPS account to pages Date: Sun, 6 Dec 2020 18:14:41 +0800 Message-Id: <20201206101451.14706-3-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201206101451.14706-1-songmuchun@bytedance.com> References: <20201206101451.14706-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert the NR_ANON_THPS account to pages. Signed-off-by: Muchun Song --- drivers/base/node.c | 3 +-- fs/proc/meminfo.c | 2 +- mm/huge_memory.c | 3 ++- mm/memcontrol.c | 20 ++++++-------------- mm/page_alloc.c | 2 +- mm/rmap.c | 7 ++++--- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 6ffa470e2984..7ebe4c2f64d1 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -461,8 +461,7 @@ static ssize_t node_read_meminfo(struct device *dev, nid, K(sunreclaimable) #ifdef CONFIG_TRANSPARENT_HUGEPAGE , - nid, K(node_page_state(pgdat, NR_ANON_THPS) * - HPAGE_PMD_NR), + nid, K(node_page_state(pgdat, NR_ANON_THPS)), nid, K(node_page_state(pgdat, NR_SHMEM_THPS) * HPAGE_PMD_NR), nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) * diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 887a5532e449..1f7e1945c313 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -129,7 +129,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) #ifdef CONFIG_TRANSPARENT_HUGEPAGE show_val_kb(m, "AnonHugePages: ", - global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR); + global_node_page_state(NR_ANON_THPS)); show_val_kb(m, "ShmemHugePages: ", global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR); show_val_kb(m, "ShmemPmdMapped: ", diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c94dfc0cc1a3..1a13e1dab3ec 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2178,7 +2178,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, lock_page_memcg(page); if (atomic_add_negative(-1, compound_mapcount_ptr(page))) { /* Last compound_mapcount is gone. */ - __dec_lruvec_page_state(page, NR_ANON_THPS); + __mod_lruvec_page_state(page, NR_ANON_THPS, + -HPAGE_PMD_NR); if (TestClearPageDoubleMap(page)) { /* No need in mapcount reference anymore */ for (i = 0; i < HPAGE_PMD_NR; i++) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 695dedf8687a..2700c1db5a1a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1513,7 +1513,7 @@ static struct memory_stat memory_stats[] = { * on some architectures, the macro of HPAGE_PMD_SIZE is not * constant(e.g. powerpc). */ - { "anon_thp", 0, NR_ANON_THPS }, + { "anon_thp", PAGE_SIZE, NR_ANON_THPS }, { "file_thp", 0, NR_FILE_THPS }, { "shmem_thp", 0, NR_SHMEM_THPS }, #endif @@ -1546,8 +1546,7 @@ static int __init memory_stats_init(void) for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (memory_stats[i].idx == NR_ANON_THPS || - memory_stats[i].idx == NR_FILE_THPS || + if (memory_stats[i].idx == NR_FILE_THPS || memory_stats[i].idx == NR_SHMEM_THPS) memory_stats[i].ratio = HPAGE_PMD_SIZE; #endif @@ -4069,10 +4068,6 @@ static int memcg_stat_show(struct seq_file *m, void *v) if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account()) continue; nr = memcg_page_state_local(memcg, memcg1_stats[i]); -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (memcg1_stats[i] == NR_ANON_THPS) - nr *= HPAGE_PMD_NR; -#endif seq_printf(m, "%s %lu\n", memcg1_stat_names[i], nr * PAGE_SIZE); } @@ -4103,10 +4098,6 @@ static int memcg_stat_show(struct seq_file *m, void *v) if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account()) continue; nr = memcg_page_state(memcg, memcg1_stats[i]); -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (memcg1_stats[i] == NR_ANON_THPS) - nr *= HPAGE_PMD_NR; -#endif seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], (u64)nr * PAGE_SIZE); } @@ -5634,10 +5625,11 @@ static int mem_cgroup_move_account(struct page *page, __mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages); __mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages); if (PageTransHuge(page)) { - __dec_lruvec_state(from_vec, NR_ANON_THPS); - __inc_lruvec_state(to_vec, NR_ANON_THPS); + __mod_lruvec_state(from_vec, NR_ANON_THPS, + -nr_pages); + __mod_lruvec_state(to_vec, NR_ANON_THPS, + nr_pages); } - } } else { __mod_lruvec_state(from_vec, NR_FILE_PAGES, -nr_pages); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 56e603eea1dd..f97ca98d361f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5570,7 +5570,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) K(node_page_state(pgdat, NR_SHMEM_THPS) * HPAGE_PMD_NR), K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR), - K(node_page_state(pgdat, NR_ANON_THPS) * HPAGE_PMD_NR), + K(node_page_state(pgdat, NR_ANON_THPS)), #endif K(node_page_state(pgdat, NR_WRITEBACK_TEMP)), node_page_state(pgdat, NR_KERNEL_STACK_KB), diff --git a/mm/rmap.c b/mm/rmap.c index 08c56aaf72eb..f59e92e26b61 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1144,7 +1144,8 @@ void do_page_add_anon_rmap(struct page *page, * disabled. */ if (compound) - __inc_lruvec_page_state(page, NR_ANON_THPS); + __mod_lruvec_page_state(page, NR_ANON_THPS, + HPAGE_PMD_NR); __mod_lruvec_page_state(page, NR_ANON_MAPPED, nr); } @@ -1186,7 +1187,7 @@ void page_add_new_anon_rmap(struct page *page, if (hpage_pincount_available(page)) atomic_set(compound_pincount_ptr(page), 0); - __inc_lruvec_page_state(page, NR_ANON_THPS); + __mod_lruvec_page_state(page, NR_ANON_THPS, HPAGE_PMD_NR); } else { /* Anon THP always mapped first with PMD */ VM_BUG_ON_PAGE(PageTransCompound(page), page); @@ -1292,7 +1293,7 @@ static void page_remove_anon_compound_rmap(struct page *page) if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) return; - __dec_lruvec_page_state(page, NR_ANON_THPS); + __mod_lruvec_page_state(page, NR_ANON_THPS, -HPAGE_PMD_NR); if (TestClearPageDoubleMap(page)) { /* -- 2.11.0