Re: [PATCH -v4 0/4] mm/vmscan: fix swappiness=max and clean up per-node proactive reclaim

From: Andrew Morton

Date: Fri Jul 24 2026 - 01:37:18 EST


On Fri, 24 Jul 2026 11:34:31 +0800 Ridong <ridong.chen@xxxxxxxxx> wrote:

> Fixes and one cleanup.
>
> Patch 1 fixes "swappiness=max": the anon-only test in get_scan_count()
> sat after the "cannot reclaim anon" check, so when no anon was
> reclaimable the request fell back to SCAN_FILE and evicted page cache
> instead.
>
> Patch 2 fixes reclaim_store() collapsing every error into -EAGAIN, so
> callers can no longer tell an invalid argument from a busy interface;
> propagate the real error code, matching the memcg path.
>
> Patch 3 drops the now-unused gfp_mask parameter from __node_reclaim().
>
> Patch 4 fixes the same "swappiness=max" issue for MGLRU.

Thanks, I've updated mm.git's mm-unstable branch to this version.

Sashiko said one thing, but you've examined this before. Hopefully
MGLRU maintainers will consider your suggestion in
https://lore.kernel.org/8336e48a-ab3a-4db9-a7f9-5bb6af2b22c3@xxxxxxxxx

https://sashiko.dev/#/patchset/20260723045718.2052070-1-ridong.chen@xxxxxxxxx

> v3 -> v4:
> - Patch 4: Update comments and commit message.
> - Patch 4: Adopted Sashiko's suggestion to use WARN_ON_ONCE.

Here's how v4 altered mm.git:


mm/vmscan.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)

--- a/mm/vmscan.c~b
+++ a/mm/vmscan.c
@@ -2492,7 +2492,13 @@ static void get_scan_count(struct lruvec
enum scan_balance scan_balance;
enum lru_list lru;

- /* Proactive reclaim initiated by userspace for anonymous memory only */
+ /*
+ * Proactive reclaim initiated by userspace for anonymous memory only.
+ * SWAPPINESS_ANON_ONLY is set only on the proactive reclaim path, so
+ * warn if it shows up elsewhere. When anon cannot be reclaimed (e.g.
+ * no swap), bail out instead of falling back to evicting file pages,
+ * which would violate the anon-only semantics.
+ */
if (swappiness == SWAPPINESS_ANON_ONLY) {
WARN_ON_ONCE(!sc->proactive);
if (!can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) {
@@ -2693,6 +2699,10 @@ static int get_swappiness(struct lruvec
{
struct mem_cgroup *memcg = lruvec_memcg(lruvec);
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
+ int swappiness = sc_swappiness(sc, memcg);
+
+ if (swappiness == SWAPPINESS_ANON_ONLY)
+ return swappiness;

if (!sc->may_swap)
return 0;
@@ -2701,7 +2711,7 @@ static int get_swappiness(struct lruvec
mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH)
return 0;

- return sc_swappiness(sc, memcg);
+ return swappiness;
}

static int get_nr_gens(struct lruvec *lruvec, int type)
@@ -4903,6 +4913,20 @@ static long get_nr_to_scan(struct lruvec
struct mem_cgroup *memcg, int swappiness)
{
unsigned long nr_to_scan, evictable;
+ struct pglist_data *pgdat = lruvec_pgdat(lruvec);
+
+ /*
+ * Proactive reclaim initiated by userspace for anonymous memory only.
+ * SWAPPINESS_ANON_ONLY is set only on the proactive reclaim path, so
+ * warn if it shows up elsewhere. When anon cannot be reclaimed (e.g.
+ * no swap), return 0 to skip the scan entirely, avoiding useless scan
+ * work when there is nothing eligible to reclaim.
+ */
+ if (swappiness == SWAPPINESS_ANON_ONLY) {
+ WARN_ON_ONCE(!sc->proactive);
+ if (!can_reclaim_anon_pages(memcg, pgdat->node_id, sc))
+ return 0;
+ }

evictable = lruvec_evictable_size(lruvec, swappiness);

_