From: Zi Yan <ziy@nvidia.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
"David Hildenbrand (Arm)" <david@kernel.org>,
Matthew Wilcox <willy@infradead.org>
Cc: Nico Pache <npache@redhat.com>, Song Liu <songliubraving@fb.com>,
Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 7.2 v2 05/12] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check in hugepage_pmd_enabled()
Date: Wed, 15 Apr 2026 14:01:27 -0400 [thread overview]
Message-ID: <68F85F77-8EFE-449D-B643-AEEB38CB50B2@nvidia.com> (raw)
In-Reply-To: <38697379-cbba-4c64-ae65-6774b01021d9@linux.alibaba.com>
On 15 Apr 2026, at 5:21, Baolin Wang wrote:
> On 4/15/26 4:00 PM, David Hildenbrand (Arm) wrote:
>> On 4/15/26 08:36, Baolin Wang wrote:
>>>
>>>
>>> On 4/15/26 2:25 AM, Zi Yan wrote:
>>>> On 14 Apr 2026, at 14:14, David Hildenbrand (Arm) wrote:
>>>>
>>>>>
>>>>> Yeah, it would be better if we could avoid it. But the dependency on the
>>>>> global toggle as it is today is a bit weird.
>>>>>
>>>>>
>>>>> I don't think there is other interaction with FS and the global toggle
>>>>> besides this and the one you are adjusting, right?
>>>>>
>>>
>>> I'm afraid not. Please also consider the per-size mTHP interfaces. It's
>>> possible that hugepage_global_enabled() returns false, but
>>> hugepages-2048kB/enabled is set to "always", which would still allow
>>> khugepaged to collapse folios.
>
> My comments are in reply to Zi’s comment:
>
> "I think hugepage_global_enabled() should be enough to decide whether khugepaged should run or not. "
>
> I’m concerned that only relying on hugepage_global_enabled() to decide whether khugepaged should run would cause a regression for anonymous and shmem memory collapse, as it ignores per-size mTHP configuration.
>
>> The question is really which semantics we want.
>>
>> Right now, there is no way to disable khugepaged for anon pages, to just
>> get them during page faults.
>
> Right.
>
>> And we are now talking about the same problem for FS: to only get them
>> during page faults (like we did so far without CONFIG_READ_ONLY_THP_FOR_FS).
>
> OK. I’m fine with using hugepage_global_enabled() to determine whether khugepaged scans file folios.
>
> My concern is that for anonymous memory and shmem, the per-size mTHP settings should be considered.
OK, I misunderstood the meaning of hugepage_global_enabled(), since per-size
mTHP settings could also enable khugepaged if PMD_SIZE is set.
I will take willy’s original suggestion and make khugepaged on if the global
setting is enabled. The below is the new version of this patch. I moved anon
pmd huge page code to a separate anon_hpage_pmd_enabled() like
shmem_hpage_pmd_enabled() and cleaned up the comment. Let me know your thoughts.
Thanks.
From 92b92f2b2ab41c70b41dd304ce648786ee6a1603 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Wed, 15 Apr 2026 13:52:50 -0400
Subject: [PATCH] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check in
hugepage_pmd_enabled()
Remove READ_ONLY_THP_FOR_FS and khugepaged for file-backed pmd-sized
hugepages are enabled by the global transparent hugepage control.
khugepaged can still be enabled by per-size control for anon and shmem when
the global control is off.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
mm/khugepaged.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b8452dbdb043..586d27ce896e 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -406,18 +406,8 @@ static inline int collapse_test_exit_or_disable(struct mm_struct *mm)
mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm);
}
-static bool hugepage_pmd_enabled(void)
+static inline bool anon_hpage_pmd_enabled()
{
- /*
- * We cover the anon, shmem and the file-backed case here; file-backed
- * hugepages, when configured in, are determined by the global control.
- * Anon pmd-sized hugepages are determined by the pmd-size control.
- * Shmem pmd-sized hugepages are also determined by its pmd-size control,
- * except when the global shmem_huge is set to SHMEM_HUGE_DENY.
- */
- if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
- hugepage_global_enabled())
- return true;
if (test_bit(PMD_ORDER, &huge_anon_orders_always))
return true;
if (test_bit(PMD_ORDER, &huge_anon_orders_madvise))
@@ -425,6 +415,20 @@ static bool hugepage_pmd_enabled(void)
if (test_bit(PMD_ORDER, &huge_anon_orders_inherit) &&
hugepage_global_enabled())
return true;
+ return false;
+}
+
+static bool hugepage_pmd_enabled(void)
+{
+ /*
+ * Anon, shmem and file-backed pmd-sized hugepages are all determined by
+ * the global control. If the global control is off, anon and shmem
+ * pmd-sized hugepages are also determined by its per-size control.
+ */
+ if (hugepage_global_enabled())
+ return true;
+ if (anon_hpage_pmd_enabled())
+ return true;
if (IS_ENABLED(CONFIG_SHMEM) && shmem_hpage_pmd_enabled())
return true;
return false;
--
2.43.0
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2026-04-15 18:01 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 19:20 [PATCH 7.2 v2 00/12] Remove read-only THP support for FSes without large folio support Zi Yan
2026-04-13 19:20 ` [PATCH 7.2 v2 01/12] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check Zi Yan
2026-04-13 20:20 ` Matthew Wilcox
2026-04-13 20:34 ` Zi Yan
2026-04-14 10:19 ` David Hildenbrand (Arm)
2026-04-14 10:20 ` David Hildenbrand (Arm)
2026-04-15 6:09 ` Baolin Wang
2026-04-14 10:29 ` David Hildenbrand (Arm)
2026-04-14 15:37 ` Lance Yang
2026-04-14 15:43 ` Lance Yang
2026-04-14 15:59 ` Zi Yan
2026-04-13 19:20 ` [PATCH 7.2 v2 02/12] mm/khugepaged: add folio dirty check after try_to_unmap_flush() Zi Yan
2026-04-13 20:23 ` Matthew Wilcox
2026-04-13 20:28 ` Zi Yan
2026-04-14 10:38 ` David Hildenbrand (Arm)
2026-04-14 15:55 ` Zi Yan
2026-04-13 19:20 ` [PATCH 7.2 v2 03/12] mm/huge_memory: remove READ_ONLY_THP_FOR_FS from file_thp_enabled() Zi Yan
2026-04-14 10:40 ` David Hildenbrand (Arm)
2026-04-14 15:59 ` Zi Yan
2026-04-15 6:17 ` Baolin Wang
2026-04-13 19:20 ` [PATCH 7.2 v2 04/12] mm: remove READ_ONLY_THP_FOR_FS Kconfig option Zi Yan
2026-04-14 10:40 ` David Hildenbrand (Arm)
2026-04-15 6:20 ` Baolin Wang
2026-04-13 19:20 ` [PATCH 7.2 v2 05/12] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check in hugepage_pmd_enabled() Zi Yan
2026-04-13 20:33 ` Matthew Wilcox
2026-04-13 20:42 ` Zi Yan
2026-04-14 11:02 ` David Hildenbrand (Arm)
2026-04-14 16:30 ` Zi Yan
2026-04-14 18:14 ` David Hildenbrand (Arm)
2026-04-14 18:25 ` Zi Yan
2026-04-15 6:36 ` Baolin Wang
2026-04-15 8:00 ` David Hildenbrand (Arm)
2026-04-15 9:21 ` Baolin Wang
2026-04-15 18:01 ` Zi Yan [this message]
2026-04-13 19:20 ` [PATCH 7.2 v2 06/12] mm: fs: remove filemap_nr_thps*() functions and their users Zi Yan
2026-04-13 20:35 ` Matthew Wilcox
2026-04-14 11:02 ` David Hildenbrand (Arm)
2026-04-15 6:53 ` Baolin Wang
2026-04-13 19:20 ` [PATCH 7.2 v2 07/12] fs: remove nr_thps from struct address_space Zi Yan
2026-04-13 20:38 ` Matthew Wilcox
2026-04-15 6:44 ` Baolin Wang
2026-04-13 19:20 ` [PATCH 7.2 v2 08/12] mm/huge_memory: remove folio split check for READ_ONLY_THP_FOR_FS Zi Yan
2026-04-13 20:41 ` Matthew Wilcox
2026-04-13 20:46 ` Zi Yan
2026-04-14 11:03 ` David Hildenbrand (Arm)
2026-04-15 6:47 ` Baolin Wang
2026-04-13 19:20 ` [PATCH 7.2 v2 09/12] mm/truncate: use folio_split() in truncate_inode_partial_folio() Zi Yan
2026-04-13 19:20 ` [PATCH 7.2 v2 10/12] fs/btrfs: remove a comment referring to READ_ONLY_THP_FOR_FS Zi Yan
2026-04-14 11:06 ` David Hildenbrand (Arm)
2026-04-13 19:20 ` [PATCH 7.2 v2 11/12] selftests/mm: remove READ_ONLY_THP_FOR_FS in khugepaged Zi Yan
2026-04-14 11:06 ` David Hildenbrand (Arm)
2026-04-13 19:20 ` [PATCH 7.2 v2 12/12] selftests/mm: remove READ_ONLY_THP_FOR_FS from comments in guard-regions Zi Yan
2026-04-13 20:47 ` Matthew Wilcox
2026-04-13 20:51 ` Zi Yan
2026-04-13 22:28 ` Matthew Wilcox
2026-04-14 11:09 ` David Hildenbrand (Arm)
2026-04-14 16:45 ` Zi Yan
2026-04-14 17:40 ` Matthew Wilcox
2026-04-14 17:53 ` Zi Yan
2026-04-14 11:07 ` David Hildenbrand (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68F85F77-8EFE-449D-B643-AEEB38CB50B2@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=brauner@kernel.org \
--cc=clm@fb.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=dsterba@suse.com \
--cc=jack@suse.cz \
--cc=lance.yang@linux.dev \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=npache@redhat.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox