From patchwork Thu May 30 02:04: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: 13679636 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 2F461C25B75 for ; Thu, 30 May 2024 02:04:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 542486B00A1; Wed, 29 May 2024 22:04:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2F26B00A3; Wed, 29 May 2024 22:04:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D0826B00A5; Wed, 29 May 2024 22:04:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0BBDF6B00A1 for ; Wed, 29 May 2024 22:04:47 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AF83E40B82 for ; Thu, 30 May 2024 02:04:46 +0000 (UTC) X-FDA: 82173418572.16.BC77374 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf22.hostedemail.com (Postfix) with ESMTP id A3AE5C0002 for ; Thu, 30 May 2024 02:04:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=chj+aDAX; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 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=1717034685; 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=ptAk81AGNsYnCqrfWiyusE+CUxd4N7JUTOqMyRP+zl4=; b=1CgsyHe5G/BpVvcWB4YwYQ9u+oBd8iRaKHutLzkbcA2hidzRMpiu2phPwG4usyNuatCB/Y hsB5kTcpEm5a+tDRl97vRTJCTY+4EeC6ZsuoDksnIAxQiZKzShrB9b6qvN4RmBN+4nUiOa 9tEWRIhmFFfgR3OhKxFc9UepIGKeTDU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=chj+aDAX; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf22.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717034685; a=rsa-sha256; cv=none; b=eYJH+bQe+Hhu83/5A+N5A9M1JjuM3DPk0RUZ+CvCbjsvf1XfNGHsCHj6iftYYR2WJTRKal ICKj0FTTO3jZ4mm/gYeti0Z8J5gbSHrvhJSc682Nrxrxw2wIZT+sPCJ+ETFYonkjKBDDR0 rwtgxVAqbdaQ4hUEGRFdrDzvOJ0sf2A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717034681; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ptAk81AGNsYnCqrfWiyusE+CUxd4N7JUTOqMyRP+zl4=; b=chj+aDAXZTS7mDUOgsmGZO28i95jAOvEBzKpdeUXB5WSSlTNT8RUkAAI1n3wtCD97oh5EL22a56UVXzDOKfQY9GemhAffXcwvOmgHU5vH6wfi3A35m37xME5b/pP0Pw/LKdvzMBNF91XMq2AWsIhQW9lvbE6gMbTZYo8RS9nsBI= 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-contentspam033037067110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W7V3uQV_1717034680; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7V3uQV_1717034680) by smtp.aliyun-inc.com; Thu, 30 May 2024 10:04:40 +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 v3 6/6] mm: shmem: add mTHP counters for anonymous shmem Date: Thu, 30 May 2024 10:04:17 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: A3AE5C0002 X-Stat-Signature: yer84kprssetaicxj36ejmjqtua4i6ri X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1717034684-62039 X-HE-Meta: U2FsdGVkX1+rRN0TqVut5WG2b1yRPsXXVH4OQDGHSBXwK/PFb3/tNgD6dctw0bRTiFuHAhXf/tsEMvnQacenbatjuDBakE7p3KWkzauoxxgJLL4bb8yP3PXbxV9+5GjS5xcw7YfDxkIcgqxkCwZpSqN7/fXF5DNxVVWxTNRkO+Qz7AW0SnajxSQufWXWz7W+rWtpIwnctaOfdVimfUfASffVjX8GVASH2PtKWqljlZUAp+iYvp/ogHFxhMryIz1oANPI1uFNwA693vc28DMitKD9iF8LONFJdnKoSnloKLMmd45Gjp5drK7UR8k+dQlNX3SYC8LDYl9sVyzN4pzVHoJNVEdbhbLGOHEI2eM+vtq2DT3V9tDQZ7mg6ZqAvhISIhXer+Afdx5cBaW7g9S8T4vIC+nU++IbCV1z4151dCdAwipH02Wj7btQs2aixyC/Ycu4QhsnE8kbCRYwPny09J4cgMoxrvt60ktEoTNxtBfEPADRauJLW9onURJ0gOr8ZvnrBcCRYhxnz44wBvjVIp11On3PE0hdULtKPlNcCMJz31CaVuwtPEJj9aTlCUELKY4GHzhOksBB3W7ONxRH/G02aJRZGJPL+a1kO7q4GzcoLUfR9rPgmRybmBs4ZDTZ37PxjowVza5bqJSY/pM+gunj0kBdil1bvnU85xtXhNxydE1XJrx1LwiI91Vu7Vjl0sSlELoKklwi9yS0HWovNoiNYechRfdpO4zKodSRPg/L6C71mTiYGYIu1bfW5Kbynu74wnUzP9lNPIFdN1fQENxySe/CAe898vHtsEkVSRrd7kcYGAax68U89A8eAzrUGTvoVeymDDLxHjS5NGN1kAZQHNxDRbYEOEM6wVBv98cxTVyBqBfueF0GSY/2x/1Jtwv51chDFFJCouNDj88Nhv0aYdEoaTcY0maou3Sft1ESeT7jRAmDvnIihszNxUhMAluewonX7UkVw5oJ9Mf D4elntRD 2zNu7J75oTM/rYnjnPGP2CXNVfFARXREegX+xdJ3yuF+QT0M27JurRukNZ+LpFQHuDfC/6uvY0U4dsUXWuLW7tN8MjP/u3WMEYSIQ69QmLsZ88D+zcj4tx5W4Kjp8oI9eDIls7WrtBLTW/eI6DqNpAQ39I4nEQG3semgK9gwUWjnJ+AqSK3anFXPOf6QVuhbZM8lhWM7h1h/K2N21xPaf7ihCNVXj5Ftn9QkJyP8ZakWZgEE= 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 efc093ee7d4d..cdcc3b919bca 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)