From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A31121CFE0 for ; Mon, 20 Jul 2026 02:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784514482; cv=none; b=YOmI2ofDfF5vLywo+X/hBfFaYsTJDcUQcSomyk4qwNzixear0OLnsZNs8kfzH2i1SeoXu4Jp01KZ6n0IadxUQIQvyFEqvQc4puu4xiY+Qv01bK6FE8humLYpYJXrr/zkd/EkZRKSnRllhf3bBCzUZ7Hf5vxJP5Y2F2MZS7tUqpc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784514482; c=relaxed/simple; bh=qOHX2sNatS2m89LmPvQQZKynEBtyX1Va7y5Gf/gYoL8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lYyy7wWiWwDuKXEwJjfF1tbaoayy7+p/bQ7tK5VqiGtod9gZaKLXGM027Uo2Sl20pO/Y+y9uoeXYqsaW19XYdk682ZAWvJz0+eRM3VwMucfcn6PeWVqWXwD+oPqsN68oJ4q1fX2UatWXUpTpuf6K/uukvM5JXpABOAbf3xaMXts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=eNR5XIKw; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="eNR5XIKw" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784514477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AlNhtQCquztP9G9X9Z8iMtH1eSwOYMw8dTp0ZlM181c=; b=eNR5XIKwOUOOp9+tzPCT94JJoXfglAFyTLkEo6lbTOBL7ZmigdZfbK5O+mg/9ghIFh9eBs PW6Mv+3DKHv2p3XIvxukoaCbKBlc0/6zNPw7hJrLWoMq27RNj4Bqk5zw9RYzX1dUUVPpi4 763PxCA35hA5D2IQaHJMS9Q+06zHa3Y= Date: Mon, 20 Jul 2026 10:27:43 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2 1/4] mm/vmscan: fix anon-only reclaim evicting file pages when swappiness=max To: Ridong Chen , akpm@linux-foundation.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, shakeel.butt@linux.dev, ljs@kernel.org, kasong@tencent.com, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, hezhongkun.hzk@bytedance.com, muchun.song@linux.dev, dave@stgolabs.net, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ridong Chen References: <20260718095251.82937-1-ridong.chen@linux.dev> <20260718095251.82937-2-ridong.chen@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <20260718095251.82937-2-ridong.chen@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 7/18/26 5:52 PM, Ridong Chen 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 > Signed-off-by: Ridong Chen > --- > mm/vmscan.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) Thanks for the fix! Reviewed-by: Qi Zheng > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 35c3bb15ae96..d6b383d96a0c 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2501,6 +2501,17 @@ 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 */ > + 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; > + } > + > /* 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)) { > scan_balance = SCAN_FILE; > @@ -2519,13 +2530,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > goto out; > } > > - /* 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; > - } > - > /* > * Do not apply any pressure balancing cleverness when the > * system is close to OOM, scan both anon and file equally