From: Kairui Song <ryncsn@gmail.com>
To: Barry Song <baohua@kernel.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>,
Qi Zheng <zhengqi.arch@bytedance.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
David Stevens <stevensd@google.com>,
Chen Ridong <chenridong@huaweicloud.com>,
Leno Hou <lenohou@gmail.com>, Yafang Shao <laoar.shao@gmail.com>,
Yu Zhao <yuzhao@google.com>,
Zicheng Wang <wangzicheng@honor.com>,
Kalesh Singh <kaleshsingh@google.com>,
Suren Baghdasaryan <surenb@google.com>,
Chris Li <chrisl@kernel.org>, Vernon Yang <vernon2gm@gmail.com>,
linux-kernel@vger.kernel.org, Qi Zheng <qi.zheng@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>
Subject: Re: [PATCH v5 05/14] mm/mglru: scan and count the exact number of folios
Date: Fri, 17 Apr 2026 01:39:48 +0800 [thread overview]
Message-ID: <CAMgjq7D+ni+t-bLCeEmOHwt8s5+4iszCMdzzek+P-DuZYemcVQ@mail.gmail.com> (raw)
In-Reply-To: <CAGsJ_4yH6v58oD8K56hMPp5bTYGC1Bfo3XSAViW9gWeSwLXgDw@mail.gmail.com>
On Thu, Apr 16, 2026 at 3:03 PM Barry Song <baohua@kernel.org> wrote:
>
> On Mon, Apr 13, 2026 at 12:48 AM Kairui Song via B4 Relay
> <devnull+kasong.tencent.com@kernel.org> wrote:
> >
> > static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swappiness)
> > @@ -4686,7 +4681,7 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca
> >
> > static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
> > struct scan_control *sc, int type, int tier,
> > - struct list_head *list)
> > + struct list_head *list, int *isolatedp)
> > {
> > int i;
> > int gen;
> > @@ -4756,11 +4751,9 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
> > type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
> > if (type == LRU_GEN_FILE)
> > sc->nr.file_taken += isolated;
> > - /*
> > - * There might not be eligible folios due to reclaim_idx. Check the
> > - * remaining to prevent livelock if it's not making progress.
> > - */
> > - return isolated || !remaining ? scanned : 0;
> > +
> > + *isolatedp = isolated;
> > + return scanned;
> > }
> >
> > static int get_tier_idx(struct lruvec *lruvec, int type)
> > @@ -4804,33 +4797,36 @@ static int get_type_to_scan(struct lruvec *lruvec, int swappiness)
> >
> > static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
> > struct scan_control *sc, int swappiness,
> > - int *type_scanned, struct list_head *list)
> > + struct list_head *list, int *isolated,
> > + int *isolate_type, int *isolate_scanned)
> > {
> > int i;
> > + int scanned = 0;
>
> I would prefer to rename this to total_scanned.
Good suggestion.
>
> > int type = get_type_to_scan(lruvec, swappiness);
> >
> > for_each_evictable_type(i, swappiness) {
> > - int scanned;
> > + int type_scan;
>
> And then we keep this as "scanned".
>
> > int tier = get_tier_idx(lruvec, type);
> >
> > - *type_scanned = type;
> > + type_scan = scan_folios(nr_to_scan, lruvec, sc,
> > + type, tier, list, isolated);
> >
> > - scanned = scan_folios(nr_to_scan, lruvec, sc, type, tier, list);
> > - if (scanned)
> > - return scanned;
> > + scanned += type_scan;
> > + if (*isolated) {
> > + *isolate_type = type;
> > + *isolate_scanned = type_scan;
> > + break;
> > + }
> >
> > type = !type;
> > }
> >
> > - return 0;
> > + return scanned;
>
> Then
> return total_scanned;
>
> > }
> >
> > static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
> > struct scan_control *sc, int swappiness)
> > {
> > - int type;
> > - int scanned;
> > - int reclaimed;
> > LIST_HEAD(list);
> > LIST_HEAD(clean);
> > struct folio *folio;
> > @@ -4838,19 +4834,23 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
> > enum node_stat_item item;
> > struct reclaim_stat stat;
> > struct lru_gen_mm_walk *walk;
> > + int scanned, reclaimed;
> > + int isolated = 0, type, type_scanned;
> > bool skip_retry = false;
> > - struct lru_gen_folio *lrugen = &lruvec->lrugen;
> > struct mem_cgroup *memcg = lruvec_memcg(lruvec);
> > struct pglist_data *pgdat = lruvec_pgdat(lruvec);
> >
> > lruvec_lock_irq(lruvec);
> >
> > - scanned = isolate_folios(nr_to_scan, lruvec, sc, swappiness, &type, &list);
> > + /* In case folio deletion left empty old gens, flush them */
> > + try_to_inc_min_seq(lruvec, swappiness);
> >
> > - scanned += try_to_inc_min_seq(lruvec, swappiness);
> > + scanned = isolate_folios(nr_to_scan, lruvec, sc, swappiness,
> > + &list, &isolated, &type, &type_scanned);
> >
> > - if (evictable_min_seq(lrugen->min_seq, swappiness) + MIN_NR_GENS > lrugen->max_seq)
> > - scanned = 0;
> > + /* Isolation might create empty gen, flush them */
> > + if (scanned)
>
> scanned is not equal to isolated, right?
> Somehow, I feel the comment does not match the if (scanned).
> I assume sort_folio() could also create empty gen?
Yeah, you are right, it should be isolated. Usually one batch scan
always isolates a few folios so I didn't observe much difference in
testing, but I should definitely fix this. Thanks!
next prev parent reply other threads:[~2026-04-16 17:40 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-12 16:48 [PATCH v5 00/14] mm/mglru: improve reclaim loop and dirty folio handling Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 01/14] mm/mglru: consolidate common code for retrieving evictable size Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 02/14] mm/mglru: rename variables related to aging and rotation Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 03/14] mm/mglru: relocate the LRU scan batch limit to callers Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 04/14] mm/mglru: restructure the reclaim loop Kairui Song via B4 Relay
2026-04-16 6:33 ` Barry Song
2026-04-16 18:47 ` Kairui Song
2026-04-12 16:48 ` [PATCH v5 05/14] mm/mglru: scan and count the exact number of folios Kairui Song via B4 Relay
2026-04-15 3:16 ` Baolin Wang
2026-04-16 7:01 ` Barry Song
2026-04-16 17:39 ` Kairui Song [this message]
2026-04-12 16:48 ` [PATCH v5 06/14] mm/mglru: use a smaller batch for reclaim Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 07/14] mm/mglru: don't abort scan immediately right after aging Kairui Song via B4 Relay
2026-04-16 7:32 ` Barry Song
2026-04-12 16:48 ` [PATCH v5 08/14] mm/mglru: remove redundant swap constrained check upon isolation Kairui Song via B4 Relay
2026-04-14 7:43 ` Chen Ridong
2026-04-15 3:19 ` Baolin Wang
2026-04-16 9:05 ` Barry Song
2026-04-12 16:48 ` [PATCH v5 09/14] mm/mglru: use the common routine for dirty/writeback reactivation Kairui Song via B4 Relay
2026-04-15 3:30 ` Baolin Wang
2026-04-16 9:18 ` Barry Song
2026-04-12 16:48 ` [PATCH v5 10/14] mm/mglru: simplify and improve dirty writeback handling Kairui Song via B4 Relay
2026-04-15 3:25 ` Baolin Wang
2026-04-12 16:48 ` [PATCH v5 11/14] mm/mglru: remove no longer used reclaim argument for folio protection Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 12/14] mm/vmscan: remove sc->file_taken Kairui Song via B4 Relay
2026-04-14 7:46 ` Chen Ridong
2026-04-12 16:48 ` [PATCH v5 13/14] mm/vmscan: remove sc->unqueued_dirty Kairui Song via B4 Relay
2026-04-14 7:46 ` Chen Ridong
2026-04-12 16:48 ` [PATCH v5 14/14] mm/vmscan: unify writeback reclaim statistic and throttling Kairui Song via B4 Relay
2026-04-17 2:51 ` [PATCH v5 00/14] mm/mglru: improve reclaim loop and dirty folio handling wangxinyu19
2026-04-17 2:55 ` wangxinyu19
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=CAMgjq7D+ni+t-bLCeEmOHwt8s5+4iszCMdzzek+P-DuZYemcVQ@mail.gmail.com \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chenridong@huaweicloud.com \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kaleshsingh@google.com \
--cc=laoar.shao@gmail.com \
--cc=lenohou@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stevensd@google.com \
--cc=surenb@google.com \
--cc=vernon2gm@gmail.com \
--cc=wangzicheng@honor.com \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=yuzhao@google.com \
--cc=zhengqi.arch@bytedance.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