From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Lance Yang <lance.yang@linux.dev>
Cc: akpm@linux-foundation.org, david@redhat.com,
Liam.Howlett@oracle.com, baohua@kernel.org,
baolin.wang@linux.alibaba.com, dev.jain@arm.com,
hughd@google.com, ioworker0@gmail.com, kirill@shutemov.name,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
mpenttil@redhat.com, npache@redhat.com, ryan.roberts@arm.com,
ziy@nvidia.com, richard.weiyang@gmail.com
Subject: Re: [PATCH mm-new v3 1/1] mm/khugepaged: abort collapse scan on non-swap entries
Date: Tue, 14 Oct 2025 12:08:23 +0100 [thread overview]
Message-ID: <f33735d3-b38d-4b6a-aeba-b415e6b24ea2@lucifer.local> (raw)
In-Reply-To: <20251008032657.72406-1-lance.yang@linux.dev>
On Wed, Oct 08, 2025 at 11:26:57AM +0800, Lance Yang wrote:
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index abe54f0043c7..bec3e268dc76 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1020,6 +1020,11 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm,
> if (!is_swap_pte(vmf.orig_pte))
> continue;
>
> + if (non_swap_entry(pte_to_swp_entry(vmf.orig_pte))) {
> + result = SCAN_PTE_NON_PRESENT;
> + goto out;
> + }
OK seems in line with what we were discussing before...
> +
> vmf.pte = pte;
> vmf.ptl = ptl;
> ret = do_swap_page(&vmf);
> @@ -1281,7 +1286,23 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> for (addr = start_addr, _pte = pte; _pte < pte + HPAGE_PMD_NR;
> _pte++, addr += PAGE_SIZE) {
> pte_t pteval = ptep_get(_pte);
> - if (is_swap_pte(pteval)) {
> + if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
> + ++none_or_zero;
> + if (!userfaultfd_armed(vma) &&
> + (!cc->is_khugepaged ||
> + none_or_zero <= khugepaged_max_ptes_none)) {
> + continue;
> + } else {
> + result = SCAN_EXCEED_NONE_PTE;
> + count_vm_event(THP_SCAN_EXCEED_NONE_PTE);
> + goto out_unmap;
> + }
> + } else if (!pte_present(pteval)) {
> + if (non_swap_entry(pte_to_swp_entry(pteval))) {
Hm but can't this be pte_protnone() at this stage (or something else)? And then
we're just assuming pte_to_swp_entry() is operating on a swap entry when it in
fact might not be?
Couldn't we end up with false positives here?
> + result = SCAN_PTE_NON_PRESENT;
> + goto out_unmap;
> + }
> +
> ++unmapped;
> if (!cc->is_khugepaged ||
> unmapped <= khugepaged_max_ptes_swap) {
> @@ -1290,7 +1311,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> * enabled swap entries. Please see
> * comment below for pte_uffd_wp().
> */
> - if (pte_swp_uffd_wp_any(pteval)) {
> + if (pte_swp_uffd_wp(pteval)) {
Again you're assuming it's a swap entry but you're not asserting this is a swap
entry in this branch?
Also an aside - I hate, hate, hate how this uffd wp stuff has infiltrated all
kinds of open-coded stuff. It's so gross (not your fault, just a general
comment...)
> result = SCAN_PTE_UFFD_WP;
> goto out_unmap;
> }
> @@ -1301,18 +1322,6 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> goto out_unmap;
> }
> }
> - if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
> - ++none_or_zero;
> - if (!userfaultfd_armed(vma) &&
> - (!cc->is_khugepaged ||
> - none_or_zero <= khugepaged_max_ptes_none)) {
> - continue;
> - } else {
> - result = SCAN_EXCEED_NONE_PTE;
> - count_vm_event(THP_SCAN_EXCEED_NONE_PTE);
> - goto out_unmap;
> - }
> - }
> if (pte_uffd_wp(pteval)) {
> /*
> * Don't collapse the page if any of the small
> --
> 2.49.0
>
Cheers, Lorenzo
next prev parent reply other threads:[~2025-10-14 11:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 3:26 Lance Yang
2025-10-08 8:18 ` David Hildenbrand
2025-10-10 3:44 ` Barry Song
2025-10-10 15:21 ` Zi Yan
2025-10-10 15:34 ` Lance Yang
2025-10-10 15:35 ` Zi Yan
2025-10-14 11:08 ` Lorenzo Stoakes [this message]
2025-10-14 14:26 ` Lance Yang
2025-10-14 14:32 ` David Hildenbrand
2025-10-14 14:37 ` Lance Yang
2025-10-14 14:43 ` Lorenzo Stoakes
2025-10-14 14:39 ` Lorenzo Stoakes
2025-10-14 15:01 ` Lance Yang
2025-10-14 15:12 ` David Hildenbrand
2025-10-14 15:33 ` David Hildenbrand
2025-10-14 16:10 ` Lorenzo Stoakes
2025-10-14 15:41 ` Lorenzo Stoakes
2025-10-14 15:48 ` David Hildenbrand
2025-10-14 15:57 ` Lorenzo Stoakes
2025-10-14 15:11 ` David Hildenbrand
2025-10-14 15:52 ` Lorenzo Stoakes
2025-10-14 16:09 ` Lance Yang
2025-10-14 16:27 ` Lorenzo Stoakes
2025-10-15 1:52 ` Lance Yang
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=f33735d3-b38d-4b6a-aeba-b415e6b24ea2@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=hughd@google.com \
--cc=ioworker0@gmail.com \
--cc=kirill@shutemov.name \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mpenttil@redhat.com \
--cc=npache@redhat.com \
--cc=richard.weiyang@gmail.com \
--cc=ryan.roberts@arm.com \
--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
all inboxes | Powered by JetHome®