From: Ridong Chen <ridong.chen@linux.dev>
To: kasong@tencent.com, linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Barry Song <baohua@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Muchun Song <muchun.song@linux.dev>, Chris Li <chrisl@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>, Yu Zhao <yuzhao@google.com>,
Zi Yan <ziy@nvidia.com>, Qi Zheng <qi.zheng@linux.dev>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Kairui Song <ryncsn@gmail.com>
Subject: Re: [PATCH 4/7] mm/mglru: move max_seq read into walk_update_folio
Date: Thu, 20 Aug 2026 10:13:36 +0800 [thread overview]
Message-ID: <e25532ec-04c8-4d88-974d-17478da87a3b@linux.dev> (raw)
In-Reply-To: <20260818-mglru-flags-cleanup-v1-4-8dbbdac0d28c@tencent.com>
On 8/18/2026 1:38 PM, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@tencent.com>
>
> walk_pte_range(), walk_pmd_range_locked(), and lru_gen_look_around()
> each read lrugen->max_seq to compute the target generation used by
> walk_update_folio(), then pass it as a parameter. Move the read into
> walk_update_folio() itself so the callers no longer need to compute
> or pass the value.
>
> The max_seq read now happens once per folio update rather than once
> per walk range, so folios always get promoted to the current youngest
> generation.
>
> Signed-off-by: Kairui Song <kasong@tencent.com>
> Reviewed-by: Baoquan He <baoquan.he@linux.dev>
> ---
> mm/vmscan.c | 29 ++++++++++++-----------------
> 1 file changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 080132997d87..a819be6b7ae9 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3517,13 +3517,15 @@ static bool suitable_to_scan(int total, int young)
> }
>
> static void walk_update_folio(struct lru_gen_mm_walk *walk, struct vm_area_struct *vma,
> - struct folio *folio, int new_gen, bool dirty)
> + struct lruvec *lruvec, struct folio *folio, bool dirty)
> {
> - int old_gen;
> + int new_gen, old_gen;
>
> if (!folio)
> return;
>
> + new_gen = lru_gen_from_seq(READ_ONCE(lruvec->lrugen.max_seq));
> +
> if (dirty && !folio_test_dirty(folio) &&
> !(folio_test_anon(folio) && folio_test_swapbacked(folio) &&
> !folio_test_swapcache(folio)))
> @@ -3554,8 +3556,6 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
> struct lru_gen_mm_walk *walk = args->private;
> struct mem_cgroup *memcg = lruvec_memcg(walk->lruvec);
> struct pglist_data *pgdat = lruvec_pgdat(walk->lruvec);
> - DEFINE_MAX_SEQ(walk->lruvec);
> - int gen = lru_gen_from_seq(max_seq);
> unsigned int nr;
> pmd_t pmdval;
>
> @@ -3606,7 +3606,7 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
> continue;
>
> if (last != folio) {
> - walk_update_folio(walk, args->vma, last, gen, dirty);
> + walk_update_folio(walk, args->vma, walk->lruvec, last, dirty);
>
> last = folio;
> dirty = false;
> @@ -3619,7 +3619,7 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
> walk->mm_stats[MM_LEAF_YOUNG] += nr;
> }
>
> - walk_update_folio(walk, args->vma, last, gen, dirty);
> + walk_update_folio(walk, args->vma, walk->lruvec, last, dirty);
> last = NULL;
>
> if (i < PTRS_PER_PTE && get_next_vma(PMD_MASK, PAGE_SIZE, args, &start, &end))
> @@ -3642,8 +3642,6 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
> struct lru_gen_mm_walk *walk = args->private;
> struct mem_cgroup *memcg = lruvec_memcg(walk->lruvec);
> struct pglist_data *pgdat = lruvec_pgdat(walk->lruvec);
> - DEFINE_MAX_SEQ(walk->lruvec);
> - int gen = lru_gen_from_seq(max_seq);
>
> VM_WARN_ON_ONCE(pud_leaf(*pud));
>
> @@ -3697,7 +3695,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
> goto next;
>
> if (last != folio) {
> - walk_update_folio(walk, vma, last, gen, dirty);
> + walk_update_folio(walk, vma, walk->lruvec, last, dirty);
>
> last = folio;
> dirty = false;
> @@ -3711,7 +3709,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
> i = i > MIN_LRU_BATCH ? 0 : find_next_bit(bitmap, MIN_LRU_BATCH, i) + 1;
> } while (i <= MIN_LRU_BATCH);
>
> - walk_update_folio(walk, vma, last, gen, dirty);
> + walk_update_folio(walk, vma, walk->lruvec, last, dirty);
>
> lazy_mmu_mode_disable();
> spin_unlock(ptl);
> @@ -4275,8 +4273,6 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
> struct pglist_data *pgdat = folio_pgdat(folio);
> struct lruvec *lruvec;
> struct lru_gen_mm_state *mm_state;
> - unsigned long max_seq;
> - int gen;
>
> lockdep_assert_held(pvmw->ptl);
> VM_WARN_ON_ONCE_FOLIO(folio_test_lru(folio), folio);
> @@ -4313,8 +4309,6 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
>
> memcg = get_mem_cgroup_from_folio(folio);
> lruvec = mem_cgroup_lruvec(memcg, pgdat);
> - max_seq = READ_ONCE((lruvec)->lrugen.max_seq);
> - gen = lru_gen_from_seq(max_seq);
> mm_state = get_mm_state(lruvec);
>
> lazy_mmu_mode_enable();
> @@ -4346,7 +4340,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
> continue;
>
> if (last != folio) {
> - walk_update_folio(walk, vma, last, gen, dirty);
> + walk_update_folio(walk, vma, lruvec, last, dirty);
>
> last = folio;
> dirty = false;
> @@ -4358,13 +4352,14 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
> young += nr;
> }
>
> - walk_update_folio(walk, vma, last, gen, dirty);
> + walk_update_folio(walk, vma, lruvec, last, dirty);
>
> lazy_mmu_mode_disable();
>
> /* feedback from rmap walkers to page table walkers */
> if (mm_state && suitable_to_scan(i, young))
> - update_bloom_filter(mm_state, max_seq, pvmw->pmd);
> + update_bloom_filter(mm_state, READ_ONCE(lruvec->lrugen.max_seq),
> + pvmw->pmd);
>
> mem_cgroup_put(memcg);
>
>
LGTM.
Reviewed-by: Ridong Chen <ridong.chen@linux.dev>
--
Best regards
Ridong
next prev parent reply other threads:[~2026-08-20 2:13 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 5:38 [PATCH 0/7] mm/mglru: clean up folio counters and flag usage Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-18 5:38 ` [PATCH 1/7] mm/memcontrol: make lru_zone_size atomic and simplify sanity check Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 2:05 ` Ridong Chen
2026-08-18 5:38 ` [PATCH 2/7] mm/mglru: introduce helpers for manipulating gen and refs flags Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 9:03 ` Baolin Wang
2026-08-19 9:37 ` Kairui Song
2026-08-19 9:46 ` Baolin Wang
2026-08-19 9:49 ` Kairui Song
2026-08-20 1:43 ` Ridong Chen
2026-08-20 2:04 ` Ridong Chen
2026-08-20 2:05 ` Ridong Chen
2026-08-18 5:38 ` [PATCH 3/7] mm/migrate: copy the referenced state via folio_migrate_refs() Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 10:12 ` Baoquan He
2026-08-18 5:38 ` [PATCH 4/7] mm/mglru: move max_seq read into walk_update_folio Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 9:18 ` Baolin Wang
2026-08-20 2:13 ` Ridong Chen [this message]
2026-08-18 5:38 ` [PATCH 5/7] mm/mglru: use explicit tier range in read_ctrl_pos() Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 9:25 ` Baolin Wang
2026-08-19 10:16 ` Baoquan He
2026-08-19 21:24 ` Barry Song
2026-08-20 2:33 ` Ridong Chen
2026-08-20 3:22 ` Kairui Song
2026-08-18 5:38 ` [PATCH 6/7] mm/mglru: fix potential generation folio number leak Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-20 1:52 ` Baolin Wang
2026-08-20 3:45 ` Kairui Song
2026-08-18 5:38 ` [PATCH 7/7] mm/mglru: improve code readability and harden folio_inc_gen Kairui Song via B4 Relay
2026-08-18 5:38 ` Kairui Song
2026-08-19 21:30 ` Barry Song
2026-08-20 0:53 ` Baoquan He
2026-08-20 0:57 ` Baoquan He
2026-08-20 1:02 ` Baolin Wang
2026-08-20 2:11 ` Kairui Song
2026-08-20 2:27 ` Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e25532ec-04c8-4d88-974d-17478da87a3b@linux.dev \
--to=ridong.chen@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=qi.zheng@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.