Re: [PATCH v6 13/18] mm/khugepaged: convert to LRU refs based operations for MGLRU

From: David Hildenbrand (Arm)

Date: Wed Nov 25 2026 - 05:11:55 EST


On 11/23/26 19:53, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> For MGLRU, PG_referenced is only the lowest bit of the folio LRU refs
> count, so folios with nonzero even refs no longer have the bit set.
> folio_pte_referenced() testing the raw bit misses hot folios at
> refs 2, 4 or 6, under-counting the referenced folios of a candidate range
> and aborting otherwise good collapses with SCAN_LACK_REFERENCED_PAGE.
>
> Test the refs count directly when MGLRU is enabled, mirroring the
> smaps conversion. The classical LRU keeps the plain bit test.
>
> Tested-by: Zhao Zhenzhuo <zhaozhengzhuo@xxxxxxxxxxxxx>
> Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
> Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> ---
> mm/khugepaged.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 2dc4245814df..5e768481ac22 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -579,7 +579,9 @@ static bool folio_pte_referenced(struct folio *folio,
> struct vm_area_struct *vma, unsigned long addr, pte_t pteval)
> {
> /* The folio was referenced previously ... */
> - if (folio_test_young(folio) || folio_test_referenced(folio))
> + if (folio_test_young(folio))
> + return true;
> + if (folio_check_lru_refs(folio))
> return true;

Why separate lines?

Also, is there some way to abstract this that core-mm has to worry less about
the details?

Some helper that tells us using nice semantics exactly what we want to know.

--
Cheers,

David