Re: [RFC PATCH] mm: vmscan: avoid anon scanning for GFP_NOIO with low swapcache
From: Bo Zhang
Date: Thu Sep 03 2026 - 09:14:43 EST
On Thu, Sep 3, 2026 at 6:35 PM Barry Song <baohua@xxxxxxxxxx> wrote:
>
> Yes. The coexistence of `GFP_NOIO` and anon rmap scanning seems
> nasty. We might also want to do something like the following, but
> the side effect is that it might keep a folio while preserving its
> PTE young state, indirectly making the folio semantically hotter.
> So this may not be a good option. Skipping anon scanning in the first
> place seems more sensible.
>
> + /*
> + * Don't waste time doing rmap and scanning PTE access for
> + * non-reclaimable folios.
> + */
> + if (!do_demote_pass && folio_test_anon(folio) &&
> + folio_test_swapbacked(folio) &&
> + !folio_test_swapcache(folio)) {
> + if (!(sc->gfp_mask & __GFP_IO))
> + goto keep_locked;
> + if (folio_maybe_dma_pinned(folio))
> + goto keep_locked;
> + }
Agreed. That matches my thinking: doing the rmap/PTE walk first and
then keeping the folio would leave its young state set and make it look
hotter, so skipping anon selection up front avoids that side effect.
I'll keep the check in can_reclaim_anon_pages().
> it seems we could just use mem_cgroup_lruvec() instead:
>
> - struct lruvec *lruvec = get_lruvec(memcg, nid);
> + struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid));
>
> I applied your patch on my PC with the above change. I didn't see any
> panic or run into any problems.
Thanks, and thanks to the sashiko bot for catching this. I've switched
to mem_cgroup_lruvec() in v2, which also lets me drop the get_lruvec()
move entirely. Thanks for testing it on your side.
I'll send v2 shortly.
Thanks,
Bo