Re: [PATCH v8 07/14] mm: shmem: allow THP support determination at folio allocation time

From: Luiz Capitulino

Date: Tue Sep 22 2026 - 21:38:06 EST




On 9/21/26 10:20 PM, Zi Yan wrote:
On Thu Sep 17, 2026 at 9:45 PM EDT, Luiz Capitulino wrote:
In order to enable THP support in shmem today, besides the user
configuration required, the CPU must support PMD-sized pages. This
is the case because of the following has_transparent_hugepage()
usage:

- shmem_parse_one() and shmem_parse_huge(): Check if THP is built-in and
if the CPU supports PMD-sized pages

- shmem_init(): Since the CONFIG_TRANSPARENT_HUGEPAGE guard is outside
the code block calling has_transparent_hugepage(), the
has_transparent_hugepage() call is exclusively checking if the CPU
supports PMD-sized pages

While it's necessary to check if CONFIG_TRANSPARENT_HUGEPAGE is enabled
in all cases, shmem can determine THP size support at folio allocation
time. Therefore, drop the has_transparent_hugepage() usage listed above
while keeping the CONFIG_TRANSPARENT_HUGEPAGE checks.

Additionally, we need to check if PMD size order is supported in
shmem_getattr(). Use pgtable_has_pmd_leaves() for that.

Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
Signed-off-by: Luiz Capitulino <luizcap@xxxxxxxxxx>
---
mm/shmem.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 776dff8a848e..930657d05375 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -690,7 +690,7 @@ static int shmem_parse_huge(const char *str)
else
return -EINVAL;
- if (!has_transparent_hugepage() &&
+ if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY)
return -EINVAL;

This can be deleted, since shmem_parse_huge() is guarded by
CONFIG_TRANSPARENT_HUGEPAGE and after the change the if is always false
under that guard.

Otherwise, LGTM. With the above code deleted, feel free to add

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

OK, here's the diff:

diff --git a/mm/shmem.c b/mm/shmem.c
index c00bc1829fc9..d12995d41846 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -690,10 +690,6 @@ static int shmem_parse_huge(const char *str)
else
return -EINVAL;
- if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) &&
- huge != SHMEM_HUGE_NEVER && huge != SHMEM_HUGE_DENY)
- return -EINVAL;
-
/* Do not override huge allocation policy with non-PMD sized mTHP */
if (huge == SHMEM_HUGE_FORCE &&
huge_shmem_orders_inherit != BIT(HPAGE_PMD_ORDER))