From: Lance Yang <lance.yang@linux.dev>
To: pedrodemargomes@gmail.com
Cc: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org,
ziy@nvidia.com, baolin.wang@linux.alibaba.com,
liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com,
dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev,
usama.arif@linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH mm-stable] mm/khugepaged: avoid unnecessary checking for swap entries when collapsing a mTHP
Date: Wed, 26 Aug 2026 12:43:50 +0800 [thread overview]
Message-ID: <20260826044350.24284-1-lance.yang@linux.dev> (raw)
In-Reply-To: <20260825192433.3185880-1-pedrodemargomes@gmail.com>
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@gmail.com>
>---
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
[...]
prev parent reply other threads:[~2026-08-26 4:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 19:24 [PATCH mm-stable] mm/khugepaged: avoid unnecessary checking for swap entries when collapsing a mTHP Pedro Demarchi Gomes
2026-08-26 4:43 ` Lance Yang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260826044350.24284-1-lance.yang@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=pedrodemargomes@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox