From: Barry Song <baohua@kernel.org>
To: ridong.chen@linux.dev
Cc: akpm@linux-foundation.org, axelrasmussen@google.com,
baohua@kernel.org, baolin.wang@linux.alibaba.com,
baoquan.he@linux.dev, chenridong@xiaomi.com, david@kernel.org,
hannes@cmpxchg.org, kasong@tencent.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org,
mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev,
weixugc@google.com, yuanchu@google.com
Subject: Re: [PATCH mm-new v9] mm: vmscan: retry folios written back while isolated for traditional LRU
Date: Fri, 18 Sep 2026 17:18:04 +0800 [thread overview]
Message-ID: <20260918091804.69981-1-baohua@kernel.org> (raw)
In-Reply-To: <188835d7-64c1-422a-8a64-6b5e0e960ee1@linux.dev>
On Fri, Sep 18, 2026 at 10:12 AM Ridong Chen <ridong.chen@linux.dev> wrote:
[...]
> >
> > I wouldn't necessarily call it a fix, as keeping the swap cache for
> > those folios can sometimes help with future hits. For example, we may
> > hit those folios again before they are reclaimed. So it's a
> > double-edged sword.
> >
> > That said, the cold/hot inversion is a real problem that we should
> > fix. Ideally, we should find a way to restore the missed
> > `folio_rotate_reclaimable()` behavior, conceptually something like:
> >
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index fde28d0a647d..5ee296474b48 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -891,7 +891,10 @@ long remove_mapping(struct address_space
> > *mapping, struct folio *folio)
> > */
> > void folio_putback_lru(struct folio *folio)
> > {
> > - folio_add_lru(folio);
> > + if (folio_has_been_writtenback_due_reclaim(folio))
> > + folio_add_lru_tail(folio);
> > + else
> > + folio_add_lru(folio);
> > folio_put(folio); /* drop ref from isolate */
> > }
> >
>
> That is a good idea. But I am not sure I can find the correct way to do it. I
> will give it a try and get back to you.
>
Maybe something like the below? I haven't tested it.
diff --git a/mm/vmscan.c b/mm/vmscan.c
index fde28d0a647d..906db7d8c043 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1942,7 +1942,7 @@ static bool too_many_isolated(struct pglist_data *pgdat, int file,
*
* Note: The caller must not hold any lruvec lock.
*/
-static unsigned int move_folios_to_lru(struct list_head *list)
+static unsigned int move_folios_to_lru(struct list_head *list, bool do_rotate)
{
int nr_pages, nr_moved = 0;
struct lruvec *lruvec = NULL;
@@ -1989,7 +1989,16 @@ static unsigned int move_folios_to_lru(struct list_head *list)
continue;
}
- lruvec_add_folio(lruvec, folio);
+ /*
+ * Put folios that may have missed folio_rotate_reclaimable() at the tail
+ * to avoid cold/hot inversion
+ */
+ if (do_rotate && !folio_test_active(folio) && !folio_mapped(folio) &&
+ !folio_test_dirty(folio) && !folio_test_writeback(folio))
+ lruvec_add_folio_tail(lruvec, folio);
+ else
+ lruvec_add_folio(lruvec, folio);
+
nr_pages = folio_nr_pages(folio);
nr_moved += nr_pages;
if (folio_test_active(folio))
@@ -2106,7 +2115,7 @@ static unsigned long shrink_inactive_list(unsigned long nr_to_scan,
nr_reclaimed = shrink_folio_list(&folio_list, pgdat, sc, &stat, false,
lruvec_memcg(lruvec));
- move_folios_to_lru(&folio_list);
+ move_folios_to_lru(&folio_list, true);
mod_lruvec_state(lruvec, PGDEMOTE_KSWAPD + reclaimer_offset(sc),
stat.nr_demoted);
@@ -2217,8 +2226,8 @@ static void shrink_active_list(unsigned long nr_to_scan,
/*
* Move folios back to the lru list.
*/
- nr_activate = move_folios_to_lru(&l_active);
- nr_deactivate = move_folios_to_lru(&l_inactive);
+ nr_activate = move_folios_to_lru(&l_active, false);
+ nr_deactivate = move_folios_to_lru(&l_inactive, false);
count_vm_events(PGDEACTIVATE, nr_deactivate);
count_memcg_events(lruvec_memcg(lruvec), PGDEACTIVATE, nr_deactivate);
@@ -5083,7 +5092,7 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
folio_set_active(folio);
}
- move_folios_to_lru(&list);
+ move_folios_to_lru(&list, true);
walk = current->reclaim_state->mm_walk;
if (walk && walk->batched) {
prev parent reply other threads:[~2026-09-18 9:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 12:38 Ridong Chen
2026-09-16 21:25 ` Barry Song
2026-09-16 21:34 ` Barry Song
2026-09-18 2:12 ` Ridong Chen
2026-09-18 9:18 ` Barry Song [this message]
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=20260918091804.69981-1-baohua@kernel.org \
--to=baohua@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--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=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=ridong.chen@linux.dev \
--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®