Re: [PATCH 7.2 v16 09/13] mm/khugepaged: introduce collapse_allowable_orders helper function

Nico Pache
2026-04-29T18:22:21Z

On 4/27/26 2:24 PM, David Hildenbrand (Arm) wrote:
> On 4/19/26 20:57, Nico Pache wrote:
>> Add collapse_allowable_orders() to generalize THP order eligibility. The
>> function determines which THP orders are permitted based on collapse
>> context (khugepaged vs madv_collapse).
>>
>> This consolidates collapse configuration logic and provides a clean
>> interface for future mTHP collapse support where the orders may be
>> different.
>>
>> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> Signed-off-by: Nico Pache <npache@redhat.com>
>> ---
>
>
> [...]
>
>> cc = kmalloc_obj(*cc);
>> diff --git a/mm/vma.c b/mm/vma.c
>> index 377321b48734..c0398fb597b3 100644
>> --- a/mm/vma.c
>> +++ b/mm/vma.c
>> @@ -989,7 +989,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range(
>> goto abort;
>>
>> vma_set_flags_mask(vmg->target, sticky_flags);
>> - khugepaged_enter_vma(vmg->target, vmg->vm_flags);
>> + khugepaged_enter_vma(vmg->target);
>> vmg->state = VMA_MERGE_SUCCESS;
>> return vmg->target;
>>
>> @@ -1110,7 +1110,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg)
>> * following VMA if we have VMAs on both sides.
>> */
>> if (vmg->target && !vma_expand(vmg)) {
>> - khugepaged_enter_vma(vmg->target, vmg->vm_flags);
>> + khugepaged_enter_vma(vmg->target);
>> vmg->state = VMA_MERGE_SUCCESS;
>> return vmg->target;
>> }
>> @@ -2589,7 +2589,7 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap,
>> * call covers the non-merge case.
>> */
>> if (!vma_is_anonymous(vma))
>> - khugepaged_enter_vma(vma, map->vm_flags);
>> + khugepaged_enter_vma(vma);
>> *vmap = vma;
>
> Are you sure that in all cases, vma->vm_flags already corresponds to
> vmg->vm_flags / map->vm_flags?

I reviewed most of them and nothing stuck out, but I can go over them
again. Lorenzo may also have more insight into this as he is more
familiar and has been working on this stuff.

@lorenzo?

>
>
> That's a change that makes this patch unnecessary hard to follow, in particular,
> because it's not documented in the patch description.

Thats really weird I could have sworn I did update this description...
There was a lot of changes this round, so it was hard to keep track of
everything. Sorry.

>
> If you think the change is fine, you should better move that into a separate
> cleanup patch where you only drop the flags parameter from khugepaged_enter_vma().

Yeah thats a better idea. Ill separate it out, thank you for the reviews :)

>