Re: [PATCH v3 2/2] mm: shmem: disallow hugepages if the system-wide shmem THP sysfs settings are disabled

From: Baolin Wang
Date: Mon Jun 23 2025 - 21:58:22 EST




On 2025/6/23 21:59, David Hildenbrand wrote:
On 23.06.25 10:28, Baolin Wang wrote:
When invoking thp_vma_allowable_orders(), if the TVA_ENFORCE_SYSFS flag is not
specified, we will ignore the THP sysfs settings. And the MADV_COLLAPSE is an
example of such a case.

The MADV_COLLAPSE will ignore the system-wide shmem THP sysfs settings, which
means that even though we have disabled the shmem THP configuration, MADV_COLLAPSE
will still attempt to collapse into a shmem THP. This violates the rule we have
agreed upon: never means never.

Another rule for madvise, referring to David's suggestion: “allowing for collapsing
in a VM without VM_HUGEPAGE in the "madvise" mode would be fine".

To fix the MADV_COLLAPSE issue for shmem, then the current strategy should be:

For shmem, if none of always, madvise, within_size, and inherit have enabled
PMD-sized THP, then MADV_COLLAPSE will be prohibited from collapsing PMD-sized THP.

I assume we could rephrase that to "For shmem, if "shmem_enabled" is set to either "none" or "deny", then MADV_COLLAPSE will be prohibited from collapsing."

Yes. Setting 'deny' will also prevent MADV_COLLAPSE(), and there is no 'none' option for 'shmem_enabled'. Will update the commit mesasge to make it clear.