Re: [PATCH] mm: shmem: fix incorrect vm_flags usage when checking allowable orders

From: Lance Yang

Date: Mon Aug 17 2026 - 03:40:00 EST




On 2026/8/17 15:16, Baolin Wang wrote:
Lance reported that when MADV_HUGEPAGE is set on a tmpfs file mounted with
huge=advise option, khugepaged fails the allowable order check and does not
scan the tmpfs file for collapse.

After commit 6beeab870e70 ("mm: shmem: move shmem_huge_global_enabled() into
shmem_allowable_huge_orders()"), the shmem/tmpfs allowable order check reads
vma->vm_flags directly. However, when MADV_HUGEPAGE is handled,
khugepaged_enter_vma() is called before the VMA's vm_flags have been updated,
so the check uses stale flags and incorrectly rejects the VMA for collapse.
As a result, khugepaged does not collapse the tmpfs file into PMD order in time.

Fix this by passing vm_flags as a parameter to shmem_allowable_huge_orders()
instead of reading it from the vm_area_struct.

Reported-by: Lance Yang <lance.yang@xxxxxxxxx>
Closes: https://lore.kernel.org/all/20260815181632.21453-1-lance.yang@xxxxxxxxx/
Fixes: 6beeab870e70 ("mm: shmem: move shmem_huge_global_enabled() into shmem_allowable_huge_orders()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
---

LGTM.

Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>