Re: [PATCH 1/3] mm/vmscan: fix anon-only reclaim evicting file pages when swappiness=max

From: Muchun Song

Date: Fri Jul 17 2026 - 09:00:02 EST




> On Jul 17, 2026, at 19:32, Ridong <ridong.chen@xxxxxxxxx> wrote:
>
> From: Ridong Chen <chenridong@xxxxxxxxxx>
>
> As Qi mentioned [1], when swappiness=max (SWAPPINESS_ANON_ONLY) is set,
> the reclaim logic is expected to reclaim anonymous pages exclusively.
> However, due to the current ordering of checks in get_scan_count(),
> file pages may still be evicted if can_reclaim_anon_pages() returns
> false, which contradicts the semantics of SWAPPINESS_ANON_ONLY.
>
> Reproducer in a cgroup holding 64M of file cache, with no swap configured:
>
> Before (file cache is wrongly evicted):
> # cat memory.stat
> anon 196608
> file 67178496
> pgscan_proactive 0
> # echo "64M swappiness=max" > memory.reclaim
> # cat memory.stat
> anon 208896
> file 4096 <- page cache evicted
> pgsteal_proactive 16400
> pgscan_proactive 16400
>
> After (file cache is left intact):
> # cat memory.stat
> anon 200704
> file 67178496
> pgscan_proactive 0
> # echo "64M swappiness=max" > memory.reclaim
> -bash: echo: write error: Resource temporarily unavailable
> # cat memory.stat
> anon 208896
> file 67178496 <- page cache untouched
> pgsteal_proactive 0
> pgscan_proactive 0
>
> Fix this by bailing out early when SWAPPINESS_ANON_ONLY is set and no
> anonymous pages are reclaimable, before falling back to file reclaim.
>
> [1] https://lore.kernel.org/cgroups/7ddf3eee-5fe2-45f7-8614-c8936a039e04@xxxxxxxxx/
>
> Fixes: 68a1436bde00 ("mm: add swappiness=max arg to memory.reclaim for only anon reclaim")
> Suggested-by: Qi Zheng <qi.zheng@xxxxxxxxx>
> Signed-off-by: Ridong Chen <chenridong@xxxxxxxxxx>

Reviewed-by: Muchun Song <muchun.song@xxxxxxxxx>