Re: [PATCH -v4 4/4] mm/mglru: fix anon-only reclaim evicting file pages when swappiness=max
From: Barry Song
Date: Fri Jul 24 2026 - 04:33:51 EST
On Fri, Jul 24, 2026 at 11:35 AM Ridong <ridong.chen@xxxxxxxxx> wrote:
>
> From: Ridong Chen <chenridong@xxxxxxxxxx>
>
> The previous patch fixed this issue for the traditional LRU. The same
> problem exists in MGLRU [1]: when swappiness=max (SWAPPINESS_ANON_ONLY)
> is set, reclaim is expected to evict anonymous pages exclusively, but
> file pages can still be reclaimed when anonymous pages cannot be
> reclaimed (e.g. no swap and no demotion target).
>
> Fix it the same way as the traditional LRU: keep returning
> SWAPPINESS_ANON_ONLY in get_swappiness(), and return 0 from
> get_nr_to_scan() when SWAPPINESS_ANON_ONLY is set but anon pages cannot
> be reclaimed. Since get_nr_to_scan() decides how much MGLRU scans,
> returning 0 skips the scan entirely and avoids the useless scan work
> when there is nothing eligible to reclaim.
>
> The test result:
> Before fix:
>
> # cat /sys/kernel/mm/lru_gen/enabled
> 0x0007
> # cat memory.stat
> anon 204800
> file 67108864
> ...
> pgsteal_proactive 0
> pgscan_proactive 0
>
> # echo "64M swappiness=max" > memory.reclaim
> # cat memory.stat
> anon 208896
> file 0
> ...
> pgsteal_proactive 16384
> pgscan_proactive 16384
>
> After fix:
>
> # cat memory.stat
> anon 188416
> file 67215360
> kernel 1970176
> ...
> pgsteal_proactive 0
> pgscan_proactive 0
>
> # echo "64M swappiness=max" > memory.reclaim
> -bash: echo: write error: Resource temporarily unavailable
> # cat memory.stat
> anon 204800
> file 67215360
> ...
> pgsteal_proactive 0
> pgscan_proactive 0
>
> [1] https://sashiko.dev/#/patchset/20260717113300.214717-1-ridong.chen@xxxxxxxxx
>
> Fixes: 68a1436bde00 ("mm: add swappiness=max arg to memory.reclaim for only anon reclaim")
> Signed-off-by: Ridong Chen <chenridong@xxxxxxxxxx>
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>