From: "Barry Song (Xiaomi)" <baohua@kernel.org>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: hui.zhu@linux.dev, axelrasmussen@google.com, baohua@kernel.org,
baolin.wang@linux.alibaba.com, david@kernel.org,
hannes@cmpxchg.org, linux-kernel@vger.kernel.org, ljs@kernel.org,
mhocko@kernel.org, qi.zheng@linux.dev, ryncsn@gmail.com,
shakeel.butt@linux.dev, weixugc@google.com, yuanchu@google.com,
zhuhui@kylinos.cn, baoquan.he@linux.dev,
liuxiang.277@bytedance.com, wangzicheng@honor.com,
lianux.mm@gmail.com, kasong@tencent.com, liam@infradead.org,
surenb@google.com, mhocko@suse.com, rppt@kernel.org,
zhangbo56@xiaomi.com, lyugaofei@xiaomi.com,
ridong.chen@linux.dev, kunwu.chan@gmail.com
Subject: [RFC PATCH v5 00/14] mm: mglru: fix swappiness behavior
Date: Fri, 23 Oct 2026 06:01:49 +0800 [thread overview]
Message-ID: <20261022220203.91911-1-baohua@kernel.org> (raw)
Classic LRU respects swappiness, while MGLRU only partially honors it
when selecting the scan type, resulting in a much smaller overall
impact.
For example, when building the kernel in a memcg limited to 1024 MB
of memory, with swappiness=200, CLRU barely scans or reclaims file
pages, while MGLRU still reclaims a significant number of them.
Similarly, with swappiness=1, MGLRU does not reclaim as many file
pages as expected for such an extreme swappiness value:
pgsteal_file
swappiness CLRU MGLRU(no patches)
1 5,894,538 756,589
36 799,998 497,282
71 548,331 415,612
106 407,012 383,814
141 253,737 354,249
176 189,003 347,805
200 0 346,078
pgsteal_anon
swappiness CLRU MGLRU(no patches)
1 3,962,404 2,768,654
36 2,830,250 2,976,260
71 3,121,386 3,142,954
106 3,521,720 3,382,383
141 3,504,471 2,970,859
176 3,592,335 3,163,130
200 14,095,617 3,209,132
pgscan_file
swappiness CLRU MGLRU(no patches)
1 10,270,808 886,997
36 1,010,341 569,036
71 656,136 490,972
106 460,326 436,042
141 295,184 403,132
176 235,147 390,358
200 0 398,363
pgscan_anon
swappiness CLRU MGLRU(no patches)
1 19,341,957 5,960,884
36 17,530,774 6,394,951
71 18,624,264 6,673,569
106 20,088,558 6,976,364
141 19,686,813 6,206,580
176 20,936,177 6,344,854
200 45,313,873 6,295,581
refault_file
swappiness CLRU MGLRU(no patches)
1 5,795,115 678,254
36 720,877 419,659
71 469,270 338,518
106 331,584 308,983
141 174,509 277,375
176 113,352 272,390
200 0 269,349
refault_anon
swappiness CLRU MGLRU(no patches)
1 738,618 578,308
36 451,410 665,723
71 514,961 657,870
106 633,161 786,893
141 648,640 662,673
176 668,779 708,969
200 4,816,312 672,514
In this patchset, patches 1-8 from Kairui introduce a model that uses
refaults to determine nr_to_scan[] for both file and anon in MGLRU.
For each reclaim operation, we calculate how many file and anon
folios to scan, similar to CLRU, rather than relying on
get_type_to_scan() and fallback mechanisms to decide what to
reclaim, which have proven rather unreliable in honoring swappiness.
This model also allows scanning and reclaiming from the two youngest
generations, including the youngest generation itself. This can help
resolve OOM situations[1] and reduce the need for aging.
Patch 9 from Barry fixes a cold/hot inversion exacerbated by patches
1–8 (which also exists in mainline) and improves reclaim efficiency.
Patches 10-13 from Gaofei and Barry optimize aging based on folio
distribution imbalance and improve reclaim behavior at extreme
swappiness values such as 1 and 200.
Patch 14 from Bo Zhang addresses the GFP_NOIO issue in MGLRU.
After the patchset, the results track CLRU across the full swappiness
range (see table below), with more file scanning at low swappiness
and more anon scanning at high swappiness.
pgsteal_file
swappiness CLRU MGLRU MGLRU+patches
1 5,894,538 756,589 7,394,183
36 799,998 497,282 526,176
71 548,331 415,612 433,353
106 407,012 383,814 347,647
141 253,737 354,249 314,437
176 189,003 347,805 261,677
200 0 346,078 188
pgsteal_anon
swappiness CLRU MGLRU MGLRU+patches
1 3,962,404 2,768,654 5,362,153
36 2,830,250 2,976,260 2,736,749
71 3,121,386 3,142,954 3,246,589
106 3,521,720 3,382,383 3,074,851
141 3,504,471 2,970,859 3,178,409
176 3,592,335 3,163,130 3,650,544
200 14,095,617 3,209,132 14,538,399
pgscan_file
swappiness CLRU MGLRU MGLRU+patches
1 10,270,808 886,997 16,246,260
36 1,010,341 569,036 614,389
71 656,136 490,972 484,769
106 460,326 436,042 367,969
141 295,184 403,132 328,943
176 235,147 390,358 268,142
200 0 398,363 188
pgscan_anon
swappiness CLRU MGLRU MGLRU+patches
1 19,341,957 5,960,884 7,646,122
36 17,530,774 6,394,951 5,914,405
71 18,624,264 6,673,569 7,167,762
106 20,088,558 6,976,364 7,821,921
141 19,686,813 6,206,580 8,495,970
176 20,936,177 6,344,854 10,585,375
200 45,313,873 6,295,581 30,313,342
refault_file
swappiness CLRU MGLRU MGLRU+patches
1 5,795,115 678,254 7,315,064
36 720,877 419,659 448,199
71 469,270 338,518 355,269
106 331,584 308,983 270,736
141 174,509 277,375 237,643
176 113,352 272,390 184,908
200 0 269,349 102
refault_anon
swappiness CLRU MGLRU MGLRU+patches
1 738,618 578,308 1,383,725
36 451,410 665,723 543,071
71 514,961 657,870 683,874
106 633,161 786,893 669,716
141 648,640 662,673 719,231
176 668,779 708,969 901,918
200 4,816,312 672,514 5,511,787
[1] https://github.com/ryncsn/emm-test-project/tree/master/file-anon-mix-pressure
RFC v5:
* Remove the aging optimizations, which have been merged - thanks for Baolin,
Baoqun, Lian Wang, Kairui, Kunwu, Ridong reviewing on this;
* Add Kairui's model for determining nr_to_scan[] for both types.
* Fix cold/hot inversion for rejected folios - Barry.
* Improve and clean up imbalanced aging, and optimize extreme
swappiness values of 1 and 200 - Gaofei, Barry.
* Address the GFP_NOIO issue in MGLRU - Bo Zhang.
* RFC v4 link:
https://lore.kernel.org/linux-mm/20260812121658.69965-1-baohua@kernel.org/
RFC v4:
* Clean up isolate_folios() based on Baolin's feedback. Thanks!
* Further improve isolate_folios() and scan_folios(), including
handling of exhausted reclaim types.
* Add fixes and performance improvements to inc_min_seq(),
and reduce lock contention.
* Improve the handling of imbalanced aging and remaining
generation-based aging.
* RFC v3 link:
https://lore.kernel.org/linux-mm/20260731083843.37811-1-baohua@kernel.org/
RFC v3:
- Added Ridong's patch of improving isolate_folios() readability;
- for lru_gen_imbalanced(), apply some suggestions from Zicheng
and Kairui, considering lruvec size and use macro;
- drop "mm: mglru: only fall back when reclaim is running at high
priority"
- mitigate aging for balanced swappiess value(near middle 100)
as swappiness bias is less a concern for them; but slightly
increased aging overhead might not be good.
* RFC v2 link:
https://lore.kernel.org/linux-mm/20260726122123.7614-1-baohua@kernel.org/
RFC v2:
- Quickly address a few issues raised in the Sashiko comments so
reviewers can ignore v1 and review a cleaner version instead.
https://sashiko.dev/#/patchset/20260726012946.18684-1-baohua@kernel.org
Thanks, Sashiko!
Barry Song (Xiaomi) (3):
mm/mglru: Avoid placing rejected folios below populated gen
mm/mglru: Reduce LRU lock contention by shrinking folio batches in
inc_min_seq
mm/mglru: Make swappiness=1 file reclaim more aggressive
Bo Zhang (1):
mm/mglru: Avoid scan anon while swapcache is low for GFP_NOIO
allocation
Kairui Song (8):
mm/mglru: report evictable sizes per type
mm/mglru: extract lruvec_populated_min_seq() helper
mm/mglru: reclaim from the oldest populated gen
mm/mglru: lift the forced protection of reclaimer
mm/mglru: skip zones above reclaim_idx instead of rotating them
mm/mglru: return for unavailable anon reclaim earlier
mm/mglru: balance anon and file scan budget by refault rate
mm/mglru: lift youngest gen protection for higher priority
lyugaofei (2):
mm/mglru: Run aging when pages are rare outside the youngest gen
mm/mglru: Avoid prolonged anon reclaim with swappiness=200
include/linux/mm_inline.h | 22 +-
mm/vmscan.c | 482 ++++++++++++++++++++++++--------------
2 files changed, 332 insertions(+), 172 deletions(-)
--
2.34.1
next reply other threads:[~2026-10-22 22:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 22:01 Barry Song (Xiaomi) [this message]
2026-10-22 22:01 ` [RFC PATCH v5 01/14] mm/mglru: report evictable sizes per type Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 02/14] mm/mglru: extract lruvec_populated_min_seq() helper Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 03/14] mm/mglru: reclaim from the oldest populated gen Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 04/14] mm/mglru: lift the forced protection of reclaimer Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 05/14] mm/mglru: skip zones above reclaim_idx instead of rotating them Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 06/14] mm/mglru: return for unavailable anon reclaim earlier Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 07/14] mm/mglru: balance anon and file scan budget by refault rate Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 08/14] mm/mglru: lift youngest gen protection for higher priority Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 09/14] mm/mglru: Avoid placing rejected folios below populated gen Barry Song (Xiaomi)
2026-10-22 22:01 ` [RFC PATCH v5 10/14] mm/mglru: Run aging when pages are rare outside the youngest gen Barry Song (Xiaomi)
2026-10-22 22:02 ` [RFC PATCH v5 11/14] mm/mglru: Reduce LRU lock contention by shrinking folio batches in inc_min_seq Barry Song (Xiaomi)
2026-10-22 22:02 ` [RFC PATCH v5 12/14] mm/mglru: Avoid prolonged anon reclaim with swappiness=200 Barry Song (Xiaomi)
2026-10-22 22:02 ` [RFC PATCH v5 13/14] mm/mglru: Make swappiness=1 file reclaim more aggressive Barry Song (Xiaomi)
2026-10-22 22:02 ` [RFC PATCH v5 14/14] mm/mglru: Avoid scan anon while swapcache is low for GFP_NOIO allocation Barry Song (Xiaomi)
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=20261022220203.91911-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=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hui.zhu@linux.dev \
--cc=kasong@tencent.com \
--cc=kunwu.chan@gmail.com \
--cc=liam@infradead.org \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuxiang.277@bytedance.com \
--cc=ljs@kernel.org \
--cc=lyugaofei@xiaomi.com \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=ridong.chen@linux.dev \
--cc=rppt@kernel.org \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=wangzicheng@honor.com \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=zhangbo56@xiaomi.com \
--cc=zhuhui@kylinos.cn \
/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®