From patchwork Tue Jun 11 10:11:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13693377 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 E60EAC27C5E for ; Tue, 11 Jun 2024 10:11:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DD826B00A5; Tue, 11 Jun 2024 06:11:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 466AC6B00A7; Tue, 11 Jun 2024 06:11:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DF2F6B00A8; Tue, 11 Jun 2024 06:11:28 -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 0ACFB6B00A5 for ; Tue, 11 Jun 2024 06:11:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C396A1C1E48 for ; Tue, 11 Jun 2024 10:11:27 +0000 (UTC) X-FDA: 82218190614.09.BDDBC62 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by imf08.hostedemail.com (Postfix) with ESMTP id B778F160016 for ; Tue, 11 Jun 2024 10:11:25 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=jI6eHc3s; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718100686; 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=nLj8yUsK2lei34HSlxIopppsBC+abcyB+V/ZUwcOo4A=; b=qi97HcDGsFiFMdsyWoBKtEaW2CNzAEvTa4BlJb6qEF41k9++VSswkH2Ov4EckbfUoparRE 771RYFDF84cL3mg1X/FmDyD+/Sa6HiE7mvbEhuq51Dq4rWqgm04Im0AYbMnk/WdNGQob/P N/gUKlWBoTwj48GjCnqFhQykiQTkGlY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=jI6eHc3s; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718100686; a=rsa-sha256; cv=none; b=UY6njvFHZ4T/N0CCnb9vtCJyRiEKwYTzy4vIBT6ACmjIPDbXB7ceQ8VXU7cDxPB9/P9AE8 sir+meA2HtRCQWV/tgErmqitaTKRm4iqpjYBwDFsP2VMnBYFsgvvNiYNNZb/y0E7xbyyWi 3upydUJkm0ptF/aXQHufdBE7RYUNvpw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718100682; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=nLj8yUsK2lei34HSlxIopppsBC+abcyB+V/ZUwcOo4A=; b=jI6eHc3s7Dh200K72Vp2xKk9UjuQgAiiwwnHGqgadNMokNpBfiy12gYTzTcNhkpDibiqeIscxgAx42TLdN1NYekzkrqbB17CFARjGG9mql7wWyxLYxLq3tsWOu11gSe30DXWkBx9F/CaZr2VfoSv6AyvT594tEiswDJnVQT6ChM= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W8G7ENT_1718100681; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W8G7ENT_1718100681) by smtp.aliyun-inc.com; Tue, 11 Jun 2024 18:11:22 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 6/6] mm: shmem: add mTHP counters for anonymous shmem Date: Tue, 11 Jun 2024 18:11:10 +0800 Message-Id: <4fd9e467d49ae4a747e428bcd821c7d13125ae67.1718090413.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B778F160016 X-Rspamd-Server: rspam01 X-Stat-Signature: ybcsypd7gznhrnu8de49xkpdf1mtym59 X-HE-Tag: 1718100685-127468 X-HE-Meta: U2FsdGVkX1+EalnkX4KU0UPkXgCHksG1+7nYmRNN0eJjDBeJDKLGkWhOgHN4gd9+itX9mdBNCl6Vb1ArsVlVTsr3xyJcSDrQEneLisVtdJz4WSQV4P35yx3rTSUgib9lO2vKy4A4XfxAIdtCNdIZvlxVSyf80MkQ6PvH8R7W/YbvabEBdeN0P/q2X13IU1pYt7L5AAmmwyq8M0vC231MfNtUFsDDe3qNriivcPaPl3nDo/fJK847Akt7FQc+D4YotWneROnQrGh3nn+F9te7bZPHX4QjZNebMU3JkgSv5fZ8RGuGaPYmHj63nf895poJsmnLCWCyBgw3RQh/JAS0zJkjhpkH1PQsKknPNlb31s/bUExfWcDMFd/6YgbAAymFeJtKajdopqIKy9tiaPtaL3FdGFLdCsSrd+Pcl+65Qri05v8XdH9Fde7DFF7baeMqSG5U/+i8AjJCJ4Un0JCJT6CdDGcZ7gUaBjztqlkP8V+ENRbSkShXSvDKm+T2Dlee+cMG6KWsij9XS4EoFrXgWaUM2EHhlREH4c7L3vjO8IchqfO1JHqyxffp0waCc5VCPk/0CVROSKfavGB4xwBPhmoBiC0g+p4kuJxt4lNwtsED/BD0g/DuZeVvuMBlNuibLrg0ll4G0hGjFeAVMa3m0Yx0JFRBpQugfbOwfWpVl1Tyj6NJlxW5xQoot1LpaL/faXgPoxuxllNUTjvdezaZriwK0HC8Oxzr61w+9K2Zart2sAsWJd6dwKngjTWWAUcevqTi+FpZTLx/jjgpMsa2wzkeTk3TDQwMBVIDFn5fROJhFYaNbub7+mfbDVrf9T2VNfdKc+lGVJ+LlYBw0Ea72D1px2dIDRgyKV6+bwiuF3OVyyhLnOLTFlDof9WTuF5KJLmPHONGUDywi63MAvROm3Loykciwq1FLMiyWXd7J3/KhswWU5THwlEzfp5UZxvybyyAcM9tuKAate1CYh5 dkaTKbFB w9xC5FY0WUAfAECRSdvk00aCa1jN5lz1BmtrGKDIWxUqPN9jrOuyHSkIz6PIZjeAOSUA+aaJh7xGiXI+oCGN7I2Bmv9V89IWBOvEkp6ytzmrq/vyL927gbLQ7KGZFVNMjaugFS33UBO6NaOM39/n+pB2QQbcPmi56CA3QPuGMblfRxsIgpVGNgu8nMHbNBubMi+633LIpxc8G8Gy8xwYGCy9l9rVC6OBITq5IjL9xF15lbP4= 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 Reviewed-by: Lance Yang --- 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 909cfc67521d..212cca384d7e 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_SWPOUT, MTHP_STAT_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 1360a1903b66..3fbcd77f5957 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(swpout, MTHP_STAT_SWPOUT); DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_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, &swpout_attr.attr, &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 f5469c357be6..99bd3c34f0fb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1773,6 +1773,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 { @@ -1792,9 +1795,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; } @@ -2168,6 +2177,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)