Re: [PATCH 05/12] mm/collapse: state what a collapse may do in the policy
From: Kiryl Shutsemau
Date: Mon Sep 07 2026 - 07:18:55 EST
On Mon, Sep 07, 2026 at 05:05:19PM +0800, Baolin Wang wrote:
> > +/* What a collapse is allowed to do, decided by the caller that asks for it */
> > +struct collapse_policy {
> > + /* Limits, stated per PMD; HPAGE_PMD_NR means "no limit" */
> > + unsigned int max_ptes_none;
> > + unsigned int max_ptes_swap;
> > + unsigned int max_ptes_shared;
> > +
> > + /*
> > + * Hold a sub-PMD window to a stricter rule than a PMD: no swapped-out
> > + * and no shared PTEs at all, and max_ptes_none as
> > + * collapse_max_ptes_none() scales it.
> > + */
> > + bool strict_sub_pmd;
>
> This is a bit confusing to me. Actually, the check for mTHP collapse is
> stricter.
>
> How about naming it 'allow_mthp_collapse'? That way we can keep the most
> original comments for the collapse_max_ptes_xxx() functions, which is
> clearer to me.
>
> If others have a better name, please ignore my comment.
I would rather keep strict_sub_pmd.
Which orders a caller asks for is already decided elsewhere:
collapse_possible_orders() hands khugepaged every anonymous order and
MADV_COLLAPSE the PMD order only, from tva_type.
A flag called allow_mthp_collapse next to that would read as
a second place deciding the same thing, and flipping it would not change
which orders get collapsed. What it does change is how a sub-PMD window
is judged once one is asked for, and it is read at exactly the three
places that judge one.
I will do:
/* Take no swapped-out or shared PTE into a sub-PMD collapse */
bool strict_sub_pmd;
>
> > + /*
> > + * Collapse only where it looks worth doing: require some sign the
> > + * range is in use, and leave clean lazyfree folios for reclaim rather
> > + * than collapsing them into a folio that is not lazyfree.
> > + */
> > + bool skip_lazyfree;
> > + bool require_referenced;
> > +
> > + /*
> > + * Finish the job rather than leaving it half done for a fault to pick
> > + * up: map the PMD over a file collapse before returning, and write
> > + * dirty pages back and retry once instead of refusing them. Both cost
> > + * latency the caller has to be willing to pay.
> > + */
>
> Can you simplify theses comments? I think the 'install_pmd' is easy to
> expalain. :)
Done for v2.
--
Kiryl Shutsemau / Kirill A. Shutemov