* Re: [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check
[not found] <aa778cfc-b7f8-4100-89bb-d2b2ef8e1138@redhat.com>
@ 2026-05-07 3:29 ` Lance Yang
2026-05-07 5:52 ` Zi Yan
0 siblings, 1 reply; 5+ messages in thread
From: Lance Yang @ 2026-05-07 3:29 UTC (permalink / raw)
To: npache, ziy
Cc: akpm, david, willy, songliubraving, clm, dsterba, viro, brauner,
jack, ljs, baolin.wang, Liam.Howlett, ryan.roberts, dev.jain,
baohua, lance.yang, vbabka, rppt, surenb, mhocko, shuah,
linux-btrfs, linux-kernel, linux-fsdevel, linux-mm,
linux-kselftest
On Sun, May 03, 2026 at 09:48:40PM -0600, Nico Pache wrote:
>
>
>On 4/29/26 9:29 AM, Zi Yan wrote:
>> collapse_file() requires FSes supporting large folio with at least
>> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
>> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>>
>> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>>
>> Add a helper function mapping_pmd_folio_support() for FSes supporting large
>> folio with at least PMD_ORDER.
>>
>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>> Reviewed-by: Lance Yang <lance.yang@linux.dev>
>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> include/linux/pagemap.h | 26 ++++++++++++++++++++++++++
>> mm/khugepaged.c | 10 ++++++++--
>> 2 files changed, 34 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
>> index 1f50991b43e3b..1fed3414fe9b8 100644
>> --- a/include/linux/pagemap.h
>> +++ b/include/linux/pagemap.h
>> @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
>> return mapping_max_folio_order(mapping) > 0;
>> }
>>
>> +/**
>> + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio
>> + * @mapping: The address_space
>> + *
>> + * Some file supports large folio but does not support as large as PMD order.
>> + * If a PMD-sized pagecache folio is attempted to be created on a filesystem,
>> + * this check needs to be performed first.
>> + *
>> + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not
>> + * supported.
>> + */
>> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
>> +{
>> + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
>> + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
>> +
>> + return mapping_max_folio_order(mapping) >= PMD_ORDER;
>
>Probably a stupid question, but I dont know FS thats well.
>
>Here we are checking that the max allowed folio order is greater than
>(or eq) to the PMD_ORDER. Yet the function asks if PMD specifically is
>supported. In the future could we have some FS that does not support PMD
>orders, but does support larger orders (eg. PUD)?
Good point.
IIUC, mapping_max_folio_order() means "maximum supported order" not
"the only supported order", so mapping_pmd_folio_support() just means
"PMD order is within the supported range".
Also, mapping_set_large_folios() sets the range to:
mapping_set_folio_order_range(mapping, 0, MAX_PAGECACHE_ORDER);
and __filemap_get_folio_mpol() treats max as a cap, then falls back down
towards min.
That said, if we want the helper name to mean "PMD order specifically is
supported", the more future-proof test would be:
mapping_min_folio_order(mapping) <= PMD_ORDER &&
mapping_max_folio_order(mapping) >= PMD_ORDER
Thoughs?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check
2026-05-07 3:29 ` [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check Lance Yang
@ 2026-05-07 5:52 ` Zi Yan
0 siblings, 0 replies; 5+ messages in thread
From: Zi Yan @ 2026-05-07 5:52 UTC (permalink / raw)
To: Lance Yang, npache
Cc: akpm, david, willy, songliubraving, clm, dsterba, viro, brauner,
jack, ljs, baolin.wang, Liam.Howlett, ryan.roberts, dev.jain,
baohua, vbabka, rppt, surenb, mhocko, shuah, linux-btrfs,
linux-kernel, linux-fsdevel, linux-mm, linux-kselftest
On 7 May 2026, at 11:29, Lance Yang wrote:
> On Sun, May 03, 2026 at 09:48:40PM -0600, Nico Pache wrote:
>>
>>
>> On 4/29/26 9:29 AM, Zi Yan wrote:
>>> collapse_file() requires FSes supporting large folio with at least
>>> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
>>> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>>>
>>> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>>>
>>> Add a helper function mapping_pmd_folio_support() for FSes supporting large
>>> folio with at least PMD_ORDER.
>>>
>>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>>> Reviewed-by: Lance Yang <lance.yang@linux.dev>
>>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>>> ---
>>> include/linux/pagemap.h | 26 ++++++++++++++++++++++++++
>>> mm/khugepaged.c | 10 ++++++++--
>>> 2 files changed, 34 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
>>> index 1f50991b43e3b..1fed3414fe9b8 100644
>>> --- a/include/linux/pagemap.h
>>> +++ b/include/linux/pagemap.h
>>> @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
>>> return mapping_max_folio_order(mapping) > 0;
>>> }
>>>
>>> +/**
>>> + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio
>>> + * @mapping: The address_space
>>> + *
>>> + * Some file supports large folio but does not support as large as PMD order.
>>> + * If a PMD-sized pagecache folio is attempted to be created on a filesystem,
>>> + * this check needs to be performed first.
>>> + *
>>> + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not
>>> + * supported.
>>> + */
>>> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
>>> +{
>>> + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
>>> + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
>>> +
>>> + return mapping_max_folio_order(mapping) >= PMD_ORDER;
>>
>> Probably a stupid question, but I dont know FS thats well.
>>
>> Here we are checking that the max allowed folio order is greater than
>> (or eq) to the PMD_ORDER. Yet the function asks if PMD specifically is
>> supported. In the future could we have some FS that does not support PMD
>> orders, but does support larger orders (eg. PUD)?
>
> Good point.
>
> IIUC, mapping_max_folio_order() means "maximum supported order" not
> "the only supported order", so mapping_pmd_folio_support() just means
> "PMD order is within the supported range".
>
> Also, mapping_set_large_folios() sets the range to:
>
> mapping_set_folio_order_range(mapping, 0, MAX_PAGECACHE_ORDER);
>
> and __filemap_get_folio_mpol() treats max as a cap, then falls back down
> towards min.
>
> That said, if we want the helper name to mean "PMD order specifically is
> supported", the more future-proof test would be:
>
> mapping_min_folio_order(mapping) <= PMD_ORDER &&
> mapping_max_folio_order(mapping) >= PMD_ORDER
>
> Thoughs?
Thank both for raising this up. I agree just <= PMD_ORDER might not cover
the exact requirement here. Let me send a fixup.
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check
[not found] ` <20260429152924.727124-2-ziy@nvidia.com>
@ 2026-05-07 6:08 ` Zi Yan
2026-05-07 6:57 ` Zi Yan
2026-05-08 19:39 ` David Hildenbrand (Arm)
1 sibling, 1 reply; 5+ messages in thread
From: Zi Yan @ 2026-05-07 6:08 UTC (permalink / raw)
To: Andrew Morton, Nico Pache, Lance Yang
Cc: Matthew Wilcox (Oracle), David Hildenbrand, Song Liu, Chris Mason,
David Sterba, Alexander Viro, Christian Brauner, Jan Kara,
Lorenzo Stoakes, Zi Yan, Baolin Wang, Liam R. Howlett,
Ryan Roberts, Dev Jain, Barry Song, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
linux-btrfs, linux-kernel, linux-fsdevel, linux-mm,
linux-kselftest
On 29 Apr 2026, at 23:29, Zi Yan wrote:
> collapse_file() requires FSes supporting large folio with at least
> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>
> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>
> Add a helper function mapping_pmd_folio_support() for FSes supporting large
> folio with at least PMD_ORDER.
>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Lance Yang <lance.yang@linux.dev>
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> include/linux/pagemap.h | 26 ++++++++++++++++++++++++++
> mm/khugepaged.c | 10 ++++++++--
> 2 files changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 1f50991b43e3b..1fed3414fe9b8 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
> return mapping_max_folio_order(mapping) > 0;
> }
>
> +/**
> + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio
> + * @mapping: The address_space
> + *
> + * Some file supports large folio but does not support as large as PMD order.
> + * If a PMD-sized pagecache folio is attempted to be created on a filesystem,
> + * this check needs to be performed first.
> + *
> + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not
> + * supported.
> + */
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
> +{
> + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
> + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
> +
> + return mapping_max_folio_order(mapping) >= PMD_ORDER;
Hi Andrew,
Can you help apply the fixup below? It addresses the concern raised by
Nico and Lance[1]. Thanks.
[1] https://lore.kernel.org/all/aa778cfc-b7f8-4100-89bb-d2b2ef8e1138@redhat.com/
From 9c1749df6516c06b1628ac7804bc7a6ab5709f37 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Thu, 7 May 2026 02:02:28 -0400
Subject: [PATCH] fix mapping_pmd_folio_support() to represent its exact
meaning
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
include/linux/pagemap.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c6a4ecd3d6ed1..52895896f3357 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -530,7 +530,8 @@ static inline bool mapping_pmd_folio_support(const struct address_space *mapping
/* AS_FOLIO_ORDER is only reasonable for pagecache folios */
VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
- return mapping_max_folio_order(mapping) >= PMD_ORDER;
+ return mapping_min_folio_order(mapping) <= PMD_ORDER &&
+ mapping_max_folio_order(mapping) >= PMD_ORDER
}
#else
static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
--
2.53.0
Best Regards,
Yan, Zi
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check
2026-05-07 6:08 ` Zi Yan
@ 2026-05-07 6:57 ` Zi Yan
0 siblings, 0 replies; 5+ messages in thread
From: Zi Yan @ 2026-05-07 6:57 UTC (permalink / raw)
To: Andrew Morton, Nico Pache, Lance Yang
Cc: Matthew Wilcox (Oracle), David Hildenbrand, Song Liu, Chris Mason,
David Sterba, Alexander Viro, Christian Brauner, Jan Kara,
Lorenzo Stoakes, Zi Yan, Baolin Wang, Liam R. Howlett,
Ryan Roberts, Dev Jain, Barry Song, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
linux-btrfs, linux-kernel, linux-fsdevel, linux-mm,
linux-kselftest
On 7 May 2026, at 14:08, Zi Yan wrote:
> On 29 Apr 2026, at 23:29, Zi Yan wrote:
>
>> collapse_file() requires FSes supporting large folio with at least
>> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
>> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>>
>> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>>
>> Add a helper function mapping_pmd_folio_support() for FSes supporting large
>> folio with at least PMD_ORDER.
>>
>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>> Reviewed-by: Lance Yang <lance.yang@linux.dev>
>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> include/linux/pagemap.h | 26 ++++++++++++++++++++++++++
>> mm/khugepaged.c | 10 ++++++++--
>> 2 files changed, 34 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
>> index 1f50991b43e3b..1fed3414fe9b8 100644
>> --- a/include/linux/pagemap.h
>> +++ b/include/linux/pagemap.h
>> @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
>> return mapping_max_folio_order(mapping) > 0;
>> }
>>
>> +/**
>> + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio
>> + * @mapping: The address_space
>> + *
>> + * Some file supports large folio but does not support as large as PMD order.
>> + * If a PMD-sized pagecache folio is attempted to be created on a filesystem,
>> + * this check needs to be performed first.
>> + *
>> + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not
>> + * supported.
>> + */
>> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
>> +{
>> + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
>> + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
>> +
>> + return mapping_max_folio_order(mapping) >= PMD_ORDER;
>
> Hi Andrew,
>
> Can you help apply the fixup below? It addresses the concern raised by
> Nico and Lance[1]. Thanks.
>
> [1] https://lore.kernel.org/all/aa778cfc-b7f8-4100-89bb-d2b2ef8e1138@redhat.com/
>
I was missing a semicolon. Here is the right fixup. Sorry for the noise.
From fbd183f7528a3d0bdb421018af4aef45f6366682 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Thu, 7 May 2026 02:02:28 -0400
Subject: [PATCH] fix mapping_pmd_folio_support() to represent its exact
meaning.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
include/linux/pagemap.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c6a4ecd3d6ed1..41dbb55a47d8e 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -530,7 +530,8 @@ static inline bool mapping_pmd_folio_support(const struct address_space *mapping
/* AS_FOLIO_ORDER is only reasonable for pagecache folios */
VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
- return mapping_max_folio_order(mapping) >= PMD_ORDER;
+ return mapping_min_folio_order(mapping) <= PMD_ORDER &&
+ mapping_max_folio_order(mapping) >= PMD_ORDER;
}
#else
static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
--
2.53.0
Best Regards,
Yan, Zi
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check
[not found] ` <20260429152924.727124-2-ziy@nvidia.com>
2026-05-07 6:08 ` Zi Yan
@ 2026-05-08 19:39 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-08 19:39 UTC (permalink / raw)
To: Zi Yan, Andrew Morton, Matthew Wilcox (Oracle), Song Liu
Cc: Chris Mason, David Sterba, Alexander Viro, Christian Brauner,
Jan Kara, Lorenzo Stoakes, Baolin Wang, Liam R. Howlett,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, linux-btrfs, linux-kernel, linux-fsdevel, linux-mm,
linux-kselftest
On 4/29/26 17:29, Zi Yan wrote:
> collapse_file() requires FSes supporting large folio with at least
> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>
> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>
> Add a helper function mapping_pmd_folio_support() for FSes supporting large
> folio with at least PMD_ORDER.
>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Lance Yang <lance.yang@linux.dev>
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> include/linux/pagemap.h | 26 ++++++++++++++++++++++++++
> mm/khugepaged.c | 10 ++++++++--
> 2 files changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 1f50991b43e3b..1fed3414fe9b8 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
> return mapping_max_folio_order(mapping) > 0;
> }
Some smaller doc improvements:
>
> +/**
> + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio
"supports"
> + * @mapping: The address_space
> + *
> + * Some file supports large folio but does not support as large as PMD order.
"While some mappings support large folios, they might not support PMD-sized folios."
> + * If a PMD-sized pagecache folio is attempted to be created on a filesystem,
> + * this check needs to be performed first.
I'd rather just add (relate to the previous sentence):
"This function checks whether a mapping supports PMD-sized folios. For example,
khugepaged needs this information before attempting to collapsing THPs".
> + *
> + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not
> + * supported.
I'd say "folios are supported" and end up with:
"True if PMD-sized folios are supported, otherwise false."
> + */
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
> +{
> + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
> + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON);
> +
> + return mapping_max_folio_order(mapping) >= PMD_ORDER;
Agreed that this should check for ==, although in practice it would currently
not make a difference.
> +}
> +#else
> +static inline bool mapping_pmd_folio_support(const struct address_space *mapping)
> +{
> + return false;
> +}
> +#endif
> +
> /* Return the maximum folio size for this pagecache mapping, in bytes. */
> static inline size_t mapping_max_folio_size(const struct address_space *mapping)
> {
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index e112525c4aa9c..6808f2b48d864 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2235,8 +2235,14 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
> int nr_none = 0;
> bool is_shmem = shmem_file(file);
>
> - VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
> - VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
> + /*
> + * MADV_COLLAPSE ignores shmem huge config, so do not check shmem
> + *
> + * TODO: once shmem always calls mapping_set_large_folios() on its
> + * mapping, the shmem check can be removed.
> + */
TODO LGTM.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-08 19:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <aa778cfc-b7f8-4100-89bb-d2b2ef8e1138@redhat.com>
2026-05-07 3:29 ` [PATCH v5 01/14] mm/khugepaged: remove READ_ONLY_THP_FOR_FS check Lance Yang
2026-05-07 5:52 ` Zi Yan
[not found] <20260429152924.727124-1-ziy@nvidia.com>
[not found] ` <20260429152924.727124-2-ziy@nvidia.com>
2026-05-07 6:08 ` Zi Yan
2026-05-07 6:57 ` Zi Yan
2026-05-08 19:39 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox