* [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse
@ 2026-09-14 2:12 Baolin Wang
2026-09-14 2:23 ` Barry Song
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Baolin Wang @ 2026-09-14 2:12 UTC (permalink / raw)
To: akpm, hughd, david
Cc: ziy, liam, nico.pache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, kas, ljs, baolin.wang, linux-mm,
linux-kernel
According to Documentation/mm/transhuge.rst, MADV_COLLAPSE is expected to
ignore any THP or mTHP interface settings.
However, after commit 26c7d8413aaf ("mm: thp: support "THPeligible" semantics
for mTHP with anonymous shmem"), performing MADV_COLLAPSE on shmem will
depend on /sys/.../hugepages-2048kB/shmem_enabled being set to "inherit"
(although that is the default), which can cause MADV_COLLAPSE to fail
unexpectedly.
Fix this by returning the result of shmem_huge_global_enabled() directly
when MADV_COLLAPSE is requested, allowing PMD-order collapse while ignoring
shmem THP/mTHP settings.
Fixes: 26c7d8413aaf ("mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem")
Reported-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Closes: https://lore.kernel.org/all/20260908125105.1510704-7-kirill@shutemov.name/
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Acked-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
Changes from v1:
- Use the correct fixes tag (per Kiryl).
- Collect reviewed tags from Kiryl, Zi and Lance. Thanks.
---
mm/shmem.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index c92ed17dbc4a..b572c60f2af8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2049,8 +2049,11 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
global_orders = shmem_huge_global_enabled(inode, index, write_end,
shmem_huge_force, vma, vm_flags);
- /* Tmpfs huge pages allocation */
- if (!vma || !vma_is_anon_shmem(vma))
+ /*
+ * Tmpfs huge pages allocation or forced collapse ignores
+ * sysfs configs.
+ */
+ if (!vma || !vma_is_anon_shmem(vma) || shmem_huge_force)
return global_orders;
/*
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse
2026-09-14 2:12 [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse Baolin Wang
@ 2026-09-14 2:23 ` Barry Song
2026-09-14 2:43 ` Andrew Morton
2026-09-14 3:09 ` Qi Zheng
2 siblings, 0 replies; 5+ messages in thread
From: Barry Song @ 2026-09-14 2:23 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, hughd, david, ziy, liam, nico.pache, ryan.roberts,
dev.jain, lance.yang, usama.arif, kas, ljs, linux-mm,
linux-kernel
On Mon, Sep 14, 2026 at 10:13 AM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
> According to Documentation/mm/transhuge.rst, MADV_COLLAPSE is expected to
> ignore any THP or mTHP interface settings.
>
> However, after commit 26c7d8413aaf ("mm: thp: support "THPeligible" semantics
> for mTHP with anonymous shmem"), performing MADV_COLLAPSE on shmem will
> depend on /sys/.../hugepages-2048kB/shmem_enabled being set to "inherit"
> (although that is the default), which can cause MADV_COLLAPSE to fail
> unexpectedly.
>
> Fix this by returning the result of shmem_huge_global_enabled() directly
> when MADV_COLLAPSE is requested, allowing PMD-order collapse while ignoring
> shmem THP/mTHP settings.
>
> Fixes: 26c7d8413aaf ("mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem")
> Reported-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Closes: https://lore.kernel.org/all/20260908125105.1510704-7-kirill@shutemov.name/
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Acked-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Lance Yang <lance.yang@linux.dev>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
LGTM,
Reviewed-by: Barry Song <baohua@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse
2026-09-14 2:12 [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse Baolin Wang
2026-09-14 2:23 ` Barry Song
@ 2026-09-14 2:43 ` Andrew Morton
2026-09-14 3:40 ` Baolin Wang
2026-09-14 3:09 ` Qi Zheng
2 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2026-09-14 2:43 UTC (permalink / raw)
To: Baolin Wang
Cc: hughd, david, ziy, liam, nico.pache, ryan.roberts, dev.jain,
baohua, lance.yang, usama.arif, kas, ljs, linux-mm, linux-kernel
On Mon, 14 Sep 2026 10:12:41 +0800 Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
> According to Documentation/mm/transhuge.rst, MADV_COLLAPSE is expected to
> ignore any THP or mTHP interface settings.
>
> However, after commit 26c7d8413aaf ("mm: thp: support "THPeligible" semantics
> for mTHP with anonymous shmem"), performing MADV_COLLAPSE on shmem will
> depend on /sys/.../hugepages-2048kB/shmem_enabled being set to "inherit"
> (although that is the default), which can cause MADV_COLLAPSE to fail
> unexpectedly.
Userspace-visible runtime regression?
> Fix this by returning the result of shmem_huge_global_enabled() directly
> when MADV_COLLAPSE is requested, allowing PMD-order collapse while ignoring
> shmem THP/mTHP settings.
>
> Fixes: 26c7d8413aaf ("mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem")
Should we backport?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse
2026-09-14 2:12 [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse Baolin Wang
2026-09-14 2:23 ` Barry Song
2026-09-14 2:43 ` Andrew Morton
@ 2026-09-14 3:09 ` Qi Zheng
2 siblings, 0 replies; 5+ messages in thread
From: Qi Zheng @ 2026-09-14 3:09 UTC (permalink / raw)
To: Baolin Wang, akpm, hughd, david
Cc: ziy, liam, nico.pache, ryan.roberts, dev.jain, baohua,
lance.yang, usama.arif, kas, ljs, linux-mm, linux-kernel
On 9/14/26 10:12 AM, Baolin Wang wrote:
> According to Documentation/mm/transhuge.rst, MADV_COLLAPSE is expected to
> ignore any THP or mTHP interface settings.
>
> However, after commit 26c7d8413aaf ("mm: thp: support "THPeligible" semantics
> for mTHP with anonymous shmem"), performing MADV_COLLAPSE on shmem will
> depend on /sys/.../hugepages-2048kB/shmem_enabled being set to "inherit"
> (although that is the default), which can cause MADV_COLLAPSE to fail
> unexpectedly.
>
> Fix this by returning the result of shmem_huge_global_enabled() directly
> when MADV_COLLAPSE is requested, allowing PMD-order collapse while ignoring
> shmem THP/mTHP settings.
>
> Fixes: 26c7d8413aaf ("mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem")
> Reported-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Closes: https://lore.kernel.org/all/20260908125105.1510704-7-kirill@shutemov.name/
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Acked-by: Zi Yan <ziy@nvidia.com>
> Reviewed-by: Lance Yang <lance.yang@linux.dev>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> Changes from v1:
> - Use the correct fixes tag (per Kiryl).
> - Collect reviewed tags from Kiryl, Zi and Lance. Thanks.
> ---
> mm/shmem.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
Acked-by: Qi Zheng <qi.zheng@linux.dev>
Thanks,
Qi
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index c92ed17dbc4a..b572c60f2af8 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2049,8 +2049,11 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
>
> global_orders = shmem_huge_global_enabled(inode, index, write_end,
> shmem_huge_force, vma, vm_flags);
> - /* Tmpfs huge pages allocation */
> - if (!vma || !vma_is_anon_shmem(vma))
> + /*
> + * Tmpfs huge pages allocation or forced collapse ignores
> + * sysfs configs.
> + */
> + if (!vma || !vma_is_anon_shmem(vma) || shmem_huge_force)
> return global_orders;
>
> /*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse
2026-09-14 2:43 ` Andrew Morton
@ 2026-09-14 3:40 ` Baolin Wang
0 siblings, 0 replies; 5+ messages in thread
From: Baolin Wang @ 2026-09-14 3:40 UTC (permalink / raw)
To: Andrew Morton
Cc: hughd, david, ziy, liam, nico.pache, ryan.roberts, dev.jain,
baohua, lance.yang, usama.arif, kas, ljs, linux-mm, linux-kernel
On 9/14/26 10:43 AM, Andrew Morton wrote:
> On Mon, 14 Sep 2026 10:12:41 +0800 Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
>
>> According to Documentation/mm/transhuge.rst, MADV_COLLAPSE is expected to
>> ignore any THP or mTHP interface settings.
>>
>> However, after commit 26c7d8413aaf ("mm: thp: support "THPeligible" semantics
>> for mTHP with anonymous shmem"), performing MADV_COLLAPSE on shmem will
>> depend on /sys/.../hugepages-2048kB/shmem_enabled being set to "inherit"
>> (although that is the default), which can cause MADV_COLLAPSE to fail
>> unexpectedly.
>
> Userspace-visible runtime regression?
Yes, it could cause a userspace-visible performance regression.
>> Fix this by returning the result of shmem_huge_global_enabled() directly
>> when MADV_COLLAPSE is requested, allowing PMD-order collapse while ignoring
>> shmem THP/mTHP settings.
>>
>> Fixes: 26c7d8413aaf ("mm: thp: support "THPeligible" semantics for mTHP with anonymous shmem")
>
> Should we backport?
I'm not sure, since the issue is triggered by a rather uncommon
configuration. But given that the fix is simple, I think it's fine to CC
stable.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-14 3:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14 2:12 [PATCH v2] mm: shmem: ignore sysfs configs for shmem forced collapse Baolin Wang
2026-09-14 2:23 ` Barry Song
2026-09-14 2:43 ` Andrew Morton
2026-09-14 3:40 ` Baolin Wang
2026-09-14 3:09 ` Qi Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®