Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Muzafarov <maxmuzaf@gmail.com>
To: linux-mm@kvack.org, Kairui Song <ryncsn@gmail.com>,
	Tianyi Chen <hi@tychen.cc>
Cc: Maxim Muzafarov <maxmuzaf@gmail.com>,
	Kairui Song <kasong@tencent.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	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>,
	Baoquan He <baoquan.he@linux.dev>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Yu Zhao <yuzhao@google.com>, Johannes Weiner <hannes@cmpxchg.org>,
	David Hildenbrand <david@kernel.org>,
	Michal Hocko <mhocko@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 0/1] mm/mglru: MADV_RANDOM page cache never ages and thrashes the oldest generation
Date: Sat, 21 Nov 2026 21:59:52 +0100	[thread overview]
Message-ID: <20261121205953.30737-1-maxmuzaf@gmail.com> (raw)
In-Reply-To: <20261119082441.196139-1-hi@tychen.cc>

Hi Tianyi, Kairui,

Sorry for the late reply. There was a lot of new information for me
to digest.

I've checked the reproducer you provided. It tests a slightly
different scenario from the one I mentioned in my first email.
However, I managed to adapt it [1] to my case and tested everything
with the same setup (x86-64 VM), and I also reproduced your results.

The key difference [1] is that I added two new knobs:
- SCAN_PASSES (default 1, your value), how many times each scan page
  is touched
- SCAN_MB (default 96, your value), the cold scan size in MiB

This is important because 300 MiB scan forces reclaim to reach the
pages during the first pass, which clears their accessed bits and
evicts some of them. The second pass then gives the scan pages a
second visible access. The reproducer from my first email also reads
the cold data twice (--loops=2).

So the idea is to get the cold data promoted to newer generations
and watch whether the workload recovers while the oldest generation
is thrashing.

With a 300 MiB scan and 2 passes, neither MGLRU nor MGLRU-FG5 can
recover. FG5 handles the 96 MiB scans and the 300 MiB single pass
scan.

The Patch
---------

Kairui,

On Mon, Nov 02, 2026 at 02:02:33AM +0800, Kairui Song wrote:
> This code snip:
> + /* Set refault as active. */
> + if (distance < total / 2) {
> + folio_set_active(folio);
[...]
> That way, even a random folio will be put to the head directly instead
> of keep thrasing on tail. And placing on head or newer gen will
> trigger aging.

As I understand it, the refault distance series will break this loop
on tail. However, will the loop survive when the hot random set
is much bigger than half of memory? E.g. when its refault
distances exceed total / 2 and refaults land in the oldest
generation again? Should we in this case use the aging logic from
this patch as a fallback?

Anyway I'd be happy to test the refault distance implementation as
part of this work when it's ready.

I also rebased the patch onto mm-new (25fee5b1762b) [2] and on top
of the MGLRU-FG5 branch [3]. The patch applies unchanged to both.

Please, let me know if I need to send v2 of the patch to this thread.

Setup
-----

The same .config, and a fresh 4 vCPU x86-64 KVM guest per kernel.
OpenSearch and a cold mmap scan (96/300 MiB, one/two passes)
share a 1 GiB memcg with no swap. Median of 5 seeds,
lru_gen enabled=7 vs 0.

mmbase   7.4.0-rc1-mmbase+, mm-new (25fee5b1762b)
fg5      7.4.0-rc1-fg5+, 25fee5b1762b with 17 MGLRU-FG5 patches [4]
age2     7.4.0-rc1-age2+, mmbase with the patch on top
fg5age   7.4.0-rc1-fg5age+, fg5 with the patch on top

Results
-------

First, the good news. I can confirm that FG5 keeps .vec in memory
with a 96 MiB scan and MGLRU doesn't. With passes=2 it also
looks fine.

My guess is that at 96 MiB reclaim never reaches the scan pages
between the two passes, so their accessed bits stay set and the
second pass is not seen as a new access? I haven't confirmed this.

96 MiB scan:

kernel passes LRU       p50   p99 refaults .vec scan .vec late
fg5         1 MGLRU     1.1   2.6        2     117.2     117.2
fg5         1 classic   1.1   2.4        7     117.2     117.2
fg5         2 MGLRU     1.0   2.1        1     117.2     117.2
fg5         2 classic   1.0   2.0        0     117.2     117.2
mmbase      1 MGLRU    15.4  69.0   510691      75.3     102.2
mmbase      1 classic   1.0   2.2        3     117.2     117.2
mmbase      2 MGLRU    16.6  73.4   558370      70.1     100.0
mmbase      2 classic   1.1   2.6        3     117.2     117.2

With a 300 MiB scan, .vec is fully evicted during the scan on every
kernel, so these runs show whether it comes back. With passes=2,
MGLRU-FG5 is NOT able to recover, and this is where the refault
distance implementation should help?

300 MiB scan:

kernel passes LRU       p50   p99 refaults .vec scan .vec late scan late
fg5         1 MGLRU     1.0   2.2      413       0.0     117.2     115.8
fg5         1 classic   1.1   2.4      409       0.0     117.2     104.5
fg5         2 MGLRU   156.1 248.5 12548335       0.0       4.7     292.0
fg5         2 classic   1.1   2.4      686       0.0     117.2     157.5
mmbase      1 MGLRU   146.3 227.4 11247224       0.0      15.0     293.5
mmbase      1 classic   1.0   2.3      409       0.0     117.2     102.0
mmbase      2 MGLRU   150.2 248.9 11643192       0.0      11.3     295.0
mmbase      2 classic   1.1   2.5      547       0.0     117.2     157.2

The patch runs aging when the oldest generation is thrashing, so
min_seq moves again, and both MGLRU and MGLRU-FG5 recover.

300 MiB scan, with the patch:

kernel passes LRU       p50   p99 refaults .vec scan .vec late scan late
age         1 MGLRU     1.1   2.4      571       0.0     117.2     152.8
age         1 classic   1.1   2.3      410       0.0     117.2     106.5
age         2 MGLRU     1.1   2.3      565       0.0     117.2     150.8
age         2 classic   1.1   2.5      866       0.0     117.2     153.8
fg5age      1 MGLRU     1.1   2.3      410       0.0     117.2     112.1
fg5age      1 classic   1.1   2.3      407       0.0     117.2     102.2
fg5age      2 MGLRU     1.1   2.3      430       0.0     117.2     143.0
fg5age      2 classic   1.1   2.6      955       0.0     117.2     154.5

The full results are in the gist [5].

Links
-----

[1] https://gist.github.com/Mmuzaf/263806a5bfae85e75c3331467f85353e/030e6f11096e1980303aa153da0a35b220b4eecc
[2] https://github.com/Mmuzaf/linux/commit/cbd48001580bf1ad8a8767b1afd8e4ad969b3432
[3] https://github.com/Mmuzaf/linux/commit/1e889df5c555e99d437c608e25c22ccb5286ff8f
[4] https://lore.kernel.org/linux-mm/20261120103250.1241429-1-hi@tychen.cc/
[5] https://gist.github.com/Mmuzaf/e87acbefc15acc2cac40c2181de984dd

Thanks,
Maxim Muzafarov


      reply	other threads:[~2026-11-21 21:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 16:04 [RFC PATCH 0/1] mm/mglru: MADV_RANDOM page cache never ages and thrashes the oldest generation Maxim Muzafarov
2026-11-01 16:04 ` [RFC PATCH 1/1] mm/mglru: age when the oldest generation is thrashing Maxim Muzafarov
2026-11-02 16:04   ` sashiko-bot
2026-11-01 18:02 ` [RFC PATCH 0/1] mm/mglru: MADV_RANDOM page cache never ages and thrashes the oldest generation Kairui Song
2026-11-18 17:59 ` Tianyi Chen
2026-11-18 18:45   ` Kairui Song
2026-11-19  8:24     ` Tianyi Chen
2026-11-21 20:59       ` Maxim Muzafarov [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=20261121205953.30737-1-maxmuzaf@gmail.com \
    --to=maxmuzaf@gmail.com \
    --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=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hi@tychen.cc \
    --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=ryncsn@gmail.com \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=yuzhao@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