From nobody Sat Jul 25 04:29:48 2026 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 5C9BD2DB794 for ; Sat, 18 Jul 2026 09:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368453; cv=none; b=PDrVR/TnHyD/xQOj9EtOWnlTnPV+6khXCqRI9F2yMQlOjaFnRNJ7zY33XTH1Z5OiYcGmonv5Tsb1dOLpFExOPDnjzUGN1RwpPT0HUEkiSKKA5/JnaA4E2vQC0FIN71jywJafTN/O5G+L3RV7KthO6UZlKWpZ/4OQe0MVQC213kY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368453; c=relaxed/simple; bh=6K+wru565EZSAc6eOSQX5rAMRLO603qn5um4ie3pkAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kev7yd8I0NLRxHzFaMyzD4GOvB+DV2t7zXiH0jCHSPem5sH7qs6lv9zGjoWE+BPx7XRQeHAk4Vsaax7gB+Awx52RCe9STWhw+fo93tBWels+HO+gCc8Yo5Prp54vmzrAg7x72ag4tfxpCfzw2YrSmPLeqF2o5r4jBI5XO7OgPyo= 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=IPZJ2vmv; arc=none smtp.client-ip=95.215.58.177 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="IPZJ2vmv" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784368450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Q+i8KecsNiTPDlAIDtRLOAH9MLCuFDqX7eHJi+IsDY=; b=IPZJ2vmvhKbB2s6jo0mwrZ5E3jVAfCVyiNyvZzuKXamWBoC2sL/Dj9CDm4Sxw640dP4ApZ imoYOnvUxNFjfm3w884NaHFRKH64hmv0sLPWe/uDiPo5CO9UmEjMtAQ+wt5Kr7siFL5IUz tFno2FMVgo8d4AbnwDd/uuNUw8x21go= From: Ridong Chen To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, 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@linux.dev, Ridong Chen Subject: [PATCH v2 1/4] mm/vmscan: fix anon-only reclaim evicting file pages when swappiness=max Date: Sat, 18 Jul 2026 17:52:48 +0800 Message-ID: <20260718095251.82937-2-ridong.chen@linux.dev> In-Reply-To: <20260718095251.82937-1-ridong.chen@linux.dev> References: <20260718095251.82937-1-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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Ridong Chen As Qi mentioned [1], when swappiness=3Dmax (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=3Dmax" > 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=3Dmax" > 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@li= nux.dev/ Fixes: 68a1436bde00 ("mm: add swappiness=3Dmax arg to memory.reclaim for on= ly anon reclaim") Suggested-by: Qi Zheng Acked-by: Shakeel Butt Acked-by: Johannes Weiner Reviewed-by: Muchun Song Signed-off-by: Ridong Chen Reviewed-by: Barry Song Reviewed-by: Qi Zheng --- mm/vmscan.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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, st= ruct scan_control *sc, enum scan_balance scan_balance; enum lru_list lru; =20 + /* Proactive reclaim initiated by userspace for anonymous memory only */ + if (swappiness =3D=3D 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 =3D 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 =3D SCAN_FILE; @@ -2519,13 +2530,6 @@ static void get_scan_count(struct lruvec *lruvec, st= ruct scan_control *sc, goto out; } =20 - /* Proactive reclaim initiated by userspace for anonymous memory only */ - if (swappiness =3D=3D SWAPPINESS_ANON_ONLY) { - WARN_ON_ONCE(!sc->proactive); - scan_balance =3D SCAN_ANON; - goto out; - } - /* * Do not apply any pressure balancing cleverness when the * system is close to OOM, scan both anon and file equally --=20 2.43.0 From nobody Sat Jul 25 04:29:48 2026 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 6EC3538330B for ; Sat, 18 Jul 2026 09:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368462; cv=none; b=Kn4HAIwuZZpF2SaSi16xs8XDD/xvCoOWrQSJGfka3I2abGtuvQo3ZVdlyRNTroyN9XQ50FwVxK/vajZj5WRSp+wNRAlkGOk97SSEmitVzOYHOO8BiWvgF+Tkzoxlizt8QE8tEQ8na7IASiy+40iajkRHwWOkucGsaJo0jLDfPtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368462; c=relaxed/simple; bh=30wdl7j+cR4qYZaY7UEuOSr/RxCsU7QXnSe6OX6BezY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ShZJIHRLiRDecCY+HNkfglTteXZlaes+zh2p7WnJt5Tyq/hpi2iUo6WKzKS1BRTidxEnoX6sJXe2k44hZO0gecn3CGH8RnGXKLyLtLv74ZW3YC39ePmnAHDmMUNNUhIhRV4cSZUVHCT8lJHocCRCP+CJv99M3BHbVPCypn0t2jg= 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=dcdhmu96; arc=none smtp.client-ip=95.215.58.173 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="dcdhmu96" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784368459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x3ltDvom3/qAw8FbUiS3p4apXbK6gN1G2ur4K5UNTpA=; b=dcdhmu96Qo8lUZA4Nqrn4+MdC0HqrZoWIpF8V4mR4juUWJXtbnXjebaQ34mUNoFJcz2VsB m9wmvCYR4Hrkh5fWtlsNOt7eyV4CG1L2CJ7FVqEBY4bSEXRbLzpyChRw4V7Um1ZregR+JQ Y/fOp/x2m+X7tk6YsmTUXM2DP2drA0U= From: Ridong Chen To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, 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@linux.dev, Ridong Chen Subject: [PATCH v2 2/4] mm: vmscan: propagate real error code from per-node proactive reclaim Date: Sat, 18 Jul 2026 17:52:49 +0800 Message-ID: <20260718095251.82937-3-ridong.chen@linux.dev> In-Reply-To: <20260718095251.82937-1-ridong.chen@linux.dev> References: <20260718095251.82937-1-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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Ridong Chen It has been observed that per-node proactive reclaim always returns -EAGAIN when any error occurs. As discussed in the mailing list [1], the interface should distinguish between cases where no reclaimable memory is left and where another entity is concurrently using the same interface. Propagate the real error code, consistent with how memcg proactive reclaim handles errors. [1] https://lore.kernel.org/all/20250717235604.2atyx2aobwowpge3@offworld/T/= #m3514718be82a31b05726a49da9b61fbfc69a589e Fixes: b980077899ea ("mm: introduce per-node proactive reclaim interface") Reviewed-by: Muchun Song Acked-by: Johannes Weiner Acked-by: Shakeel Butt Signed-off-by: Ridong Chen Reviewed-by: Barry Song Reviewed-by: Qi Zheng --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d6b383d96a0c..cfe4556c96d7 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -8017,7 +8017,7 @@ static ssize_t reclaim_store(struct device *dev, int ret, nid =3D dev->id; =20 ret =3D user_proactive_reclaim((char *)buf, NULL, NODE_DATA(nid)); - return ret ? -EAGAIN : count; + return ret ? ret : count; } =20 static DEVICE_ATTR_WO(reclaim); --=20 2.43.0 From nobody Sat Jul 25 04:29:48 2026 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 BAAD337BE8E for ; Sat, 18 Jul 2026 09:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368470; cv=none; b=hn8tPzoz0cOuaaxGq8LSlR/DzyATgdxOj3W47o4F9xszSWDS5Ads2a2LD05xadDJubFvY+rhznH75tEl57PK5hqBDkm+AnWMw3vTM00TFXhKRMGH7rhvJR1OjX3gE2lnDGvpN5F90/xC0zkvnBNkBsFeioswoHcpnlFsAW71c/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368470; c=relaxed/simple; bh=Q89afdI9RUszeuTd+0bZGUDh9p9GYJPameUrjlT++nA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tK/SFdIi3czlQXIm0is0iJaOfG+nzgGlDS24XAgWumW52octTNGsaDx67wcQx0UgwKH0wd7/SEPGwnupb9qqRkZoSCye7NA3A3jFhyNWeK6v1AC9swPncfoOWw6xzN+lnAQbKjh+PK674Px1PiuHTDrdSTaMQU8lSFGhKBjZkv8= 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=SWJHGvIJ; arc=none smtp.client-ip=95.215.58.176 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="SWJHGvIJ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784368466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jfS0xqNab+cGTBtcs71EybfPlueNPDuy0c1ubwCt214=; b=SWJHGvIJ9H9I0bqGkmj23ibjJvqGqlNWOEBHhA4KnGBBPZvA3QtZ8Nz1wb1lGiPDUJkbfH 36CyERNXQ6ER0t4rfRLfvQXJNonVLbbMSICCymcfge+4PV2bJOjAh1c/UYcvxOrKo4GXkA uF/gu3WcHWS+QWfbjXJmFmK9+ZMHyjI= From: Ridong Chen To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, 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@linux.dev, Ridong Chen Subject: [PATCH v2 3/4] mm: vmscan: drop unused gfp_mask parameter from __node_reclaim() Date: Sat, 18 Jul 2026 17:52:50 +0800 Message-ID: <20260718095251.82937-4-ridong.chen@linux.dev> In-Reply-To: <20260718095251.82937-1-ridong.chen@linux.dev> References: <20260718095251.82937-1-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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Ridong Chen Commit 57972c78e678 ("mm/vmscan: make __node_reclaim() more generic") moved the scan_control construction out to the callers and passed the struct in by pointer. After that change every use of the gfp mask inside __node_reclaim() goes through sc->gfp_mask, leaving the gfp_mask parameter unused. Just remove the dead parameter and update the callers accordingly. No functional change. Acked-by: Shakeel Butt Acked-by: Johannes Weiner Reviewed-by: Muchun Song Signed-off-by: Ridong Chen Reviewed-by: Barry Song Reviewed-by: Qi Zheng --- mm/vmscan.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cfe4556c96d7..e1ef6350a300 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7742,7 +7742,7 @@ static unsigned long node_pagecache_reclaimable(struc= t pglist_data *pgdat) /* * Try to free up some pages from this node through reclaim. */ -static unsigned long __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_m= ask, +static unsigned long __node_reclaim(struct pglist_data *pgdat, unsigned long nr_pages, struct scan_control *sc) { @@ -7834,7 +7834,7 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp= _mask, unsigned int order) if (test_and_set_bit_lock(PGDAT_RECLAIM_LOCKED, &pgdat->flags)) return NODE_RECLAIM_NOSCAN; =20 - ret =3D __node_reclaim(pgdat, gfp_mask, nr_pages, &sc) >=3D nr_pages; + ret =3D __node_reclaim(pgdat, nr_pages, &sc) >=3D nr_pages; clear_bit_unlock(PGDAT_RECLAIM_LOCKED, &pgdat->flags); =20 if (ret) @@ -7847,7 +7847,7 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp= _mask, unsigned int order) =20 #else =20 -static unsigned long __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_m= ask, +static unsigned long __node_reclaim(struct pglist_data *pgdat, unsigned long nr_pages, struct scan_control *sc) { @@ -7949,8 +7949,7 @@ int user_proactive_reclaim(char *buf, &pgdat->flags)) return -EBUSY; =20 - reclaimed =3D __node_reclaim(pgdat, gfp_mask, - batch_size, &sc); + reclaimed =3D __node_reclaim(pgdat, batch_size, &sc); clear_bit_unlock(PGDAT_RECLAIM_LOCKED, &pgdat->flags); } =20 --=20 2.43.0 From nobody Sat Jul 25 04:29:48 2026 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 522EE2DB794 for ; Sat, 18 Jul 2026 09:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368477; cv=none; b=pDktsodZTfcyd6PC3eVwYst/UdBcUjJ5f0zrDB6A0iPyByeGfTL67yobftxtvsxzmTWZCVuD2SnPgKKJXM8aEnIaU9/qH1UOsFta+oaarG22B5EfyNNn7nxzpKjgc5i7yChyB6DZhHEhHmjpdYhNhfCYuyqzYNmUT44oEdKs7NQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784368477; c=relaxed/simple; bh=QR/d3aVXWxmvjUUKKplUp3vHqgVcUD4lvlF0VCUhPKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+IZq9Jb5MUDqVQJ82FYoMm9gDbRJH6OuRklud6U6YLtEal9LEQgWqHX63iDX69/ZRXuPkiu/S7cpLtedHZzDub9qtyomkiIo9J2ZNfMfV3LACoSRyaxDIlfWMyPSzg7UQ6+iUgKPpeu5x0ss+P0QmN/4luDAlJ9CdQPB36ktOo= 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=M7Vle5EV; arc=none smtp.client-ip=95.215.58.179 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="M7Vle5EV" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784368474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lO66TrggiuQ7p/0nxBhsLlU4BVpMMd+j4O5LEqrNdrI=; b=M7Vle5EV7fSyEDSoDc+ub+hZJ3XzmI8D08hPQ1s2AY4Zl02x7O6gHYGeqlsko18gRj5k9U IF4I4rqrl66FhbTOGVq5U8370Pr9XfmY3he+nMUypFBj2+o3+CBSqGulu8qQpPwkZtbEnk rdM+9yOjIv+BB9DYU2Xmz9HTphMUJgQ= From: Ridong Chen To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, 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@linux.dev, Ridong Chen Subject: [PATCH v2 4/4] mm/mglru: fix anon-only reclaim evicting file pages when swappiness=max Date: Sat, 18 Jul 2026 17:52:51 +0800 Message-ID: <20260718095251.82937-5-ridong.chen@linux.dev> In-Reply-To: <20260718095251.82937-1-ridong.chen@linux.dev> References: <20260718095251.82937-1-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-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Ridong Chen The previous patch fixes this issue for the traditional LRU, which also exists in MGLRU [1]. Fix this by checking whether swappiness is SWAPPINESS_ANON_ONLY in get_swappiness() first, and returning 0 from get_nr_to_scan() when swappiness is SWAPPINESS_ANON_ONLY and anon pages cannot be reclaimed, to avoid useless work. The test result: Before fix: # cat /sys/kernel/mm/lru_gen/enabled 0x0007 # cat memory.stat anon 204800 file 67108864 ... pgsteal_proactive 0 pgscan_proactive 0 # echo "64M swappiness=3Dmax" > memory.reclaim # cat memory.stat anon 208896 file 0 ... pgsteal_proactive 16384 pgscan_proactive 16384 After fix: # cat memory.stat anon 188416 file 67215360 kernel 1970176 ... pgsteal_proactive 0 pgscan_proactive 0 # echo "64M swappiness=3Dmax" > memory.reclaim -bash: echo: write error: Resource temporarily unavailable # cat memory.stat anon 204800 file 67215360 ... pgsteal_proactive 0 pgscan_proactive 0 [1] https://sashiko.dev/#/patchset/20260717113300.214717-1-ridong.chen@linu= x.dev Fixes: 68a1436bde00 ("mm: add swappiness=3Dmax arg to memory.reclaim for on= ly anon reclaim") Signed-off-by: Ridong Chen Acked-by: Qi Zheng --- mm/vmscan.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e1ef6350a300..240b04f0a21a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2702,6 +2702,10 @@ static int get_swappiness(struct lruvec *lruvec, str= uct scan_control *sc) { struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); + int swappiness =3D sc_swappiness(sc, memcg); + + if (swappiness =3D=3D SWAPPINESS_ANON_ONLY) + return swappiness; =20 if (!sc->may_swap) return 0; @@ -2710,7 +2714,7 @@ static int get_swappiness(struct lruvec *lruvec, stru= ct scan_control *sc) mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH) return 0; =20 - return sc_swappiness(sc, memcg); + return swappiness; } =20 static int get_nr_gens(struct lruvec *lruvec, int type) @@ -4915,6 +4919,14 @@ static long get_nr_to_scan(struct lruvec *lruvec, st= ruct scan_control *sc, struct mem_cgroup *memcg, int swappiness) { unsigned long nr_to_scan, evictable; + struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); + + /* Proactive reclaim: anon-only requested but anon is not reclaimable */ + if (swappiness =3D=3D SWAPPINESS_ANON_ONLY && + !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) { + WARN_ON_ONCE(!sc->proactive); + return 0; + } =20 evictable =3D lruvec_evictable_size(lruvec, swappiness); =20 --=20 2.43.0