mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH v5 00/14] mm: mglru: fix swappiness behavior
@ 2026-10-22 22:01 Barry Song (Xiaomi)
  2026-10-22 22:01 ` [RFC PATCH v5 01/14] mm/mglru: report evictable sizes per type Barry Song (Xiaomi)
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Barry Song (Xiaomi) @ 2026-10-22 22:01 UTC (permalink / raw)
  To: akpm, linux-mm
  Cc: hui.zhu, axelrasmussen, baohua, baolin.wang, david, hannes,
	linux-kernel, ljs, mhocko, qi.zheng, ryncsn, shakeel.butt,
	weixugc, yuanchu, zhuhui, baoquan.he, liuxiang.277, wangzicheng,
	lianux.mm, kasong, liam, surenb, mhocko, rppt, zhangbo56,
	lyugaofei, ridong.chen, kunwu.chan

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-10-22 22:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22 22:01 [RFC PATCH v5 00/14] mm: mglru: fix swappiness behavior Barry Song (Xiaomi)
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)

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®