* [PATCH] mm: shmem: don't set large-order range for internal anonymous shmem mapping
@ 2026-04-07 6:07 Baolin Wang
2026-04-07 6:49 ` Lance Yang
0 siblings, 1 reply; 3+ messages in thread
From: Baolin Wang @ 2026-04-07 6:07 UTC (permalink / raw)
To: akpm, hughd
Cc: willy, ziy, david, ljs, lance.yang, baolin.wang, linux-mm,
linux-kernel
Anonymous shmem large order allocations are dynamically controlled via the
global THP sysfs knob (/sys/kernel/mm/transparent_hugepage/shmem_enabled)
and the per-size mTHP knobs (/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/shmem_enabled).
Therefore, anonymous shmem uses shmem_allowable_huge_orders() to check
which large orders are allowed, rather than relying on mapping_max_folio_order().
Moreover, mapping_max_folio_order() is intended to control large order
allocations only for tmpfs mounts. Clarify this by not setting a large-order
range for internal anonymous shmem mappings, to avoid confusion, as discussed
in the previous thread[1].
[1] https://lore.kernel.org/all/ec927492-4577-4192-8fad-85eb1bb43121@linux.alibaba.com/
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/shmem.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index 4ecefe02881d..a60fe067969c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
if (sbinfo->noswap)
mapping_set_unevictable(inode->i_mapping);
- /* Don't consider 'deny' for emergencies and 'force' for testing */
- if (sbinfo->huge)
+ /*
+ * Only set the large order range for tmpfs mounts. The large order
+ * selection for the internal anonymous shmem mount is configured
+ * dynamically via the 'shmem_enabled' interfaces, so there is no
+ * need to set a large order range for the internal anonymous shmem
+ * mapping.
+ *
+ * Note: Don't consider 'deny' for emergencies and 'force' for
+ * testing.
+ */
+ if (sbinfo->huge && !(sb->s_flags & SB_KERNMOUNT))
mapping_set_large_folios(inode->i_mapping);
switch (mode & S_IFMT) {
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: shmem: don't set large-order range for internal anonymous shmem mapping
2026-04-07 6:07 [PATCH] mm: shmem: don't set large-order range for internal anonymous shmem mapping Baolin Wang
@ 2026-04-07 6:49 ` Lance Yang
2026-04-07 7:08 ` Baolin Wang
0 siblings, 1 reply; 3+ messages in thread
From: Lance Yang @ 2026-04-07 6:49 UTC (permalink / raw)
To: baolin.wang
Cc: akpm, hughd, willy, ziy, david, ljs, lance.yang, linux-mm,
linux-kernel
On Tue, Apr 07, 2026 at 02:07:27PM +0800, Baolin Wang wrote:
>Anonymous shmem large order allocations are dynamically controlled via the
>global THP sysfs knob (/sys/kernel/mm/transparent_hugepage/shmem_enabled)
>and the per-size mTHP knobs (/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/shmem_enabled).
>
>Therefore, anonymous shmem uses shmem_allowable_huge_orders() to check
>which large orders are allowed, rather than relying on mapping_max_folio_order().
>Moreover, mapping_max_folio_order() is intended to control large order
>allocations only for tmpfs mounts. Clarify this by not setting a large-order
>range for internal anonymous shmem mappings, to avoid confusion, as discussed
>in the previous thread[1].
>
>[1] https://lore.kernel.org/all/ec927492-4577-4192-8fad-85eb1bb43121@linux.alibaba.com/
>Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>---
> mm/shmem.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
>diff --git a/mm/shmem.c b/mm/shmem.c
>index 4ecefe02881d..a60fe067969c 100644
>--- a/mm/shmem.c
>+++ b/mm/shmem.c
>@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
> if (sbinfo->noswap)
> mapping_set_unevictable(inode->i_mapping);
>
>- /* Don't consider 'deny' for emergencies and 'force' for testing */
>- if (sbinfo->huge)
>+ /*
>+ * Only set the large order range for tmpfs mounts. The large order
>+ * selection for the internal anonymous shmem mount is configured
>+ * dynamically via the 'shmem_enabled' interfaces, so there is no
>+ * need to set a large order range for the internal anonymous shmem
>+ * mapping.
>+ *
>+ * Note: Don't consider 'deny' for emergencies and 'force' for
>+ * testing.
>+ */
>+ if (sbinfo->huge && !(sb->s_flags & SB_KERNMOUNT))
FWIW, SB_KERNMOUNT is broader than "internal anonymous shmem" and covers
all shm_mnt users too.
So maybe "internal shmem mount" would be a better description of what
this code is actually checking.
> mapping_set_large_folios(inode->i_mapping);
>
> switch (mode & S_IFMT) {
Cheers,
Lance
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: shmem: don't set large-order range for internal anonymous shmem mapping
2026-04-07 6:49 ` Lance Yang
@ 2026-04-07 7:08 ` Baolin Wang
0 siblings, 0 replies; 3+ messages in thread
From: Baolin Wang @ 2026-04-07 7:08 UTC (permalink / raw)
To: Lance Yang; +Cc: akpm, hughd, willy, ziy, david, ljs, linux-mm, linux-kernel
On 4/7/26 2:49 PM, Lance Yang wrote:
>
> On Tue, Apr 07, 2026 at 02:07:27PM +0800, Baolin Wang wrote:
>> Anonymous shmem large order allocations are dynamically controlled via the
>> global THP sysfs knob (/sys/kernel/mm/transparent_hugepage/shmem_enabled)
>> and the per-size mTHP knobs (/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/shmem_enabled).
>>
>> Therefore, anonymous shmem uses shmem_allowable_huge_orders() to check
>> which large orders are allowed, rather than relying on mapping_max_folio_order().
>> Moreover, mapping_max_folio_order() is intended to control large order
>> allocations only for tmpfs mounts. Clarify this by not setting a large-order
>> range for internal anonymous shmem mappings, to avoid confusion, as discussed
>> in the previous thread[1].
>>
>> [1] https://lore.kernel.org/all/ec927492-4577-4192-8fad-85eb1bb43121@linux.alibaba.com/
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> mm/shmem.c | 13 +++++++++++--
>> 1 file changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/shmem.c b/mm/shmem.c
>> index 4ecefe02881d..a60fe067969c 100644
>> --- a/mm/shmem.c
>> +++ b/mm/shmem.c
>> @@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
>> if (sbinfo->noswap)
>> mapping_set_unevictable(inode->i_mapping);
>>
>> - /* Don't consider 'deny' for emergencies and 'force' for testing */
>> - if (sbinfo->huge)
>> + /*
>> + * Only set the large order range for tmpfs mounts. The large order
>> + * selection for the internal anonymous shmem mount is configured
>> + * dynamically via the 'shmem_enabled' interfaces, so there is no
>> + * need to set a large order range for the internal anonymous shmem
>> + * mapping.
>> + *
>> + * Note: Don't consider 'deny' for emergencies and 'force' for
>> + * testing.
>> + */
>> + if (sbinfo->huge && !(sb->s_flags & SB_KERNMOUNT))
>
> FWIW, SB_KERNMOUNT is broader than "internal anonymous shmem" and covers
> all shm_mnt users too.
>
> So maybe "internal shmem mount" would be a better description of what
> this code is actually checking.
Right, good point. Will fix. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-07 7:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 6:07 [PATCH] mm: shmem: don't set large-order range for internal anonymous shmem mapping Baolin Wang
2026-04-07 6:49 ` Lance Yang
2026-04-07 7:08 ` Baolin Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox