On Tue, Apr 14, 2026 at 12:29:04PM +0200, David Hildenbrand (Arm) wrote:
>On 4/13/26 21:20, Zi Yan wrote:
>> collapse_file() requires FSes supporting large folio with at least
>> PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that.
>> MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem.
>> 
>> While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE.
>> 
>> In collapse_scan_file(), add FS eligibility check to avoid redundant scans.
>> 
>> Signed-off-by: Zi Yan <[email protected]>
>> ---
>>  mm/khugepaged.c | 12 ++++++++++--
>>  1 file changed, 10 insertions(+), 2 deletions(-)
>> 
>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>> index b8452dbdb043..d2f0acd2dac2 100644
>> --- a/mm/khugepaged.c
>> +++ b/mm/khugepaged.c
>> @@ -1892,8 +1892,9 @@ static enum scan_result collapse_file(struct mm_struct 
>> *mm, unsigned long addr,
>>      int nr_none = 0;
>>      bool is_shmem = shmem_file(file);
>>  
>> -    VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
>> -    VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
>> +    /* MADV_COLLAPSE ignores shmem huge config, so do not check shmem */
>> +    VM_WARN_ON_ONCE(!is_shmem && mapping_max_folio_order(mapping) < 
>> PMD_ORDER);
>> +    VM_WARN_ON_ONCE(start & (HPAGE_PMD_NR - 1));
>>  
>>      result = alloc_charge_folio(&new_folio, mm, cc);
>>      if (result != SCAN_SUCCEED)
>> @@ -2321,6 +2322,13 @@ static enum scan_result collapse_scan_file(struct 
>> mm_struct *mm,
>>      int node = NUMA_NO_NODE;
>>      enum scan_result result = SCAN_SUCCEED;
>>  
>> +    /*
>> +     * skip files without PMD-order folio support
>> +     * do not check shmem, since MADV_COLLAPSE ignores shmem huge config
>> +     */
>
>How is the !collapse path handled? Through thp_vma_allowable_order() in
>collapse_scan_mm_slot()?
>
>Wouldn't it be better to have that check exactly there?

Right! Looks like patch #03[1] already does that, as David also pointed
out there :)

With that in place, regular files should end up in file_thp_enabled(),
which checks that mapping_max_folio_order() >= PMD_ORDER.

For khugepaged, collapse_scan_mm_slot() calls thp_vma_allowable_order()
before entering the per-PMD scan loop, so ineligible regular file VMAs
should already get filtered there.

madvise_collapse() also calls thp_vma_allowable_order() early, so it
should get the same filtering before reaching collapse_scan_file().

So the extra check here looks redundant :)

[1] https://lore.kernel.org/linux-mm/[email protected]/

Cheers,
Lance

Reply via email to