From patchwork Mon May 6 08:46:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13655150 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 89396C4345F for ; Mon, 6 May 2024 08:47:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36C876B0095; Mon, 6 May 2024 04:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 258266B0096; Mon, 6 May 2024 04:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0359A6B0098; Mon, 6 May 2024 04:47:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D46E46B0095 for ; Mon, 6 May 2024 04:47:00 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 82B3F1A085C for ; Mon, 6 May 2024 08:47:00 +0000 (UTC) X-FDA: 82087341000.15.4839BDD Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf15.hostedemail.com (Postfix) with ESMTP id 52C0BA0016 for ; Mon, 6 May 2024 08:46:57 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pusY9aSU; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 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=1714985218; 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=NqOIe5Oq6MCM0KXK59PH5ZOetWOLxng8pqZWeky8+zw=; b=1G+fks81V7B6/mTKI6XGdaf6IpOq26YEVWH2iY9OMNKnYv2tjB39jjf1n+h9mKAHu5Wpmo FRIOmvvuQzIBVoNDtI6bYQO7aqUAZkx4Ae+deO/iYa3qdX7FMEeg3yoMqxUPrC6nhFzURR LccvkIjmF4W7P5TOV9416SA/OGjrLlU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714985218; a=rsa-sha256; cv=none; b=7jIYj3YRwsn4lt9TjIvY+T7ji1hmMdMgVWXftzhfKC22nyGytV4c1RADuwdlHscRJ9M1NA 5XJx7u6JA0AcstEUmIgwtF5O7KCcUsc3ys4J5U9P8FWC6FAKQfrkC8wd/JCMCvVR3XblAH OHtjXXXt2DlJ+7qpc/0RwYNTULr1uWc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=pusY9aSU; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1714985215; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=NqOIe5Oq6MCM0KXK59PH5ZOetWOLxng8pqZWeky8+zw=; b=pusY9aSUFQ1Msf+lw85BS2IRAzWgqVbe6qKkjtmqkG/gSZKs9ogcYvRCoovzUIbXDz2YrWdBPOLZTFGxe7EEAbUFAOzbhWGWkGEleeD6N6rPQJMBCs/OBObhe7/WMJy1Iqw6jyDyFDoczP/VxGSzHqYE7wEmB07aPH3xPXA6qus= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;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_---0W5weiNH_1714985213; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5weiNH_1714985213) by smtp.aliyun-inc.com; Mon, 06 May 2024 16:46:54 +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 8/8] mm: shmem: add mTHP counters for anonymous shmem Date: Mon, 6 May 2024 16:46:32 +0800 Message-Id: <34f0b24f7c061f796d91ade9766e20a9da0c7651.1714978902.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 52C0BA0016 X-Stat-Signature: kr83848u55n7jc9tikonif5htxjypmem X-Rspam-User: X-HE-Tag: 1714985217-860587 X-HE-Meta: U2FsdGVkX19HkUXjRMu1Ung9EcCPxTeU8UACVDcxpDTpAuFaFztzLeqor2jk2Pakgml1+6CT0bhoRlte6E8nSWD4NULbDFSGnvYmC8IT6njuLmdlyEWB/1eC0ymRK5trljSAohe8gt5RkaMpCjlenlg54akevDfB76eD7eahHjJJLWbZT9JJ0Yt0P3d8lLoQRl5RT91SKADai+pHGI24VGykuDtHgRaKD3QZv75PcWy+rkvATgCP3Kg/W4J7Cmk6aRTKzMzBDMwCMWh1ZQN3AmTcV6j6/lb15y9g8caAS7kfW+kpO4ySvMyQPdvdBg0wCe4rd7dKj3sFj8Rx7UrdBCQOiz3tieUfcy1yDGSpjVw0XfMESGcSqiHZ7OdbUuv5wpxF9I3IC5pejq0I7ltSadFGGgpj+Shn0+/SNdswo3zd2jFUeyjiGnLSjR3McsYFuLKDyf89nN5dNsvj4zcfUQJ10PAASf5S/0ppf3yPsOrMOxp1hWgW3CwRUs7azi5CF+g5Ikol7k/SyNEQVGY8XoNAfz/0xFHHXc4HJt2J2ScD3C6NiTl30udYevVhOmyOlyDJN5281K2kooSCZfENErvxNkLORHMVuf8b9Y9IR2x+36nOKOHcNMziOjeCW+1ricPb+eCvN6k31fOJ03j8yl5HGMW9Sc7lZculjNuTkaqqh0/u+ZrE5tLsWWhXSW26mvaM4wvfob1lXlVpspdE043Dv8t40zTLDzaQB2mxuvT4Ug5aU4ln5pBWcACWmspQthOyMbeWepae5/SKAvyojH2yvYT/tcIi/XVY0D0PYCJ72/t5tj4B2Yb/tBJMHT0H+jrZ36RE1vbHonTNbu0GXWmlpCgiYrz6mZTIv5dj3kG9zr+QPFJ2/PdCJxY1hACn7CA4dcFJoHMjGenqu9OZHkSmOI5rLlEdo9Xnkgm4vEB6bUsPQN2vi70jIEv0tFMV/GlFfpA9vhZJMSE8Umi qlLkQlhG 11uh8eEJ6zA68JHTLpZ/uCBqzNixtn2qJsu8wW7FsyeaXnDo1shmhETR50UCmyTNZTuCRCSc3PG8a6dYGU9agruUXIH0tp4ikWinJEUd8grNBmLPqzXPUsI/upjOEu4v7dn8mJ4vpUe4jaK/fiSVF74ZKhkDELR39KU6TZn0p5jNXg951BMOVQP1+XoB5E3OUVkZXefAb5RKZpoxnsS0RPvEQIB4QJIqultvzGq6Rjd1V7ZFCHJ7UQHxZSw== 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 dbd6b3f56210..c15bebb2cf53 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 27107afdff9e..1af2f0aa384d 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)