* [PATCH] mm/mglru: Fix young counter undercount for large folios
@ 2026-08-12 6:59 Hui Zhu
2026-08-12 10:17 ` Baolin Wang
0 siblings, 1 reply; 2+ messages in thread
From: Hui Zhu @ 2026-08-12 6:59 UTC (permalink / raw)
To: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko,
Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, linux-mm, linux-kernel
Cc: Hui Zhu
From: Hui Zhu <zhuhui@kylinos.cn>
In lru_gen_look_around(), the young counter tracks the number of young
PTEs. The original folio's contribution is represented by the initial
value of young: test_and_clear_young_ptes_notify() is called on it at
function entry, and the function returns early if it is not young. In
the subsequent loop, the original folio is skipped (its accessed bits
were already cleared), so it is not double-counted.
However, young is initialized to 1 regardless of the folio size. When
the original folio is a large folio with nr PTEs, its young count is
underestimated by nr - 1. This inconsistency can cause
suitable_to_scan() to return false, preventing the PMD from being added
to the bloom filter and reducing aging accuracy for mTHP workloads.
Initialize young to nr so the original folio is accounted the same way
as other young folios in the loop (young += nr).
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
---
mm/vmscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index bc324e37c5f1..264017850a55 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4192,7 +4192,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
unsigned long end;
struct lru_gen_mm_walk *walk;
struct folio *last = NULL;
- int young = 1;
+ int young = nr;
pte_t *pte = pvmw->pte;
unsigned long addr = pvmw->address;
struct vm_area_struct *vma = pvmw->vma;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/mglru: Fix young counter undercount for large folios
2026-08-12 6:59 [PATCH] mm/mglru: Fix young counter undercount for large folios Hui Zhu
@ 2026-08-12 10:17 ` Baolin Wang
0 siblings, 0 replies; 2+ messages in thread
From: Baolin Wang @ 2026-08-12 10:17 UTC (permalink / raw)
To: Hui Zhu, Andrew Morton, Johannes Weiner, David Hildenbrand,
Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes,
Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
linux-mm, linux-kernel
Cc: Hui Zhu
On 8/12/26 2:59 PM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> In lru_gen_look_around(), the young counter tracks the number of young
> PTEs. The original folio's contribution is represented by the initial
> value of young: test_and_clear_young_ptes_notify() is called on it at
> function entry, and the function returns early if it is not young. In
> the subsequent loop, the original folio is skipped (its accessed bits
> were already cleared), so it is not double-counted.
>
> However, young is initialized to 1 regardless of the folio size. When
> the original folio is a large folio with nr PTEs, its young count is
> underestimated by nr - 1. This inconsistency can cause
> suitable_to_scan() to return false, preventing the PMD from being added
> to the bloom filter and reducing aging accuracy for mTHP workloads.
>
> Initialize young to nr so the original folio is accounted the same way
> as other young folios in the loop (young += nr).
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
Good catch. Please also add the Fixes tag:
Fixes: 56e5b60b2114 ("mm: support batched checking of the young flag for
MGLRU")
With that,
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> mm/vmscan.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index bc324e37c5f1..264017850a55 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -4192,7 +4192,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
> unsigned long end;
> struct lru_gen_mm_walk *walk;
> struct folio *last = NULL;
> - int young = 1;
> + int young = nr;
> pte_t *pte = pvmw->pte;
> unsigned long addr = pvmw->address;
> struct vm_area_struct *vma = pvmw->vma;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-12 10:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12 6:59 [PATCH] mm/mglru: Fix young counter undercount for large folios Hui Zhu
2026-08-12 10:17 ` Baolin Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox