[PATCH -v4 0/2] mm: vmscan: fix node reclaim ignoring swappiness parameter

Ridong posted 2 patches 1 day, 1 hour ago
include/linux/memcontrol.h |  4 ++--
include/linux/swap.h       | 19 -------------------
mm/memcontrol.c            |  4 ++--
mm/swap.h                  | 13 +++++++++++++
mm/vmscan.c                | 19 +++++++------------
5 files changed, 24 insertions(+), 35 deletions(-)
[PATCH -v4 0/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
Posted by Ridong 1 day, 1 hour ago
From: Ridong Chen <chenridong@xiaomi.com>

The per-node proactive reclaim interface
(/sys/devices/system/node/nodeX/reclaim) accepts a swappiness parameter,
but it is silently ignored when CONFIG_MEMCG is disabled. The root cause
is that sc_swappiness() has separate implementations for CONFIG_MEMCG and
!CONFIG_MEMCG, and the latter never checks proactive_swappiness.

Patch 1 moves mem_cgroup_swappiness() and vm_swappiness out of the public
include/linux/swap.h into the mm-private mm/swap.h, and makes the helper
handle both CONFIG_MEMCG and !CONFIG_MEMCG in a single inline function.
This is a prerequisite for unifying sc_swappiness().

Patch 2 consolidates sc_swappiness() into a single definition that works
regardless of CONFIG_MEMCG, fixing the node reclaim swappiness bug.

---

v3 -> v4:
 - READ_ONCE() was missed when reading memcg->swappiness, add it back.

v2 -> v3:
 - Simplify mem_cgroup_swappiness as suggested by Johannes.  
 - Rebase on the next-20260722

v1 -> v2:
 - Move mem_cgroup_swappiness() and vm_swappiness to mm/swap.h instead of
   include/linux/memcontrol.h. Suggested by Barry Song.
 - Correct fix tag for patch 2.

v1: https://lore.kernel.org/all/20260711091157.306070-1-ridong.chen@linux.dev/

Ridong Chen (2):
  memcg: move mem_cgroup_swappiness and vm_swappiness to mm/swap.h
  mm: vmscan: fix node reclaim ignoring swappiness parameter

 include/linux/memcontrol.h |  4 ++--
 include/linux/swap.h       | 19 -------------------
 mm/memcontrol.c            |  4 ++--
 mm/swap.h                  | 13 +++++++++++++
 mm/vmscan.c                | 19 +++++++------------
 5 files changed, 24 insertions(+), 35 deletions(-)

-- 
2.34.1
Re: [PATCH -v4 0/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
Posted by Andrew Morton 4 hours ago
On Thu, 23 Jul 2026 11:24:32 +0800 Ridong <ridong.chen@linux.dev> wrote:

> From: Ridong Chen <chenridong@xiaomi.com>
> 
> The per-node proactive reclaim interface
> (/sys/devices/system/node/nodeX/reclaim) accepts a swappiness parameter,
> but it is silently ignored when CONFIG_MEMCG is disabled. The root cause
> is that sc_swappiness() has separate implementations for CONFIG_MEMCG and
> !CONFIG_MEMCG, and the latter never checks proactive_swappiness.
> 
> Patch 1 moves mem_cgroup_swappiness() and vm_swappiness out of the public
> include/linux/swap.h into the mm-private mm/swap.h, and makes the helper
> handle both CONFIG_MEMCG and !CONFIG_MEMCG in a single inline function.
> This is a prerequisite for unifying sc_swappiness().
> 
> Patch 2 consolidates sc_swappiness() into a single definition that works
> regardless of CONFIG_MEMCG, fixing the node reclaim swappiness bug.

Thanks, I updated mm.git to this version.

> v3 -> v4:
>  - READ_ONCE() was missed when reading memcg->swappiness, add it back.
> 
> v2 -> v3:
>  - Simplify mem_cgroup_swappiness as suggested by Johannes.  
>  - Rebase on the next-20260722

Here's how v3 plus v4 altered mm.git:


 mm/swap.h |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

--- a/mm/swap.h~b
+++ a/mm/swap.h
@@ -105,18 +105,11 @@ extern int vm_swappiness;
 static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg)
 {
 #ifdef CONFIG_MEMCG_V1
-	/* Cgroup2 doesn't have per-cgroup swappiness */
-	if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
-		return READ_ONCE(vm_swappiness);
-
-	/* root ? */
-	if (mem_cgroup_disabled() || mem_cgroup_is_root(memcg))
-		return READ_ONCE(vm_swappiness);
-
-	return READ_ONCE(memcg->swappiness);
-#else
-	return READ_ONCE(vm_swappiness);
+	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) &&
+	    !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg))
+		return READ_ONCE(memcg->swappiness);
 #endif
+	return READ_ONCE(vm_swappiness);
 }
 
 #ifdef CONFIG_SWAP
_
Re: [PATCH -v4 0/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
Posted by Ridong Chen 3 hours ago

On 7/24/2026 8:34 AM, Andrew Morton wrote:
> On Thu, 23 Jul 2026 11:24:32 +0800 Ridong <ridong.chen@linux.dev> wrote:
> 
>> From: Ridong Chen <chenridong@xiaomi.com>
>>
>> The per-node proactive reclaim interface
>> (/sys/devices/system/node/nodeX/reclaim) accepts a swappiness parameter,
>> but it is silently ignored when CONFIG_MEMCG is disabled. The root cause
>> is that sc_swappiness() has separate implementations for CONFIG_MEMCG and
>> !CONFIG_MEMCG, and the latter never checks proactive_swappiness.
>>
>> Patch 1 moves mem_cgroup_swappiness() and vm_swappiness out of the public
>> include/linux/swap.h into the mm-private mm/swap.h, and makes the helper
>> handle both CONFIG_MEMCG and !CONFIG_MEMCG in a single inline function.
>> This is a prerequisite for unifying sc_swappiness().
>>
>> Patch 2 consolidates sc_swappiness() into a single definition that works
>> regardless of CONFIG_MEMCG, fixing the node reclaim swappiness bug.
> 
> Thanks, I updated mm.git to this version.
> 
Thanks.

-- 
Best regards
Ridong