From: Baoquan He <baoquan.he@linux.dev>
To: Ridong Chen <ridong.chen@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Barry Song <baohua@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
"open list:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)"
<linux-mm@kvack.org>, Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH v2 1/3] mm/mglru: factor out lru_gen_seq_nr_pages()
Date: Tue, 15 Sep 2026 14:32:46 +0800 [thread overview]
Message-ID: <aqjmjguIzTssbpUt@fedora> (raw)
In-Reply-To: <20260911102939.2485750-2-ridong.chen@linux.dev>
On 09/11/26 at 06:29pm, Ridong Chen wrote:
> From: Ridong Chen <chenridong@xiaomi.com>
>
> Both lruvec_evictable_size() and the debugfs lru_gen_seq_show() compute
> the number of pages in a generation the same way: sum lrugen->nr_pages
> over all zones for a given (gen, type) and clamp each term to >= 0.
>
> Factor that out into lru_gen_seq_nr_pages() so the open-coded zone loop
> lives in one place. No functional change.
>
> A follow-up patch adds a tracepoint that needs the same per-generation
> page count, and will reuse this helper instead of open-coding it again.
>
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
> ---
> mm/vmscan.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 40d3f1b48a74..2554a6513aa8 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2813,6 +2813,18 @@ static int get_nr_gens(struct lruvec *lruvec, int type)
> return lruvec->lrugen.max_seq - lruvec->lrugen.min_seq[type] + 1;
> }
>
> +/* the number of pages in a generation, summed over zones and clamped to >= 0 */
^
The first letter should be capitalized?
Other than the nit, LGTM,
Reviewed-by: Baoquan He <baoquan.he@linux.dev>
> +static unsigned long lru_gen_seq_nr_pages(struct lru_gen_folio *lrugen, int gen, int type)
> +{
> + int zone;
> + unsigned long size = 0;
> +
> + for (zone = 0; zone < MAX_NR_ZONES; zone++)
> + size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
> +
> + return size;
> +}
> +
> static bool __maybe_unused seq_is_valid(struct lruvec *lruvec)
> {
> int type;
> @@ -4239,7 +4251,7 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control
>
> static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness)
> {
> - int gen, type, zone;
> + int gen, type;
> unsigned long seq, total = 0;
> struct lru_gen_folio *lrugen = &lruvec->lrugen;
> DEFINE_MAX_SEQ(lruvec);
> @@ -4248,8 +4260,7 @@ static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness
> for_each_evictable_type(type, swappiness) {
> for (seq = min_seq[type]; seq <= max_seq; seq++) {
> gen = lru_gen_from_seq(seq);
> - for (zone = 0; zone < MAX_NR_ZONES; zone++)
> - total += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
> + total += lru_gen_seq_nr_pages(lrugen, gen, type);
> }
> }
>
> @@ -5738,19 +5749,16 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)
> seq = 0;
>
> for (; seq <= max_seq; seq++) {
> - int type, zone;
> + int type;
> int gen = lru_gen_from_seq(seq);
> unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]);
>
> seq_printf(m, " %10lu %10u", seq, jiffies_to_msecs(jiffies - birth));
>
> for (type = 0; type < ANON_AND_FILE; type++) {
> - unsigned long size = 0;
> + unsigned long size = lru_gen_seq_nr_pages(lrugen, gen, type);
> char mark = full && seq < min_seq[type] ? 'x' : ' ';
>
> - for (zone = 0; zone < MAX_NR_ZONES; zone++)
> - size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
> -
> seq_printf(m, " %10lu%c", size, mark);
> }
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-09-15 6:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 10:29 [PATCH v2 0/3] mm/mglru: add tracepoints for scan and aging paths Ridong Chen
2026-09-11 10:29 ` [PATCH v2 1/3] mm/mglru: factor out lru_gen_seq_nr_pages() Ridong Chen
2026-09-14 7:09 ` Baolin Wang
2026-09-15 6:32 ` Baoquan He [this message]
2026-09-11 10:29 ` [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios() Ridong Chen
2026-09-14 7:47 ` Baolin Wang
2026-09-14 9:04 ` Ridong Chen
2026-09-15 11:14 ` Baoquan He
2026-09-15 12:17 ` Ridong Chen
2026-09-16 2:14 ` Baoquan He
2026-09-16 12:17 ` Ridong Chen
2026-09-11 10:29 ` [PATCH v2 3/3] mm/mglru: add tracepoint for inc_max_seq() Ridong Chen
2026-09-14 7:38 ` Baolin Wang
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=aqjmjguIzTssbpUt@fedora \
--to=baoquan.he@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chenridong@xiaomi.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@google.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 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®