From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Lance Yang <lance.yang@linux.dev>
Cc: akpm@linux-foundation.org, david@redhat.com, ziy@nvidia.com,
baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com,
baohua@kernel.org, ioworker0@gmail.com,
richard.weiyang@gmail.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH mm-new v3 1/3] mm/khugepaged: optimize PTE scanning with if-else-if-else-if chain
Date: Tue, 14 Oct 2025 13:17:01 +0100 [thread overview]
Message-ID: <3982686f-908f-4f92-b3ae-e6f141e617ef@lucifer.local> (raw)
In-Reply-To: <20251008043748.45554-2-lance.yang@linux.dev>
On Wed, Oct 08, 2025 at 12:37:46PM +0800, Lance Yang wrote:
> From: Lance Yang <lance.yang@linux.dev>
>
> As pointed out by Dev, the PTE checks for disjoint conditions in the
> scanning loops can be optimized. is_swap_pte, (pte_none && is_zero_pfn),
> and pte_uffd_wp are mutually exclusive.
But you're not using is_swap_pte anywhere :) This comes back to my review
quesiotn on the series this is dependent upon.
>
> This patch refactors the loops in both __collapse_huge_page_isolate() and
> hpage_collapse_scan_pmd() to use a continuous if-else-if-else-if chain
> instead of separate if blocks. While at it, the redundant pte_present()
> check before is_zero_pfn() is also removed.
I mean see review below, I don't see why you're doing this and I am
unconvinced by how redundant that check is.
Also this just feels like it should be part of the series where you change
these? I'm not sure why this is separate?
>
> Also, this is a preparatory step to make it easier to merge the
> almost-duplicated scanning logic in these two functions, as suggested
> by David.
>
> Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
> Reviewed-by: Dev Jain <dev.jain@arm.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Suggested-by: Dev Jain <dev.jain@arm.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> ---
> mm/khugepaged.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index bec3e268dc76..e3e27223137a 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -548,8 +548,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> for (_pte = pte; _pte < pte + HPAGE_PMD_NR;
> _pte++, addr += PAGE_SIZE) {
> pte_t pteval = ptep_get(_pte);
> - if (pte_none(pteval) || (pte_present(pteval) &&
> - is_zero_pfn(pte_pfn(pteval)))) {
> + if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) {
You can have non-pte_none() non-present entries no? Isn't pte_present() a
prerequisite for pfe_pfn() to be valid? If it's a swap entry couldn't you
end up accidentally (unlikely but still) hitting this?
Seems like this is required isn't it? I may be missing something here...
> ++none_or_zero;
> if (!userfaultfd_armed(vma) &&
> (!cc->is_khugepaged ||
> @@ -560,12 +559,10 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
> count_vm_event(THP_SCAN_EXCEED_NONE_PTE);
> goto out;
> }
> - }
> - if (!pte_present(pteval)) {
> + } else if (!pte_present(pteval)) {
This seems pointless, since either the above logic will continue or goto
out right?
> result = SCAN_PTE_NON_PRESENT;
> goto out;
> - }
> - if (pte_uffd_wp(pteval)) {
> + } else if (pte_uffd_wp(pteval)) {
Again, what is the point of an else when the if() branch unconditionally
->out?
> result = SCAN_PTE_UFFD_WP;
> goto out;
> }
> @@ -1321,8 +1318,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> count_vm_event(THP_SCAN_EXCEED_SWAP_PTE);
> goto out_unmap;
> }
> - }
> - if (pte_uffd_wp(pteval)) {
> + } else if (pte_uffd_wp(pteval)) {
Same comment as above, I'm really confused about the purpose of this logic?
> /*
> * Don't collapse the page if any of the small
> * PTEs are armed with uffd write protection.
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-10-14 12:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 4:37 [PATCH mm-new v3 0/3] refactor and merge PTE scanning logic Lance Yang
2025-10-08 4:37 ` [PATCH mm-new v3 1/3] mm/khugepaged: optimize PTE scanning with if-else-if-else-if chain Lance Yang
2025-10-14 12:17 ` Lorenzo Stoakes [this message]
2025-10-14 12:27 ` David Hildenbrand
2025-10-15 4:49 ` Lance Yang
2025-10-15 9:16 ` Lorenzo Stoakes
2025-10-15 9:31 ` Lance Yang
2025-10-08 4:37 ` [PATCH mm-new v3 2/3] mm/khugepaged: use VM_WARN_ON_FOLIO instead of VM_BUG_ON_FOLIO for non-anon folios Lance Yang
2025-10-14 12:25 ` Lorenzo Stoakes
2025-10-08 4:37 ` [PATCH mm-new v3 3/3] mm/khugepaged: merge PTE scanning logic into a new helper Lance Yang
2025-10-09 1:07 ` Andrew Morton
2025-10-09 1:49 ` Lance Yang
2025-10-10 9:10 ` Dev Jain
2025-10-10 10:42 ` Lance Yang
2025-10-10 13:29 ` Wei Yang
2025-10-10 13:55 ` Lance Yang
2025-10-14 12:36 ` Lorenzo Stoakes
2025-10-14 17:41 ` Lorenzo Stoakes
2025-10-15 1:48 ` 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=3982686f-908f-4f92-b3ae-e6f141e617ef@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=ioworker0@gmail.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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