From patchwork Tue Jun 4 10:17:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13685019 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 68162C25B78 for ; Tue, 4 Jun 2024 10:18:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE6D06B00B8; Tue, 4 Jun 2024 06:18:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2FFF6B00BB; Tue, 4 Jun 2024 06:18:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC0E36B00BA; Tue, 4 Jun 2024 06:18:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 857B46B00B6 for ; Tue, 4 Jun 2024 06:18:17 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1BFC7A135E for ; Tue, 4 Jun 2024 10:18:17 +0000 (UTC) X-FDA: 82192806234.23.27E928D Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf26.hostedemail.com (Postfix) with ESMTP id E57A714000D for ; Tue, 4 Jun 2024 10:18:14 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=KNk+Xooh; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf26.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 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=1717496295; 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=hr324HRcgNNfrgZ8GDchBNfhicaPktU9TGw54OvPLi4=; b=7Csnp2f/jLOGW+XFoB4bs4qwplAw8rYxiNo1OxvE/qnQ7h9PR646pogMWxllFsM5EXMzc+ CZveHoO/iPT4SqW4PeY9tuxINMpX4zWcP+mxGBGiaSGHN2covd26L2WqYZrQc1+QRIhPyi SuPuK23viah60Dm88QvUyBeOhG51kx8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=KNk+Xooh; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf26.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717496295; a=rsa-sha256; cv=none; b=Kvv3qb3HJ1lj8x9V5X+D/vQkdVjQRg7l9QyPLMC0oXXeIEuyq/Gowgmv0bmvs/xY8Xxk9X zygztgRj0LRCXW75RbNjVx+V8PnCkDHQbCO3v3TSZY4by9iRc8AAiMZJUkNmf2Eln85+dc jwTEMiZnwTyDXSh4vOsX5RP3L8qNdDM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717496291; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=hr324HRcgNNfrgZ8GDchBNfhicaPktU9TGw54OvPLi4=; b=KNk+XoohyGOW9PB5ooDCSJsizrW2ClIC6oNMPuZOh1VzC7k1QB3DLTGmADAdVt0cP2/s+NlJYUaAw05QJh5+KmAvjsqIDCM7KXaAiDpHMkbEm8QRY5ihajX5LTahGfIW+6FXJP89p3Y5PBrRjrE/9ylf48HM10iV1jrBmMJtAuk= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033068173054;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W7qsp1y_1717496290; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7qsp1y_1717496290) by smtp.aliyun-inc.com; Tue, 04 Jun 2024 18:18:10 +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 v4 6/6] mm: shmem: add mTHP counters for anonymous shmem Date: Tue, 4 Jun 2024 18:17:50 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E57A714000D X-Stat-Signature: rd7ksu1g9un1xzwc3oft9m44b1dfdnxf X-HE-Tag: 1717496294-802656 X-HE-Meta: U2FsdGVkX18Hya8k4X3XnNNVTPPCuDq9NbrmpIBHISYTX2jCr992Go58TbSK6NrjJHvQMmJzQD78vPuoW/G1pqRzkiY8+P2bnkx0ao24554oyvZzdMd0UDrVADpkro/igYC0PPNyzrytQrIvocQ+2TF47BbOAfYMQUh6i1H+3IulWzsvNEoxhKHzdVVc7g8jNq7Xpq9erQTw+mNsA/VFghH+DSzWTuF1gn/dDw+IqyOqbROOzk0DFHQafLbjDR8wi8SzgqnrSZo7YjClxKecbt9YP6YIOFj1ZCyvM41XNvUk9J9ckZlH3Pb80mWGf7960NB+vD9iAYadTrcAcvX6JmINAR04E7sdthZq4ms49AshPrrPgtvQRGcA+rKPQJUtO8ol0mNgwvra4ahTAK8hqRMTUFx2VBl2XCnOz/8Hng67KTcXCj3a6prmsxGbJPENC2hnS91i+CEpb7gxrv6D36uZYAkzuGjTV7clgDyyrdrzsXTrvAcB/KtMircSt5KiNaYl+aRxCjHjsj2IQJqzvn3qoOLPj/FwS1C0xA6Ek8fahOyvd48vOs9/pnxG8BDLxIa3fuajEz3sE8blJp+WPSezYcqdM6RzA4cuqWyavcMKjLRG3rwwTKvg52rIGVzZKRY7kQLjo6QNfOBdw4JUAl+7moHLMjJKziNLfjDl+Jao476cpIRhVyKO8DQwA1gKOV7nMmUYX2dmtgfji9m91w+BTUVK/e2OEQbHOnakOdwfQF1vQOoqFwYarExMpQENE4VFo13LuGIApX2S/iSBDK3RnT7iWZQ9qWXbR6Tp1rPBSA4VKNR+yAl7lXTwWPeW0YxnjE5RLd3erJg1PhF/ZWhDxpQZ0wzxhGpcSTRqT06LYngjjAnEBUwsoqAINdqw1Qp3ik54PIAo/sfqhAaRJBPUCOr2gKz1t7M+EhYtEsZF49oSUYycD+wZOxqWtm7ckh+irOqA7R4nQJKZYR/ X2CT23n0 1Bj+ACW9xJfZiEuqnbVzQpniRCFBBcOgavDDkiNmrCNKFCmi0xE7qeYbc3Eg1ooxqRdfzjPLOhXQax0cRYwh353203V6pTN9u5IA9l9S3Flg706Y2y3XHWWV2IBJIu59jUAwkhC16Hl+E0Xm8j0I+IbPtVB1k9F8fpesDmnlZG7aL5v/MPHdMZ5vY2lAzY6vZvaMiIDcAYU2IjY9KusEBNen9NDkmc08jc2qNc6A0v6DbOee5tMhl/1F64g== 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 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 2ecc41521dbb..d9a11950c586 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)