Re: [PATCH mm-new v3 1/3] mm/khugepaged: optimize PTE scanning with if-else-if-else-if chain

From: David Hildenbrand

Date: Tue Oct 14 2025 - 08:27:12 EST


On 14.10.25 14:17, Lorenzo Stoakes wrote:
On Wed, Oct 08, 2025 at 12:37:46PM +0800, Lance Yang wrote:
From: Lance Yang <lance.yang@xxxxxxxxx>

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?

I think Lance is trying to unify both scanning functions to look alike, such that when he refactors them out in patch #3 it looks more straight forward.

The missing pte_present() check in hpage_collapse_scan_pmd() is interesting

Likely there is one such check missing there?

--
Cheers

David / dhildenb