Re: [PATCH] mm/vmscan: respect can_reclaim_anon_pages() in MGLRU get_swappiness()

From: Barry Song

Date: Mon Nov 16 2026 - 23:43:55 EST


On Tue, Nov 17, 2026 at 10:59 AM Muhammad Haris Awan
<m.harisawan@xxxxxxxxxx> wrote:
>
> Under GFP_NOIO reclaim, reclaimers cannot add anonymous folios to the
> swapcache and can only reclaim anon folios that are already in the
> swapcache (or demotable). Traditional LRU avoids scanning anon when
> swapcache < (anon_pages >> 6) via reclaimable_anon_is_low(), but MGLRU
> explicitly skipped this check because get_swappiness() did not consult
> can_reclaim_anon_pages().
>
> Call can_reclaim_anon_pages() from get_swappiness() and remove the
> lru_gen_enabled() bypass from reclaimable_anon_is_low(). When anon
> pages are not reclaimable (e.g., GFP_NOIO with low swapcache and no
> demotion target), get_swappiness() now returns 0, restricting MGLRU
> eviction, aging, and fallback isolation to LRU_GEN_FILE only.
>
> Signed-off-by: Muhammad Haris Awan <m.harisawan@xxxxxxxxxx>
> ---
> mm/vmscan.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6a1af9b92..f5fa67985 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -379,13 +379,6 @@ static inline bool reclaimable_anon_is_low(struct mem_cgroup *memcg,
> if (!sc || (sc->gfp_mask & __GFP_IO))
> return false;
>
> - /*
> - * FIXME: MGLRU doesn't fully respect can_reclaim_anon_pages() for the
> - * scanning type, so only apply this to the traditional LRU for now.
> - */
> - if (lru_gen_enabled())
> - return false;
> -
> if (memcg) {
> struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
>
> @@ -2893,6 +2886,9 @@ static int get_swappiness(struct lruvec *lruvec, struct scan_control *sc)
> if (!sc->may_swap)
> return 0;
>
> + if (!can_reclaim_anon_pages(memcg, pgdat->node_id, sc))
> + return 0;
> +

Thanks, but we've already discussed this in [1][2].

This approach is incorrect, as it leads to hot/cold inversion.

Xiang's approach [1][2] avoids this issue, but the code is somewhat
confusing, as it effectively uses two swappiness values: one for
eviction and the other for aging.

We've been working on a clearer solution in patchset [3].

[1] https://lore.kernel.org/linux-mm/20261010141057.599595-1-liuxiang.277@xxxxxxxxxxxxx/
[2] https://lore.kernel.org/linux-mm/179248830836.1744016.8424217811286616919.noio-mglru-rfc-v2@xxxxxxxxxxxxx/
[3] https://lore.kernel.org/linux-mm/20261114200803.23129-17-baohua@xxxxxxxxxx/

Thanks,
Barry