Re: [PATCH mm-stable] mm/khugepaged: avoid unnecessary checking for swap entries when collapsing a mTHP

From: Pedro Demarchi Gomes

Date: Mon Aug 31 2026 - 16:39:17 EST


On Thu, Aug 27, 2026 at 03:07:10PM +0100, Kiryl Shutsemau wrote:
> On Thu, Aug 27, 2026 at 08:11:51PM +0800, Lance Yang wrote:
> > For the candidate above, the loop only reads its PTEs and returns
> > SCAN_SUCCEED. Pedro's bitmap lets mthp_collapse() determine that upfront
> > and skip the walk.
> >
> > Emm ... as I asked before[1], any numbers showing how much the extra scan
> > costs?
>
> With the win being only some scan cost, I don't think it is going to be
> measurable.
>
> It can open a path to future work. For example, we could find fully
> populated mTHP windows in a PMD that is not eligible for collapse
> because unmapped > max_ptes_swap. Right now we just give up on the whole
> PMD in such cases.
>
> But there are more wins to gain there. Just saying :P

Hi Kiryl,

I devised a patch based on your proposed future work idea. If you think it
makes sense, I can send it to the mailing list with a Suggested-by: tag.

Thanks!