Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
@ 2026-11-25 11:35 Hui Zhu
  2026-11-25 20:17 ` + mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch added to mm-new branch Andrew Morton
  2026-11-25 23:44 ` [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Barry Song
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Zhu @ 2026-11-25 11:35 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.
Those mm miss a generation of accessed-bit harvesting, so their aging is
less accurate and hot folios can be under-promoted. Eviction can still
detect their references via rmap and lru_gen_look_around(), so this
weakens aging rather than guaranteeing reclaim and 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>
---
Changelog:
v3:
Reword the impact as weakened aging rather than guaranteed refault,
noting the rmap/lru_gen_look_around() fallback (Barry Song).
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 related	[flat|nested] 3+ messages in thread

* + mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch added to mm-new branch
  2026-11-25 11:35 [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Hui Zhu
@ 2026-11-25 20:17 ` Andrew Morton
  2026-11-25 23:44 ` [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Barry Song
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-25 20:17 UTC (permalink / raw)
  To: mm-commits, yuanchu, weixugc, stable, shakeel.butt, qi.zheng,
	mhocko, ljs, kasong, harry, hannes, david, baoquan.he,
	baolin.wang, baohua, axelrasmussen, zhuhui, akpm


The patch titled
     Subject: mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
has been added to the -mm mm-new branch.  Its filename is
     mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Hui Zhu <zhuhui@kylinos.cn>
Subject: mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
Date: Wed, 25 Nov 2026 19:35:18 +0800

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. 
Those mm miss a generation of accessed-bit harvesting, so their aging is
less accurate and hot folios can be under-promoted.  Eviction can still
detect their references via rmap and lru_gen_look_around(), so this
weakens aging rather than guaranteeing reclaim and 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.

Link: https://patch.msgid.link/20261125113518.1207280-1-hui.zhu@linux.dev
Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios")
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Baoquan He <baoquan.he@linux.dev>
Cc: Kairui Song <kasong@tencent.com>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Harry Yoo <harry@kernel.org>
Cc: <stable@vger.kernel.org>

 mm/vmscan.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/mm/vmscan.c~mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk
+++ a/mm/vmscan.c
@@ -4767,6 +4767,8 @@ static void try_to_inc_max_seq_nowalk(st
 		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;
 		}
_

Patches currently in -mm which might be from zhuhui@kylinos.cn are

mm-vmstat-annotate-data-race-in-zone_page_state_snapshot.patch
mm-compaction-annotate-data-race-for-zone-free_areanr_free.patch
mm-mglru-use-a-smaller-batch-in-fill-drain_evictable.patch
mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk()
  2026-11-25 11:35 [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Hui Zhu
  2026-11-25 20:17 ` + mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch added to mm-new branch Andrew Morton
@ 2026-11-25 23:44 ` Barry Song
  1 sibling, 0 replies; 3+ messages in thread
From: Barry Song @ 2026-11-25 23:44 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 7:35 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.
> Those mm miss a generation of accessed-bit harvesting, so their aging is
> less accurate and hot folios can be under-promoted. Eviction can still
> detect their references via rmap and lru_gen_look_around(), so this
> weakens aging rather than guaranteeing reclaim and 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>
> ---

Reviewed-by: Barry Song <baohua@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25 23:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:35 [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Hui Zhu
2026-11-25 20:17 ` + mm-mglru-reset-the-mm-iteration-cursor-in-try_to_inc_max_seq_nowalk.patch added to mm-new branch Andrew Morton
2026-11-25 23:44 ` [PATCH v3] mm: mglru: reset the mm iteration cursor in try_to_inc_max_seq_nowalk() Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox