From patchwork Wed Jul 10 09:55:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13729136 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 47A4FC3DA45 for ; Wed, 10 Jul 2024 09:55:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3E4C6B0092; Wed, 10 Jul 2024 05:55:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC70D6B0095; Wed, 10 Jul 2024 05:55:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B67B06B0096; Wed, 10 Jul 2024 05:55:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 93FF06B0092 for ; Wed, 10 Jul 2024 05:55:18 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 22A92161C06 for ; Wed, 10 Jul 2024 09:55:18 +0000 (UTC) X-FDA: 82323385116.18.06C76A8 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 32400180016 for ; Wed, 10 Jul 2024 09:55:16 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720605292; 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:references; bh=BTNEcR8WPC5dE44KPnTc1c8T4sidO+N0Kxm7hoR+kiA=; b=2VA0QA6TRuhUF6ljHcql0nIuxSZJqZfTfQQY2bfSlnBvX1Xac721KvA30Yqa0qCYNCjjRx 1KyBf0H+Nz0lRf9m+gCokieUjpYfkjaRoLPG8EsE/sVUThb11ugcY9BdQCmfq0ueEsQ016 Yk/+w+mKIcZUNJbzDCP71JVacJmOnlc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720605292; a=rsa-sha256; cv=none; b=ZsXDJGDuAVIODSDPg9picMZEM+8tv5NGOHqDiMxBO75J8/c0x/IrgI7yivk9GtX0t8or/l YdFlle0i9juIYYw2k3/lSkITM/vw/vYHD/gmNp8iAvqStBXe2mYJjNNcGMpFmlT4SZNfBJ v1lcK2Nn992PvEfobSUs1FLIxokRtrw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4B185106F; Wed, 10 Jul 2024 02:55:40 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B3D03F762; Wed, 10 Jul 2024 02:55:12 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Hugh Dickins , Jonathan Corbet , Barry Song , David Hildenbrand , Baolin Wang , Lance Yang , Matthew Wilcox , Zi Yan , Daniel Gomez Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mm: shmem: Rename mTHP shmem counters Date: Wed, 10 Jul 2024 10:55:01 +0100 Message-ID: <20240710095503.3193901-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Stat-Signature: n9tswfp3jbnbetagqi1xpbrpbp331dhb X-Rspam-User: X-Rspamd-Queue-Id: 32400180016 X-Rspamd-Server: rspam02 X-HE-Tag: 1720605316-368469 X-HE-Meta: U2FsdGVkX18vQTY/+aSAq0I/KQPR0T4ATj8QMtZXMt3Er1bbCUHxGYzgoERV3Lvxe3dEov4VNFU38eQfohz4GZiAKv7vLDv2ej3ekOJURfp+vWGtwd9RFNxvmUXT/KjL8Yn3ipVlhUG2h66kOmRCMtAXTxZZSqWIZDQa1u8F2F3AkF6jRZyU2E18XPQYt3aygIJokqgBq3C0MKhFwqttEKbV93u8ezWDBvDY8m2A6sxIbNQH8au16iBmOR2ceNJfgvEX4VU/Ex64mNJrUhQn/KeWfDOBoXbvDL0B5T7/k1x08PMLn6RWoU6cjBPiPe6iRIPLc/ttBsN9Yi/WhUpGaLYRQjQS3vBvzyG2m24zoAqfNLkQYbbc7uMtwwcjjbpe8/Zzqp5TizLwStDFOzbqgssa5wITSDnStjWC089dHC4mBIrOzBFk3d7C1gXto2N5L1wDG5sqwHAK/eAbaY6S3iY2NQW3iOK4ffnBg0HcjIcsgd/WNi9/AITRmECHY4wO27UKLWk9W9EilB8lgkp89HMxcu+KzB8lwbxBG0AfXbbm1UhnlTrjB7rEsK9WGDb/iHHrLojd58Lf3jC08ZFj0dlo6saxKuuyQIskQULaql9/t8FGwiLuQbQHnq0pKcFAk/WcM0/XYHYYi4ljgo0FiH1C1TFQIpARIfpJf1m6qjSmIsacvKZW/vtmLwuojaW/jVDnWeb2/zUSzrAsElkkI0F07d3NJX5E8VC0XjJxvxyGIdwD2sJe88L6t/RiCgsXJej+vFpxYjMmrQIyGi4oyxbIG2LYpTi958y97idhFC3ZZF4zbeGk7L5uCvn5NTA3PMFLCpSuiI6Y7cJo1XxQU0PFrDWQenlRGuU8sRvnyPnwFZulHGkUPSQtseUyKAPOtDNc0lZWbkA+S2Cw/QNWWX6+RMepkHoam90LWv4UkgSocXXqjmBD2DkvFENXfIR8JPaY4MqJgBpfjvWf//Y 9StNkcsx KFopNLeyAP8GAhJBCKvl/1imjc9/fkqbFvt3JQeOf+N5+04xQGeqxTyG7zIY5iA77KoGcR/2/Flro+ttFAXxRHk50DIHMSE8KcCjc4aBE4aK7UAykmUakzm/Pa2OHN3BDTu5tNcEFMrDJwpby6yvr06NrhbBN51llYvKUqU/OJBvSDr46glDYQ4oriwo0VqPtlAKzkzy9tA7wJNTbN29jDyaEl0Y04ATmKp7czVzwfF9m7ss3P1PyJzxLsuZi+dCMGl8gmo6Sx/zjw9E= 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: The legacy PMD-sized THP counters at /proc/vmstat include thp_file_alloc, thp_file_fallback and thp_file_fallback_charge, which rather confusingly refer to shmem THP and do not include any other types of file pages. This is inconsistent since in most other places in the kernel, THP counters are explicitly separated for anon, shmem and file flavours. However, we are stuck with it since it constitutes a user ABI. Recently, commit 66f44583f9b6 ("mm: shmem: add mTHP counters for anonymous shmem") added equivalent mTHP stats for shmem, keeping the same "file_" prefix in the names. But in future, we may want to add extra stats to cover actual file pages, at which point, it would all become very confusing. So let's take the opportunity to rename these new counters "shmem_" before the change makes it upstream and the ABI becomes immutable. While we are at it, let's improve the documentation for the legacy counters to make it clear that they count shmem pages only. Signed-off-by: Ryan Roberts Reviewed-by: Baolin Wang Reviewed-by: Lance Yang Reviewed-by: Barry Song Acked-by: David Hildenbrand --- Hi All, Applies on top of yesterday's mm-unstable (2073cda629a4) and tested with mm selftests; no regressions observed. The backstory here is that I'd like to introduce some counters for regular file folio allocations to observe how often large folio allocation succeeds, but these shmem counters are named "file" which is going to make things confusing. So hoping to solve that before commit 66f44583f9b6 ("mm: shmem: add mTHP counters for anonymous shmem") goes upstream (it is currently in mm-stable). Changes since v1 [1] ==================== - Updated documentation for existing legacy "file_" counters to make it clear they only count shmem pages. [1] https://lore.kernel.org/linux-mm/20240708112445.2690631-1-ryan.roberts@arm.com/ Thanks, Ryan Documentation/admin-guide/mm/transhuge.rst | 29 ++++++++++++---------- include/linux/huge_mm.h | 6 ++--- mm/huge_memory.c | 12 ++++----- mm/shmem.c | 8 +++--- 4 files changed, 29 insertions(+), 26 deletions(-) -- 2.43.0 diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 747c811ee8f1..3528daa1f239 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -412,20 +412,23 @@ thp_collapse_alloc_failed the allocation. thp_file_alloc - is incremented every time a file huge page is successfully - allocated. + is incremented every time a shmem huge page is successfully + allocated (Note that despite being named after "file", the counter + measures only shmem). thp_file_fallback - is incremented if a file huge page is attempted to be allocated - but fails and instead falls back to using small pages. + is incremented if a shmem huge page is attempted to be allocated + but fails and instead falls back to using small pages. (Note that + despite being named after "file", the counter measures only shmem). thp_file_fallback_charge - is incremented if a file huge page cannot be charged and instead + is incremented if a shmem huge page cannot be charged and instead falls back to using small pages even though the allocation was - successful. + successful. (Note that despite being named after "file", the + counter measures only shmem). thp_file_mapped - is incremented every time a file huge page is mapped into + is incremented every time a file or shmem huge page is mapped into user address space. thp_split_page @@ -496,16 +499,16 @@ swpout_fallback Usually because failed to allocate some continuous swap space for the huge page. -file_alloc - is incremented every time a file huge page is successfully +shmem_alloc + is incremented every time a shmem huge page is successfully allocated. -file_fallback - is incremented if a file huge page is attempted to be allocated +shmem_fallback + is incremented if a shmem huge page is attempted to be allocated but fails and instead falls back to using small pages. -file_fallback_charge - is incremented if a file huge page cannot be charged and instead +shmem_fallback_charge + is incremented if a shmem huge page cannot be charged and instead falls back to using small pages even though the allocation was successful. diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index acb6ac24a07e..cff002be83eb 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -269,9 +269,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_SHMEM_ALLOC, + MTHP_STAT_SHMEM_FALLBACK, + MTHP_STAT_SHMEM_FALLBACK_CHARGE, MTHP_STAT_SPLIT, MTHP_STAT_SPLIT_FAILED, MTHP_STAT_SPLIT_DEFERRED, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9ec64aa2be94..f9696c94e211 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -568,9 +568,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); +DEFINE_MTHP_STAT_ATTR(shmem_alloc, MTHP_STAT_SHMEM_ALLOC); +DEFINE_MTHP_STAT_ATTR(shmem_fallback, MTHP_STAT_SHMEM_FALLBACK); +DEFINE_MTHP_STAT_ATTR(shmem_fallback_charge, MTHP_STAT_SHMEM_FALLBACK_CHARGE); DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT); DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED); DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED); @@ -581,9 +581,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, + &shmem_alloc_attr.attr, + &shmem_fallback_attr.attr, + &shmem_fallback_charge_attr.attr, &split_attr.attr, &split_failed_attr.attr, &split_deferred_attr.attr, diff --git a/mm/shmem.c b/mm/shmem.c index 921d59c3d669..f24dfbd387ba 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1777,7 +1777,7 @@ 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); + count_mthp_stat(order, MTHP_STAT_SHMEM_FALLBACK); #endif order = next_order(&suitable_orders, order); } @@ -1804,8 +1804,8 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, 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); + count_mthp_stat(folio_order(folio), MTHP_STAT_SHMEM_FALLBACK); + count_mthp_stat(folio_order(folio), MTHP_STAT_SHMEM_FALLBACK_CHARGE); #endif } goto unlock; @@ -2181,7 +2181,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, 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); + count_mthp_stat(folio_order(folio), MTHP_STAT_SHMEM_ALLOC); #endif goto alloced; }