From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 616CE2DECA3 for ; Thu, 23 Apr 2026 20:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776976245; cv=none; b=FGmUk8bq5Bif9jlSEIuzuk9cKtyAYhh+vAFDwaoEXJtV2gALgqD6e5UgfNFeg3mKpXsn/uZNJLcWS/4HkgkkWwVnEcml9DQdOehmRRSjVlahaqK19qgcv+4KzwvrAqgnPjAjYS7o6S4ljIlxD0cFSDkUU/HWxFV7s3yQnnAOJOY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776976245; c=relaxed/simple; bh=vhadWvy4VlFNmmU9nkUEgfIn1v/TnFgPg1cvvRMrBzA=; h=Date:To:From:Subject:Message-Id; b=dzSTPbegbs0EBKf9oaae2yu8bUqB7ZtjNPMmEPYGwMkNh57x7dZxhIW33qvnAiE+dxp+v6Z3ZM5Q6CJGaDdByTqITabvgrNMKX72Xh4fHG7YNjbpJnTymWEmahMuNBqxtJrhrg1tVcbD6PktSunuC3c1v1V/Va+6PKQ5L4clO0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=qhUKa3ml; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="qhUKa3ml" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0071BC2BCAF; Thu, 23 Apr 2026 20:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1776976245; bh=vhadWvy4VlFNmmU9nkUEgfIn1v/TnFgPg1cvvRMrBzA=; h=Date:To:From:Subject:From; b=qhUKa3mldeXY16P2vWZeXN5eO4vbbvTMrmILSvRqPA1UDhW1xdbLHAXeSU79fxAcJ 8Ys8GqpAxHhTdp6unY0zP2RhxtEAs/lirWh3tQd14dxUZ7J9oPOsdduPUV6H6clGQT c8/wjFDybGqmXBcgeAV8Noh/026ADbyK4TquDrw4= Date: Thu, 23 Apr 2026 13:30:44 -0700 To: mm-commits@vger.kernel.org,npache@redhat.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-khugepaged-generalize-hugepage_vma_revalidate-for-mthp-support.patch added to mm-new branch Message-Id: <20260423203045.0071BC2BCAF@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/khugepaged: generalize hugepage_vma_revalidate for mTHP support has been added to the -mm mm-new branch. Its filename is mm-khugepaged-generalize-hugepage_vma_revalidate-for-mthp-support.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-khugepaged-generalize-hugepage_vma_revalidate-for-mthp-support.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Nico Pache Subject: mm/khugepaged: generalize hugepage_vma_revalidate for mTHP support Date: Sun, 19 Apr 2026 12:57:38 -0600 Patch series "khugepaged: mTHP support", v16. This series provides khugepaged with the capability to collapse anonymous memory regions to mTHPs. To achieve this we generalize the khugepaged functions to no longer depend on PMD_ORDER. Then during the PMD scan, we use a bitmap to track individual pages that are occupied (!none/zero). After the PMD scan is done, we use the bitmap to find the optimal mTHP sizes for the PMD range. The restriction on max_ptes_none is removed during the scan, to make sure we account for the whole PMD range in the bitmap. When no mTHP size is enabled, the legacy behavior of khugepaged is maintained. We currently only support max_ptes_none values of 0 or HPAGE_PMD_NR - 1 (ie 511). If any other value is specified, the kernel will emit a warning and no mTHP collapse will be attempted. If a mTHP collapse is attempted, but contains swapped out, or shared pages, we don't perform the collapse. It is now also possible to collapse to mTHPs without requiring the PMD THP size to be enabled. These limitations are to prevent collapse "creep" behavior. This prevents constantly promoting mTHPs to the next available size, which would occur because a collapse introduces more non-zero pages that would satisfy the promotion condition on subsequent scans. Patch 1-2: Generalize hugepage_vma_revalidate and alloc_charge_folio for arbitrary orders. Patch 3: Rework max_ptes_* handling into helper functions Patch 4-5: Generalize __collapse_huge_page_* and collapse_huge_page Patch 6: Skip collapsing mTHP to smaller orders Patch 7-8: Add per-order mTHP statistics and tracepoints Patch 9: Introduce collapse_allowable_orders helper function Patch 10-12: Introduce bitmap and mTHP collapse support, fully enabled Patch 13: Documentation This patch (of 13): For khugepaged to support different mTHP orders, we must generalize this to check if the PMD is not shared by another VMA and that the order is enabled. No functional change in this patch. Also correct a comment about the functionality of the revalidation and fix a double space issues. Link: https://lore.kernel.org/20260419185750.260784-1-npache@redhat.com Link: https://lore.kernel.org/20260419185750.260784-2-npache@redhat.com Co-developed-by: Dev Jain Signed-off-by: Dev Jain Signed-off-by: Nico Pache Reviewed-by: Wei Yang Reviewed-by: Lance Yang Reviewed-by: Baolin Wang Reviewed-by: Lorenzo Stoakes Reviewed-by: Zi Yan Acked-by: David Hildenbrand (Arm) Acked-by: Usama Arif Cc: Alistair Popple Cc: Andrea Arcangeli Cc: Anshuman Khandual Cc: Barry Song Cc: Brendan Jackman Cc: Byungchul Park Cc: Catalin Marinas Cc: David Rientjes Cc: Gregory Price Cc: "Huang, Ying" Cc: Hugh Dickins Cc: Jan Kara Cc: Jann Horn Cc: Johannes Weiner Cc: Jonathan Corbet Cc: Joshua Hahn Cc: Kefeng Wang Cc: Liam Howlett Cc: "Masami Hiramatsu (Google)" Cc: Mathieu Desnoyers Cc: Matthew Brost Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Mike Rapoport Cc: Nanyong Sun Cc: Pedro Falcato Cc: Peter Xu Cc: Rafael Aquini Cc: Rakie Kim Cc: Randy Dunlap Cc: Ryan Roberts Cc: Shivank Garg Cc: Steven Rostedt Cc: Suren Baghdasaryan Cc: Takashi Iwai (SUSE) Cc: Thomas Hellström Cc: Vishal Moola (Oracle) Cc: Vlastimil Babka Cc: Will Deacon Cc: Yang Shi Cc: Zach O'Keefe Cc: Bagas Sanjaya Signed-off-by: Andrew Morton --- mm/khugepaged.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/mm/khugepaged.c~mm-khugepaged-generalize-hugepage_vma_revalidate-for-mthp-support +++ a/mm/khugepaged.c @@ -902,12 +902,13 @@ static int collapse_find_target_node(str /* * If mmap_lock temporarily dropped, revalidate vma - * before taking mmap_lock. + * after taking the mmap_lock again. * Returns enum scan_result value. */ static enum scan_result hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, - bool expect_anon, struct vm_area_struct **vmap, struct collapse_control *cc) + bool expect_anon, struct vm_area_struct **vmap, + struct collapse_control *cc, unsigned int order) { struct vm_area_struct *vma; enum tva_type type = cc->is_khugepaged ? TVA_KHUGEPAGED : @@ -920,15 +921,16 @@ static enum scan_result hugepage_vma_rev if (!vma) return SCAN_VMA_NULL; + /* Always check the PMD order to ensure its not shared by another VMA */ if (!thp_vma_suitable_order(vma, address, PMD_ORDER)) return SCAN_ADDRESS_RANGE; - if (!thp_vma_allowable_order(vma, vma->vm_flags, type, PMD_ORDER)) + if (!thp_vma_allowable_orders(vma, vma->vm_flags, type, BIT(order))) return SCAN_VMA_CHECK; /* * Anon VMA expected, the address may be unmapped then * remapped to file after khugepaged reaquired the mmap_lock. * - * thp_vma_allowable_order may return true for qualified file + * thp_vma_allowable_orders may return true for qualified file * vmas. */ if (expect_anon && (!(*vmap)->anon_vma || !vma_is_anonymous(*vmap))) @@ -1121,7 +1123,8 @@ static enum scan_result collapse_huge_pa goto out_nolock; mmap_read_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc); + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, + HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) { mmap_read_unlock(mm); goto out_nolock; @@ -1155,7 +1158,8 @@ static enum scan_result collapse_huge_pa * mmap_lock. */ mmap_write_lock(mm); - result = hugepage_vma_revalidate(mm, address, true, &vma, cc); + result = hugepage_vma_revalidate(mm, address, true, &vma, cc, + HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out_up_write; /* check if the pmd is still valid */ @@ -2857,8 +2861,8 @@ int madvise_collapse(struct vm_area_stru mmap_unlocked = false; *lock_dropped = true; result = hugepage_vma_revalidate(mm, addr, false, &vma, - cc); - if (result != SCAN_SUCCEED) { + cc, HPAGE_PMD_ORDER); + if (result != SCAN_SUCCEED) { last_fail = result; goto out_nolock; } _ Patches currently in -mm which might be from npache@redhat.com are mm-khugepaged-generalize-hugepage_vma_revalidate-for-mthp-support.patch mm-khugepaged-rework-max_ptes_-handling-with-helper-functions.patch mm-khugepaged-generalize-__collapse_huge_page_-for-mthp-support.patch mm-khugepaged-generalize-collapse_huge_page-for-mthp-collapse.patch mm-khugepaged-skip-collapsing-mthp-to-smaller-orders.patch mm-khugepaged-add-per-order-mthp-collapse-failure-statistics.patch mm-khugepaged-improve-tracepoints-for-mthp-orders.patch mm-khugepaged-introduce-collapse_allowable_orders-helper-function.patch mm-khugepaged-introduce-mthp-collapse-support.patch mm-khugepaged-avoid-unnecessary-mthp-collapse-attempts.patch documentation-mm-update-the-admin-guide-for-mthp-collapse.patch