Re: [RFC PATCH v2] mm: vmscan: avoid anon scanning for GFP_NOIO with low swapcache in MGLRU

From: Barry Song

Date: Wed Oct 21 2026 - 17:55:47 EST


On Wed, Oct 21, 2026 at 3:28 PM Baolin Wang
<baolin.wang@xxxxxxxxxxxxxxxxx> wrote:
[...]

> > static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *sc)
> > {
> > unsigned long total;
> > int swappiness = get_swappiness(lruvec, sc);
> > struct mem_cgroup *memcg = lruvec_memcg(lruvec);
> >
> > + swappiness = get_scan_swappiness(lruvec, sc, swappiness);
> > +
> > total = lruvec_evictable_size(lruvec, swappiness);
> >
> > /* whether the size is big enough to be helpful */
> > @@ -5249,9 +5265,10 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
> > bool need_rotate = false, should_age = false;
> > long nr_batch, nr_to_scan;
> > int swappiness = get_swappiness(lruvec, sc);
> > + int scan_swappiness = get_scan_swappiness(lruvec, sc, swappiness);
>
> IMO, 'swappiness' and 'scan_swappiness' are really confusing. Why move
> this logic into get_swappiness()? In get_swappiness(), we already have
> some similar logic to adjust swappiness when there is no available swap
> space.
>

Yes. It is very confusing. we can't do that in get_swappiness() as otherwise,
we will get cold/hot inversion due to GFP_NOIO. for a real swappiness=0,
we allow cold/hot inversion for anon, but for GFP_NOIO, this is not the
case.

static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
{
...
/* For file type, skip the check if swappiness is anon only */
if (type && (swappiness == SWAPPINESS_ANON_ONLY))
goto done;

/* For anon type, skip the check if swappiness is zero (file only) */
if (!type && !swappiness)
goto done;
...
}

So the trick here is that Xiang is doing scans by tuned swappiness but does age
by the original swappiness.

IMHO, this is confusing but this is a possible way to fix it before we
land something
like:
mm/mglru: Avoid scan anon while swapcache is low for GFP_NOIO allocation

https://git.kernel.org/pub/scm/linux/kernel/git/baohua/linux.git/commit/?h=kairui_scanbalance_0.4

Best Regards
Barry