From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0BF8352017 for ; Mon, 27 Jul 2026 11:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785152260; cv=none; b=JIcWdFwXW1I8ltPLqiYB4ENGYlKNoDMpwbCiUxwNrpwSBDZICmG5djx90K1q5NNHU905E05+/Um/pRuCGPLcO7Yw/ExR1+bW+YjKQA7YDf7LifRGBykhPzisBIJJSRt6obJePPHAY6YcBq+95ErefnGikhRG/544QXpCeqkCcfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785152260; c=relaxed/simple; bh=uAu45GJGeH1ds/W/0qeCUygZaBKRTR7RU9DVioeg5Gs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oQHX3P/68wHsRSioQA/5/y03GeQmgng4qmL8gy+EEfDj2O+7rUGcwmnTIAoIMZYRvm4WUJYjDeS2EL6f20XKel15kDbDZ3jNoDgQH4P5pehg8R+HZ/O1x6gTZGMrW/vNuyTNcHPK/QTN7y9K0jrGVk4xPsuOATNR6E4DDBU+/mw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=MF0XKH/d; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="MF0XKH/d" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490cf322ed0so17422985e9.1 for ; Mon, 27 Jul 2026 04:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1785152257; x=1785757057; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ifEMtdw2Y3LJzGTrNEzkInEIHCSbSBhJKHBE4Huj/fc=; b=MF0XKH/dSWf5h+I2IfZgxGWd0uSknk/cCPXxtvHCoBQJ1qaixYrUmIqLg2daNAUVw2 X4Z0dvHyxN/wrreNG7vC5qOE7YiZ4TpWJfa7nm2W0EhNxe+JtqDpj5F52JwyGLvBEbj4 wWSGle8UejsbYZRKusOjBiG415kEYTZs4sXGGZLqwcM6RVNlSKVV25hp2FR6OyLb0SG8 xHRTyQGajByVUfJCyOVLliELLGm2ZtsIk8GboiSqHT0BnyEY3UC4458R0f1CGpzSCKa8 2Hcqdll5eN8J9k7ywo9yev0LjwCtZN7ww8UL16yPmsyOVBQc+FKQBsuXPRn8lKjrLQCV YM2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785152257; x=1785757057; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ifEMtdw2Y3LJzGTrNEzkInEIHCSbSBhJKHBE4Huj/fc=; b=h6NgcoT8ab7j2dULEID+sqkwdHbWuIn2TNxaYZsOHkngp3Tv1CYLNEySnoLKE2F0cz rDv/iE3B/+yivEyMQyiAxMMQCiTQfm+c/WlOvwCMvlWnt0KCzQl+NnF9xy02wkuDozUD 6cQwHSzzRttcHkT5MGZb8N1h5U1TmkiyUkH+GrV8MZM5G2nyEFGGIA2sRR8X+z3O+pQr 1B6c0Wy2Yzm/2u0wMGjqMQljFmkjTSyl3AWVtROEssI9WBrwJ6+lBFHXfKFvmAAIxP2I JRcAmC/rWN1JEIE78t309CqGXWjbxgQFQcJ1qJk7VMwU4Qv9MuvANV9Vg5xbhLOkyqYt Q8Mg== X-Forwarded-Encrypted: i=1; AHgh+RomT0XCcSH+NIPRmh0ToBixq8dmKFtMuicgODpG56zeiNsj/2c+xSqVLZat09ptuJKaWFeZO8gspoq82v0=@vger.kernel.org X-Gm-Message-State: AOJu0YzztOBRIVlZudYhdLn7sLIkKIEyFERABmwiiWyKzd5fqtRDDV3R 9ISsAKy1iA66lw2kFnYdf7ms+uP3GaLK6VzmoE+cT9PtDHVYQHr8CLRg5bnm452bBUA= X-Gm-Gg: AR+sD10XlrZ2eVGglEJAB+dMSnmI++Z71Eg/tlE0r/ihqxW5EzM/UBWVl/rwUKMtM5g b9to7RyXE+2glVRUvWsx1YAoiKUJfs1BKOeuTc+/s/kJ8WZbHBvnZz/52d38QoOS6qcfZKjoF1n c1I9CerSss+Ug0ksYMBpmTQ5GdmrxbTfYykg9UzGTnGAyGmMpbSZtI+97IvY5pse+cbuFaoen3H DyendkHWd29r8lJBUGaTKvuuQYd6xXW4ce0ocWPZaAuUJewv1o12J/IOwDVfbUXryqwLFJ2Zrx3 SUDAlSL+hrjXN/7mtmVVhzb+EMXzQTHAbr19jb0dvFN30iqJenTYSQD3Scm/VVTx+IcFoEvdpHX CkOQSi2TVyQYiDvVQaZVXDIAy6Tm2EjHkIIpxRUibC62CBawm1hszhmBn9S5BQySCkZm0lRMldB 1cyzrRtm1mzsnITAN53U3s X-Received: by 2002:a05:600c:4583:b0:495:7426:c392 with SMTP id 5b1f17b1804b1-496b57108dcmr105591585e9.1.1785152257042; Mon, 27 Jul 2026 04:37:37 -0700 (PDT) Received: from localhost (109-81-83-7.rct.o2.cz. [109.81.83.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-496b4f30126sm217525435e9.13.2026.07.27.04.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 04:37:36 -0700 (PDT) Date: Mon, 27 Jul 2026 13:37:35 +0200 From: Michal Hocko To: Ridong Cc: Andrew Morton , Johannes Weiner , David Hildenbrand , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Zhongkun He , Muchun Song , Davidlohr Bueso , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ridong Chen Subject: Re: [PATCH -v4 1/4] mm/vmscan: fix anon-only reclaim evicting file pages when swappiness=max Message-ID: References: <20260724033435.2573323-1-ridong.chen@linux.dev> <20260724033435.2573323-2-ridong.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260724033435.2573323-2-ridong.chen@linux.dev> On Fri 24-07-26 11:34:32, Ridong wrote: > From: Ridong Chen > > 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@linux.dev/ > > Fixes: 68a1436bde00 ("mm: add swappiness=max arg to memory.reclaim for only anon reclaim") > Suggested-by: Qi Zheng > Acked-by: Shakeel Butt > Acked-by: Johannes Weiner > Reviewed-by: Muchun Song > Reviewed-by: Qi Zheng > Reviewed-by: Barry Song > Signed-off-by: Ridong Chen > --- > mm/vmscan.c | 24 +++++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 35c3bb15ae96..2c689682b952 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2501,6 +2501,23 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > enum scan_balance scan_balance; > enum lru_list lru; > > + /* > + * 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)) { > + memset(nr, 0, sizeof(*nr) * NR_LRU_LISTS); > + return; > + } > + scan_balance = SCAN_ANON; > + goto out; Rather than warning the code would be easier to understand (SWAPPINESS_ANON_ONLY implying sc->proactive is very subtle assumption that might change in the future) I would go with and explicit check. Looking at how the code is structured currently doesn't the following express the intention slightly better? diff --git a/mm/vmscan.c b/mm/vmscan.c index 35c3bb15ae96..4fd38e3f1b05 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2503,6 +2503,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, /* If we have no swap space, do not bother scanning anon folios. */ if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) { + if (swappiness == SWAPPINESS_ANON_ONLY && sc->proactive) { + memset(nr, 0, sizeof(*nr) * NR_LRU_LISTS); + return; + } scan_balance = SCAN_FILE; goto out; } @@ -2521,7 +2525,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, /* Proactive reclaim initiated by userspace for anonymous memory only */ if (swappiness == SWAPPINESS_ANON_ONLY) { - WARN_ON_ONCE(!sc->proactive); scan_balance = SCAN_ANON; goto out; } -- Michal Hocko SUSE Labs