Re: [RFC PATCH v5 00/14] mm: mglru: fix swappiness behavior

From: Kairui Song

Date: Sat Oct 24 2026 - 12:10:59 EST


On Fri, Oct 23, 2026 at 6:02 AM Barry Song (Xiaomi) <baohua@xxxxxxxxxx> wrote:
>
> 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

Hi Barry,

Thanks for pushing this series forward!

One nit pick so far is the test data seems redundant with the one
below, maybe we can just keep one of them.

> 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.

Right, the OOM reproducer is demostrated here previously:
https://lore.kernel.org/all/20260318-mglru-reclaim-v1-0-2c46f9eb0508@xxxxxxxxxxx/

That series is merged at V7:
https://lore.kernel.org/linux-mm/20260428-mglru-reclaim-v7-0-02fabb92dc43@xxxxxxxxxxx/

The problem is largely eased as described, but it isn't 100% fixed at
that time. It will still go OOM with higher pressure. So before this
series, I could still see OOM after hundreds of loops. And problem is
gone after the fixing patch in this series. Unfortunately it's very
hard to reproduce and that reproducer is the best I have so far.

>
> 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

Right, that's really nice result. Do you have system time or
performance readings? BTW for the performance reading I think we can
focus on the 36 - 176 range. If a user asks for extreme bias towards
anon/file, they strongly favor reclaim priority over throughput, and
the behavior is arguable at that point.