Re: [PATCH mm-unstable v2 3/5] mm/khugepaged: define COLLAPSE_MAX_PTES_LIMIT as HPAGE_PMD_NR - 1
From: Nico Pache
Date: Tue Mar 03 2026 - 15:31:06 EST
On Fri, Feb 27, 2026 at 1:53 AM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:
>
> On 2/26/26 21:17, Nico Pache wrote:
> > On Thu, Feb 26, 2026 at 2:28 AM David Hildenbrand (Arm)
> > <david@xxxxxxxxxx> wrote:
> >>
> >> On 2/26/26 02:29, Nico Pache wrote:
> >>> The value (HPAGE_PMD_NR - 1) is used often in the khugepaged code to
> >>> signify the limit of the max_ptes_* values. Add a define for this to
> >>> increase code readability and reuse.
> >>>
> >>> Acked-by: Pedro Falcato <pfalcato@xxxxxxx>
> >>> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
> >>> Signed-off-by: Nico Pache <npache@xxxxxxxxxx>
> >>> ---
> >>> mm/khugepaged.c | 9 +++++----
> >>> 1 file changed, 5 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> >>> index 2ef4b972470b..4615f34911d1 100644
> >>> --- a/mm/khugepaged.c
> >>> +++ b/mm/khugepaged.c
> >>> @@ -89,6 +89,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khugepaged_wait);
> >>> *
> >>> * Note that these are only respected if collapse was initiated by khugepaged.
> >>> */
> >>> +#define COLLAPSE_MAX_PTES_LIMIT (HPAGE_PMD_NR - 1)
> >>
> >> I'd call it "KHUGEPAGED_MAX_PTES_LIMIT", because it's khugepaged
> >> specific (no madvise) and matches the parameters.
> >
> > Ok before changing that, note that this is also leveraged in the mTHP
> > set. It's technically used for madvise collapse because when it's not
> > khugepaged we set max_ptes_none= 511.
>
> It's more about disabling that parameter, right?
Yeah, we conditionally set `max_ptes_none = ..._MAX_PTES_LIMIT` for
the case where no pte limit should be enforced.
-- Nico
>
> --
> Cheers,
>
> David
>