* [PATCH v2] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
@ 2026-11-25 7:39 Hui Zhu
2026-11-25 8:23 ` Barry Song
0 siblings, 1 reply; 2+ messages in thread
From: Hui Zhu @ 2026-11-25 7:39 UTC (permalink / raw)
To: Andrew Morton, Kairui Song, Qi Zheng, Shakeel Butt, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
Johannes Weiner, David Hildenbrand, Michal Hocko,
Lorenzo Stoakes, Harry Yoo, linux-mm, linux-kernel
Cc: Hui Zhu, stable
From: Hui Zhu <zhuhui@kylinos.cn>
try_to_inc_max_seq_nowalk() advances mm_state->seq without walking the
mm_list, but unlike iterate_mm_list_nowalk() it leaves head and tail
alone. If it races with an ongoing page table walk, the cursor is left in
the middle of the fifo.
The next walker reads that as "this generation already started": it skips
reset_bloom_filter() and resumes after the cursor. The mm it visits are
the ones the aborted walk never reached, so they have no bits in the
filter being read and walk_pmd_range() descends into none of their PMDs.
try_to_shrink_lruvec() ignores the failed try_to_inc_max_seq() and keeps
evicting, so those hot folios are not promoted and refault in the parent
memcg, until head wraps around a generation later.
Reset head and tail with the seq increment, as iterate_mm_list_nowalk()
does. It is safe: get_next_mm() holds an mmgrab() reference and a
concurrent walker bails out at "walk->seq <= mm_state->seq" before
touching head again.
Only reachable from memcg_reparent_objcgs() -> max_lru_gen_memcg(); not a
memory safety issue, since lru_gen_del_mm() repoints head and tail under
mm_list->lock.
Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios")
Cc: stable@vger.kernel.org
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
Reviewed-by: Baoquan He <baoquan.he@linux.dev>
---
Changelog:
v2:
Drop the helper and keep the fix open-coded (Baoquan He).
mm/vmscan.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 6a1af9b92349..3601e58f2a69 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4694,6 +4694,8 @@ static void try_to_inc_max_seq_nowalk(struct mem_cgroup *memcg,
spin_lock(&mm_list->lock);
VM_WARN_ON_ONCE(mm_state->seq + 1 < max_seq);
if (max_seq > mm_state->seq) {
+ mm_state->head = NULL;
+ mm_state->tail = NULL;
WRITE_ONCE(mm_state->seq, mm_state->seq + 1);
success = true;
}
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
2026-11-25 7:39 [PATCH v2] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Hui Zhu
@ 2026-11-25 8:23 ` Barry Song
0 siblings, 0 replies; 2+ messages in thread
From: Barry Song @ 2026-11-25 8:23 UTC (permalink / raw)
To: Hui Zhu
Cc: Andrew Morton, Kairui Song, Qi Zheng, Shakeel Butt,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
Johannes Weiner, David Hildenbrand, Michal Hocko,
Lorenzo Stoakes, Harry Yoo, linux-mm, linux-kernel, Hui Zhu,
stable
On Wed, Nov 25, 2026 at 3:39 PM Hui Zhu <hui.zhu@linux.dev> wrote:
>
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> try_to_inc_max_seq_nowalk() advances mm_state->seq without walking the
> mm_list, but unlike iterate_mm_list_nowalk() it leaves head and tail
> alone. If it races with an ongoing page table walk, the cursor is left in
> the middle of the fifo.
>
> The next walker reads that as "this generation already started": it skips
> reset_bloom_filter() and resumes after the cursor. The mm it visits are
> the ones the aborted walk never reached, so they have no bits in the
> filter being read and walk_pmd_range() descends into none of their PMDs.
> try_to_shrink_lruvec() ignores the failed try_to_inc_max_seq() and keeps
> evicting, so those hot folios are not promoted and refault in the parent
> memcg, until head wraps around a generation later.
I'm not sure I follow this part. Even if the page table walk misses
those hot folios, we can still detect references through rmap during
eviction, can't we?
We also have lru_gen_look_around() on the rmap path.
So missing those folios during aging doesn't necessarily mean they
will be reclaimed and subsequently refault.
>
> Reset head and tail with the seq increment, as iterate_mm_list_nowalk()
> does. It is safe: get_next_mm() holds an mmgrab() reference and a
> concurrent walker bails out at "walk->seq <= mm_state->seq" before
> touching head again.
>
> Only reachable from memcg_reparent_objcgs() -> max_lru_gen_memcg(); not a
> memory safety issue, since lru_gen_del_mm() repoints head and tail under
> mm_list->lock.
>
> Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> Reviewed-by: Baoquan He <baoquan.he@linux.dev>
I'm fine with the fix, but I'm not entirely convinced that everything
in the changelog is accurate. :-)
> ---
> Changelog:
> v2:
> Drop the helper and keep the fix open-coded (Baoquan He).
>
> mm/vmscan.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6a1af9b92349..3601e58f2a69 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -4694,6 +4694,8 @@ static void try_to_inc_max_seq_nowalk(struct mem_cgroup *memcg,
> spin_lock(&mm_list->lock);
> VM_WARN_ON_ONCE(mm_state->seq + 1 < max_seq);
> if (max_seq > mm_state->seq) {
> + mm_state->head = NULL;
> + mm_state->tail = NULL;
> WRITE_ONCE(mm_state->seq, mm_state->seq + 1);
> success = true;
> }
> --
> 2.53.0
>
>
Thanks,
Barry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 8:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 7:39 [PATCH v2] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Hui Zhu
2026-11-25 8:23 ` Barry Song
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®