Re: [PATCH mm-stable] mm/khugepaged: avoid unnecessary checking for swap entries when collapsing a mTHP
From: Lance Yang
Date: Wed Aug 26 2026 - 00:44:06 EST
On Tue, Aug 25, 2026 at 04:24:33PM -0300, Pedro Demarchi Gomes wrote:
>mthp_collapse() tries to swap in PTEs when collapsing a mTHP if there are any
>swap PTEs in the PMD range, even if none of those swap PTEs are
>actually part of the mTHP's range.
>
>Track swap PTEs in cc->mthp_unmapped_ptes so that mthp_collapse() can
>tell whether the mTHP's own range contains a swap PTE, and skip the
>swapin check when it doesn't.
>
>Signed-off-by: Pedro Demarchi Gomes <pedrodemargomes@xxxxxxxxx>
>---
Yeah, the code itself is fine, but ...
Any numbers showing how much the extra scan costs? khugepaged is already
quite a mess and badly needs some cleanup. TBH, another bitmap + more
bookkeeping doesn't feel worth it unless the win is pretty clear :)
> mm/khugepaged.c | 29 +++++++++++++++++++----------
> 1 file changed, 19 insertions(+), 10 deletions(-)
>
>diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>index 11ff98d55c76..38596172f7dc 100644
>--- a/mm/khugepaged.c
>+++ b/mm/khugepaged.c
>@@ -117,6 +117,9 @@ struct collapse_control {
>
> /* Each bit represents a single occupied (!none/zero) page. */
> DECLARE_BITMAP(mthp_present_ptes, MAX_PTRS_PER_PTE);
>+
>+ /* Each bit represents a single not present and not none/zero pte. */
>+ DECLARE_BITMAP(mthp_unmapped_ptes, MAX_PTRS_PER_PTE);
BTW, the comment is a bit of a mouthful :)
How about "Each bit represents a non-present, non-none PTE." ?
Cheers, Lance
[...]