Re: [PATCH 1/8] mm/khugepaged: refactor per-scan state clearing into collapse_control_init_scan()
From: Nico Pache
Date: Mon Jul 06 2026 - 13:19:06 EST
On Mon, Jul 6, 2026 at 11:08 AM Usama Arif <usama.arif@xxxxxxxxx> wrote:
>
> On Mon, 6 Jul 2026 09:44:48 -0600 Nico Pache <npache@xxxxxxxxxx> 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.
> >
> > Signed-off-by: Nico Pache <npache@xxxxxxxxxx>
> > ---
> > mm/khugepaged.c | 18 +++++++++++++-----
> > 1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > index 617bca76db49..b3985b854e77 100644
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -628,6 +628,17 @@ void __khugepaged_exit(struct mm_struct *mm)
> > }
> > }
> >
> > +/*
> > + * collapse_control_init_scan() - initialize/reset collapse_control variables
> > + * that require being cleared once per-scan.
> > + */
>
> Probably don't need the above comment, but apart from that
It was a last minute addition because I feared a review asking to add
a comment ;P I'm cool with either. The nice part of the comment is
that it clarifies these variables are per-scan.
>
> Acked-by: Usama Arif <usama.arif@xxxxxxxxx>
Thank you :)
>
> > +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,
> > @@ -1616,9 +1627,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);
> >
> > @@ -2686,8 +2695,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
> >
> >
>