From patchwork Mon May 13 05:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13663025 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 E8702C25B10 for ; Mon, 13 May 2024 05:09:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E6AA6B0203; Mon, 13 May 2024 01:08:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76DF06B0266; Mon, 13 May 2024 01:08:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1A66B0261; Mon, 13 May 2024 01:08:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 365E36B0203 for ; Mon, 13 May 2024 01:08:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D3AFD160B8A for ; Mon, 13 May 2024 05:08:49 +0000 (UTC) X-FDA: 82112192778.22.8894643 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf23.hostedemail.com (Postfix) with ESMTP id CEBBF140002 for ; Mon, 13 May 2024 05:08:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=eb5os6TL; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715576928; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+jNNX3W26VDDLfggMRp8CMmTsrteBwo6mbmSEbiS2X4=; b=aHBdwfYylJYceQsn4AAsc2S7PKoiTtRk7b0zTcncR+cEi6u9/LTZHaf3QmkcVZbP9Qa7yY vnYh2cKYE1RWrL+wron8h3+QDBFNxnBC2FXgAjzAqhpCcnQxuGyNXFdHWP1QAYt8J2aQgw 1gTcpPF+Y9EPr8OMBad8Jj+yHCfq2XY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=eb5os6TL; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715576928; a=rsa-sha256; cv=none; b=FiQqpvylEQqOxQt6xeXASH+J2Z/g8kWMTHZWw7fKOR49C0W1INrZOEzK116v3oz5f+0qn2 rnAK9/RzBsNphtM4UGFiD6RqqyZZCH0yZ6qWbilvhr/Mko9kf0xuKpArDT1MdaTv6t8X5E e6In4Hx3z8+7CQlN1uUQTK1VXHwJ9BY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715576925; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=+jNNX3W26VDDLfggMRp8CMmTsrteBwo6mbmSEbiS2X4=; b=eb5os6TLS/bs7VneEJFdYNwmz8r/qv+Up4IuJIvok1kitqTq6t2GF6XuEnw/arVkJU/nONW0TvViR6PoBVBvIL9hGkRjePmPLgBeJ7wlryslyM/V1U/PjemJKWTDIIhpylrq2n8S5xcwI6Dv38fnQgSslirFlEAQgGdO8+iR3G0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R331e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033022160150;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W6HN0Qb_1715576922; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6HN0Qb_1715576922) by smtp.aliyun-inc.com; Mon, 13 May 2024 13:08:43 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] mm: shmem: add mTHP counters for anonymous shmem Date: Mon, 13 May 2024 13:08:17 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: CEBBF140002 X-Stat-Signature: zarratyzh1zgh3cegagthdxur91c6ttu X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1715576927-676197 X-HE-Meta: U2FsdGVkX1+fSf1wb7z1LGKYvFKKgrhho+ccZ8u2TWP7Og+RUqItEqQ4c/1KrJSae4JYc9uQc3v+q/Ue3ogvHFxRVKdbf8bSTn3vKDN9Cwh30zDdQaN5snCfgA6scdilIxJOGZfIWXiwQGCZ3N7sT0WFwfDdYPLsO3VSUvvLwTTNN2ieOFL7S46TFvqcj/QSfrN8ZZopnuIyTu4YDKBUaiApPVJ7VzWjLBlYQXHtW7Tmf8OO39aO3W0IK7LkeVNcjiFAcNdakRNukmw9XBhJqybG54Et/gQ+E/YwLuKH1iIadBjVA2GMCdFVElolb7v+9Yirrf8FOOCYJF3dFnTKiFo2P8Rf2JswaREleNCwDeRUzxTmWcVB8NyoGbiTBzOggNxoiloCwAvQeViBnS0xMuBpFIScif8Xl1RoLLgEN9/+JPa115l+EbilmgoNQyFxgENodmv6JqS8ZKD6mwE6SS38SepEkkZSmH6bBuZDlyM7rwCODz9NrvjlSpUVND786DOjlL3cNSGrpjS3Lk36yE3W2gTwYCM6kBwnCdTquGp7USTL/Tvoj5/px2XOLrkML9eCKR5PVgkF6n+sL8jLVcRKBFQcoOieWq23DJOK/RKVh3jfh3uibliprzUFtpwv591rjbYpY8MtDB1Qk4BE5IhJxPrE5qH/oTNPL/J9KGvYGBN7roWTwwqz13QtNy5QjzRP6PZkhOXGiP4EoM4ArDmNsp9IJcSdTPdyrwmOJHmg/DxiY/HOpGbfHPYrvS/gBef1mKDCLRR9jaSbPDeewAuTSCpoLXchikaXL71n2/mXS9b2/OUFtqUhheunT0yd/NI+s/Vp6noC/Bvan8mjUd6PVydWPhi7fqHwbUXde4rTGWglZ9H3Mp/Gi4yZu4THhiPnItEwAI+EVnGsiI/Zcu8c2HLtCjR+U7xVObikgvR5oX++6FK5u9HoD6x+IYE8nnuLS/sU83O8jdF+9Et hjFj6YUQ HP2MFfBvk1jsERB5grZjYsPeUOsXh4BB86SJ9mJXpeOU2XJV92LLMCbn53bBOWdJnmvTLQhysnfEz6xsl/vJ7qdmvs0+B7ePb91XTB1DtvapQIVTHv1a8gFdZZ5riAxmRsh0sTf4+0HYWki8a9fXwbh+b9uDYE4MAyxvScjuUia4IqVg6rrsGGAulqpNLr0suITDD8BCMdcz2ETF0sbcP33lIZjoK8l4sfrxtLaWnnwoozwY= 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: List-Subscribe: List-Unsubscribe: Add mTHP counters for anonymous shmem. Signed-off-by: Baolin Wang --- include/linux/huge_mm.h | 3 +++ mm/huge_memory.c | 6 ++++++ mm/shmem.c | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b5339210268d..e162498fef82 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -281,6 +281,9 @@ enum mthp_stat_item { MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, MTHP_STAT_ANON_SWPOUT, MTHP_STAT_ANON_SWPOUT_FALLBACK, + MTHP_STAT_FILE_ALLOC, + MTHP_STAT_FILE_FALLBACK, + MTHP_STAT_FILE_FALLBACK_CHARGE, __MTHP_STAT_COUNT }; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d3080a8843f2..fcda6ae604f6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -555,6 +555,9 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); DEFINE_MTHP_STAT_ATTR(anon_swpout, MTHP_STAT_ANON_SWPOUT); DEFINE_MTHP_STAT_ATTR(anon_swpout_fallback, MTHP_STAT_ANON_SWPOUT_FALLBACK); +DEFINE_MTHP_STAT_ATTR(file_alloc, MTHP_STAT_FILE_ALLOC); +DEFINE_MTHP_STAT_ATTR(file_fallback, MTHP_STAT_FILE_FALLBACK); +DEFINE_MTHP_STAT_ATTR(file_fallback_charge, MTHP_STAT_FILE_FALLBACK_CHARGE); static struct attribute *stats_attrs[] = { &anon_fault_alloc_attr.attr, @@ -562,6 +565,9 @@ static struct attribute *stats_attrs[] = { &anon_fault_fallback_charge_attr.attr, &anon_swpout_attr.attr, &anon_swpout_fallback_attr.attr, + &file_alloc_attr.attr, + &file_fallback_attr.attr, + &file_fallback_charge_attr.attr, NULL, }; diff --git a/mm/shmem.c b/mm/shmem.c index 8b020ff09c72..fd2cb2e73a21 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1786,6 +1786,9 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, if (pages == HPAGE_PMD_NR) count_vm_event(THP_FILE_FALLBACK); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(order, MTHP_STAT_FILE_FALLBACK); +#endif order = next_order(&suitable_orders, order); } } else { @@ -1805,9 +1808,15 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, if (xa_find(&mapping->i_pages, &index, index + pages - 1, XA_PRESENT)) { error = -EEXIST; - } else if (pages == HPAGE_PMD_NR) { - count_vm_event(THP_FILE_FALLBACK); - count_vm_event(THP_FILE_FALLBACK_CHARGE); + } else if (pages > 1) { + if (pages == HPAGE_PMD_NR) { + count_vm_event(THP_FILE_FALLBACK); + count_vm_event(THP_FILE_FALLBACK_CHARGE); + } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK); + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK_CHARGE); +#endif } goto unlock; } @@ -2178,6 +2187,9 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, if (!IS_ERR(folio)) { if (folio_test_pmd_mappable(folio)) count_vm_event(THP_FILE_ALLOC); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_ALLOC); +#endif goto alloced; } if (PTR_ERR(folio) == -EEXIST)