Re: [PATCH v2 1/7] mm/khugepaged: refactor per-scan state clearing into collapse_control_init_scan()
From: Lorenzo Stoakes (ARM)
Date: Thu Jul 30 2026 - 11:48:37 EST
On Tue, Jul 14, 2026 at 08:59:30PM -0600, Nico Pache wrote:
> Extract the repeated clearing of node_load, alloc_nmask, and
> mthp_present_ptes into a helper to reduce duplication in
> collapse_scan_pmd() and collapse_scan_file(). Althought file scans do not
> current use the bitmap, they will in the future, and clearing it now is
> harmless.
>
> Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
> Acked-by: Usama Arif <usama.arif@xxxxxxxxx>
> Signed-off-by: Nico Pache <npache@xxxxxxxxxx>
LGTM so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> mm/khugepaged.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 55157567dc4c..6ec0812210b6 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -629,6 +629,13 @@ void __khugepaged_exit(struct mm_struct *mm)
> }
> }
>
> +static void collapse_control_init_scan(struct collapse_control *cc)
> +{
> + memset(cc->node_load, 0, sizeof(cc->node_load));
> + nodes_clear(cc->alloc_nmask);
> + bitmap_zero(cc->mthp_present_ptes, MAX_PTRS_PER_PTE);
> +}
> +
> static void release_pte_folio(struct folio *folio)
> {
> node_stat_mod_folio(folio,
> @@ -1617,9 +1624,7 @@ static enum scan_result collapse_scan_pmd(struct mm_struct *mm,
> goto out;
> }
>
> - bitmap_zero(cc->mthp_present_ptes, MAX_PTRS_PER_PTE);
> - memset(cc->node_load, 0, sizeof(cc->node_load));
> - nodes_clear(cc->alloc_nmask);
> + collapse_control_init_scan(cc);
>
> enabled_orders = collapse_possible_orders(vma, vma->vm_flags, tva_flags);
>
> @@ -2691,8 +2696,7 @@ static enum scan_result collapse_scan_file(struct mm_struct *mm,
>
> present = 0;
> swap = 0;
> - memset(cc->node_load, 0, sizeof(cc->node_load));
> - nodes_clear(cc->alloc_nmask);
> + collapse_control_init_scan(cc);
> rcu_read_lock();
> xas_for_each(&xas, folio, start + HPAGE_PMD_NR - 1) {
> if (xas_retry(&xas, folio))
> --
> 2.54.0
>
Cheers, Lorenzo