On 2025/7/2 13:57, Nico Pache wrote:
Allow madvise_collapse to scan/collapse all mTHP orders without the strict requirement of needing the PMD-order enabled. Signed-off-by: Nico Pache <[email protected]>
I am afraid we should drop this patch from the series, since Hugh explicitly opposed my modification of the madvise_collapse control logic in this thread[1].
Moreover, since we have not yet clarified how to handle the conflict between the semantics of madvise_collapse and the THP interfaces, we should keep the current logic[2] (means madvise_collapse still only allows PMD collapse).
If madvise_collapse is to support mTHP collapse, there will be more semantic conflicts to discuss.
[1] https://lore.kernel.org/all/[email protected]/ [2] https://lore.kernel.org/all/[email protected]/
--- mm/khugepaged.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b96a7327b9c0..6ea681b81647 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2930,11 +2930,13 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, unsigned long hstart, hend, addr; int thps = 0, last_fail = SCAN_FAIL; bool mmap_locked = true; + unsigned long orders = vma_is_anonymous(vma) ? + THP_ORDERS_ALL_ANON : BIT(PMD_ORDER);BUG_ON(vma->vm_start > start);BUG_ON(vma->vm_end < end);- if (!thp_vma_allowable_order(vma, vma->vm_flags, 0, PMD_ORDER))+ if (!thp_vma_allowable_orders(vma, vma->vm_flags, 0, orders)) return -EINVAL;cc = kmalloc(sizeof(*cc), GFP_KERNEL);@@ -2956,7 +2958,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, mmap_read_lock(mm); mmap_locked = true; result = hugepage_vma_revalidate(mm, addr, false, &vma, - cc, BIT(HPAGE_PMD_ORDER)); + cc, orders); if (result != SCAN_SUCCEED) { last_fail = result; goto out_nolock;
