mm: fix node reclaim swappiness handling
Subsystems (6)
cover mm: fix node reclaim swappiness handling
From: Ridong Chen <[email protected]>
The per-node proactive reclaim interface (/sys/devices/system/node/nodeX/reclaim) accepts a swappiness parameter, but it was silently ignored when CONFIG_MEMCG is disabled. The root cause is that sc_swappiness() had separate implementations for CONFIG_MEMCG and !CONFIG_MEMCG, and the latter never checked proactive_swappiness.
Patch 1 moves mem_cgroup_swappiness() from swap.h to memcontrol.h and makes it handle both CONFIG_MEMCG and !CONFIG_MEMCG cases 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.
Ridong Chen (2):
memcg: move mem_cgroup_swappiness to memcontrol.h
mm: vmscan: fix node reclaim ignoring swappiness parameter
include/linux/memcontrol.h | 25 +++++++++++++++++++++++-- include/linux/swap.h | 19 ------------------- mm/memcontrol.c | 3 +-- mm/vmscan.c | 17 +++++++---------- 4 files changed, 31 insertions(+), 33 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 memcg: move mem_cgroup_swappiness to memcontrol.h
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global vm_swappiness and ignores the per-cgroup field.
Guard memcg->swappiness with CONFIG_MEMCG_V1, and move the helper to memcontrol.h where it belongs.
No functional change for v1; v2-only kernels drop the unused field.
--- include/linux/memcontrol.h | 25 +++++++++++++++++++++++-- include/linux/swap.h | 19 ------------------- mm/memcontrol.c | 3 +-- 3 files changed, 24 insertions(+), 23 deletions(-)
include/linux/memcontrol.h +23 -2
@@ -239,8 +239,6 @@ struct mem_cgroup {*/ bool oom_group; -int swappiness; -/* memory.events and memory.events.local */ struct cgroup_file events_file;struct cgroup_file events_local_file;
@@ -318,6 +316,9 @@ struct mem_cgroup {/* List of events which userspace want to receive */ struct list_head event_list;spinlock_t event_list_lock; + +int swappiness; +#endif /* CONFIG_MEMCG_V1 */ struct mem_cgroup_per_node *nodeinfo[];
@@ -365,6 +366,9 @@ enum objext_flags {#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness; +#ifdef CONFIG_MEMCG /* * After the initialization objcg->memcg is always pointing at
@@ -1440,6 +1444,23 @@ static inline void mem_cgroup_flush_workqueue(void) { }static inline int mem_cgroup_init (void ) {return 0 ; }#endif /* CONFIG_MEMCG */ +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); +#endif +} +/* * Extended information for slab objects stored as an array in page->memcg_data * if MEMCG_DATA_OBJEXTS is set.
include/linux/swap.h +0 -19
@@ -372,7 +372,6 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem,pg_data_t *pgdat, unsigned long *nr_scanned);extern unsigned long shrink_all_memory (unsigned long nr_pages); -extern int vm_swappiness;long remove_mapping (struct address_space *mapping,struct folio *folio);#if defined(CONFIG_SYSFS ) && defined(CONFIG_NUMA )
@@ -537,25 +536,7 @@ static inline int add_swap_extent(struct swap_info_struct *sis, }#endif /* CONFIG_SWAP */ #ifdef CONFIG_MEMCG -static inline int mem_cgroup_swappiness (struct mem_cgroup *memcg) -{ -/* 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); -} -void lru_reparent_memcg (struct mem_cgroup *memcg,struct mem_cgroup *parent,int nid); -#else -static inline int mem_cgroup_swappiness (struct mem_cgroup *mem) -{ -return READ_ONCE (vm_swappiness); -}#endif #if defined(CONFIG_SWAP ) && defined(CONFIG_MEMCG ) && defined(CONFIG_BLK_CGROUP )
mm/memcontrol.c +1 -2
@@ -4174,11 +4174,10 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)#endif page_counter_set_high (&memcg->swap,PAGE_COUNTER_MAX );if (parent) { -WRITE_ONCE (memcg->swappiness,mem_cgroup_swappiness (parent)); -page_counter_init (&memcg->memory, &parent->memory, memcg_on_dfl);page_counter_init (&memcg->swap, &parent->swap, false);#ifdef CONFIG_MEMCG_V1 +WRITE_ONCE (memcg->swappiness,mem_cgroup_swappiness (parent)); memcg->memory.track_failcnt = !memcg_on_dfl;WRITE_ONCE (memcg->oom_kill_disable,READ_ONCE (parent->oom_kill_disable));page_counter_init (&memcg->kmem, &parent->kmem, false);
Signature · 1 line
2.43.0
PATCH 2/2 mm: vmscan: fix node reclaim ignoring swappiness parameter
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
sc_swappiness() had two separate definitions depending on CONFIG_MEMCG. The !CONFIG_MEMCG variant simply returned vm_swappiness, ignoring the proactive_swappiness value passed through scan_control. This caused the swappiness parameter written to /sys/devices/system/node/nodeX/reclaim to have no effect when CONFIG_MEMCG is disabled.
Fix this by consolidating sc_swappiness() into a single definition that checks sc->proactive_swappiness first, then falls back to mem_cgroup_swappiness() which already handles both CONFIG_MEMCG and !CONFIG_MEMCG.
Before fix (swappiness=max ignored, mostly file pages reclaimed):
# cat /proc/sys/vm/swappiness
60
# cat /proc/vmstat | grep pgsteal
pgsteal_kswapd 0
pgsteal_direct 0
pgsteal_khugepaged 0
pgsteal_proactive 1840
pgsteal_anon 25
pgsteal_file 1815
# echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim
# cat /proc/vmstat | grep pgsteal
pgsteal_kswapd 0
pgsteal_direct 0
pgsteal_khugepaged 0
pgsteal_proactive 18013
pgsteal_anon 337
pgsteal_file 17676After fix (swappiness=max honored, anon pages reclaimed as expected):
# cat /proc/vmstat | grep pgsteal
pgsteal_kswapd 0
pgsteal_direct 0
pgsteal_khugepaged 0
pgsteal_proactive 0
pgsteal_anon 0
pgsteal_file 0
# echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim
# cat /proc/vmstat | grep pgsteal
pgsteal_kswapd 0
pgsteal_direct 0
pgsteal_khugepaged 0
pgsteal_proactive 16283
pgsteal_anon 16283
pgsteal_file 0--- mm/vmscan.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
mm/vmscan.c +7 -10
@@ -198,6 +198,13 @@ struct scan_control {*/ int vm_swappiness =60 ; +static int sc_swappiness (struct scan_control *sc,struct mem_cgroup *memcg) +{ +if (sc->proactive && sc->proactive_swappiness) +return *sc->proactive_swappiness; +return mem_cgroup_swappiness (memcg); +} +#ifdef CONFIG_MEMCG /* Returns true for reclaim through cgroup limits or cgroup interfaces. */
@@ -239,12 +246,6 @@ static bool writeback_throttling_sane(struct scan_control *sc) return false; } -static int sc_swappiness (struct scan_control *sc,struct mem_cgroup *memcg) -{ -if (sc->proactive && sc->proactive_swappiness) -return *sc->proactive_swappiness; -return mem_cgroup_swappiness (memcg); -}#else static bool cgroup_reclaim (struct scan_control *sc) {
@@ -261,10 +262,6 @@ static bool writeback_throttling_sane(struct scan_control *sc)return true; } -static int sc_swappiness (struct scan_control *sc,struct mem_cgroup *memcg) -{ -return READ_ONCE (vm_swappiness); -}#endif static void set_task_reclaim_state(struct task_struct *task,
Signature · 1 line
2.43.0
Re: [PATCH 2/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
Quoted 52 lines · Ridong Chen
From: Ridong Chen <[email protected]>
sc_swappiness()had two separate definitions depending onCONFIG_MEMCG. The !CONFIG_MEMCG variant simply returnedvm_swappiness, ignoring theproactive_swappinessvalue passed throughscan_control. This caused the swappiness parameter written to/sys/devices/system/node/nodeX/reclaimto have no effect whenCONFIG_MEMCGis disabled.Fix this by consolidating
sc_swappiness()into a single definition that checkssc->proactive_swappinessfirst, then falls back tomem_cgroup_swappiness()which already handles bothCONFIG_MEMCGand !CONFIG_MEMCG.Before fix (swappiness=max ignored, mostly file pages reclaimed):
# cat /proc/sys/vm/swappiness 60 # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 1840 pgsteal_anon 25 pgsteal_file 1815 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 18013 pgsteal_anon 337 pgsteal_file 17676After fix (swappiness=max honored, anon pages reclaimed as expected):
# cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 0 pgsteal_anon 0 pgsteal_file 0 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 16283 pgsteal_anon 16283 pgsteal_file 0
Quoted 2 lines
Fixes 68cd9050d871 ("mm: add swappiness= arg to memory.reclaim")Signed-off-by Ridong Chen <[email protected]>
I would put Fixes: b980077899ea ("mm: introduce per-node proactive reclaim interface") instead. It wasn't a bug before that.
Probably warrants a stable CC for 6.16 as well since this is pretty user-visible breakage.
Re: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
In reply to Ridong ChenQuoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.
Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>
With some nits.
Quoted 1 line
---
[...]
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 7 lines
struct mem_cgroup_per_node *nodeinfo[];include/linux/memcontrol.h +2
-0@@ -365,6 +366,9 @@ enum objext_flags {#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;
This is a bit unusual. I'm not sure whether mm/swap.h would be a more appropriate place for this.
Thanks
Barry
Re: [PATCH 2/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
In reply to Ridong ChenQuoted 53 lines · Ridong Chen
From: Ridong Chen <[email protected]>
sc_swappiness()had two separate definitions depending onCONFIG_MEMCG. The !CONFIG_MEMCG variant simply returnedvm_swappiness, ignoring theproactive_swappinessvalue passed throughscan_control. This caused the swappiness parameter written to/sys/devices/system/node/nodeX/reclaimto have no effect whenCONFIG_MEMCGis disabled.Fix this by consolidating
sc_swappiness()into a single definition that checkssc->proactive_swappinessfirst, then falls back tomem_cgroup_swappiness()which already handles bothCONFIG_MEMCGand !CONFIG_MEMCG.Before fix (swappiness=max ignored, mostly file pages reclaimed):
# cat /proc/sys/vm/swappiness 60 # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 1840 pgsteal_anon 25 pgsteal_file 1815 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 18013 pgsteal_anon 337 pgsteal_file 17676After fix (swappiness=max honored, anon pages reclaimed as expected):
# cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 0 pgsteal_anon 0 pgsteal_file 0 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 16283 pgsteal_anon 16283 pgsteal_file 0
Quoted 2 lines
Fixes 68cd9050d871 ("mm: add swappiness= arg to memory.reclaim")Signed-off-by Ridong Chen <[email protected]>
As pointed out by Johannes, the Fixes tag should be b980077899ea.
Re: [PATCH 2/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
Quoted 54 lines · Barry Song
Quoted 53 lines · Ridong Chen
From: Ridong Chen <[email protected]>
sc_swappiness()had two separate definitions depending onCONFIG_MEMCG. The !CONFIG_MEMCG variant simply returnedvm_swappiness, ignoring theproactive_swappinessvalue passed throughscan_control. This caused the swappiness parameter written to/sys/devices/system/node/nodeX/reclaimto have no effect whenCONFIG_MEMCGis disabled.Fix this by consolidating
sc_swappiness()into a single definition that checkssc->proactive_swappinessfirst, then falls back tomem_cgroup_swappiness()which already handles bothCONFIG_MEMCGand !CONFIG_MEMCG.Before fix (swappiness=max ignored, mostly file pages reclaimed):
# cat /proc/sys/vm/swappiness 60 # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 1840 pgsteal_anon 25 pgsteal_file 1815 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 18013 pgsteal_anon 337 pgsteal_file 17676After fix (swappiness=max honored, anon pages reclaimed as expected):
# cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 0 pgsteal_anon 0 pgsteal_file 0 # echo "64M swappiness=max" > /sys/devices/system/node/node0/reclaim # cat /proc/vmstat | grep pgsteal pgsteal_kswapd 0 pgsteal_direct 0 pgsteal_khugepaged 0 pgsteal_proactive 16283 pgsteal_anon 16283 pgsteal_file 0
Quoted 7 lines
Quoted 2 lines
Fixes 68cd9050d871 ("mm: add swappiness= arg to memory.reclaim")Signed-off-by Ridong Chen <[email protected]>Reviewed-by Barry Song <[email protected]>As pointed out by Johannes, the Fixes tag should be
b980077899ea.
Hi Johannes and Barry,
Thank you for your review. You are right, will update it.
Signature · 2 lines
Best regards Ridong
Re: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
In reply to Barry SongQuoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {
Quoted 8 lines
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 4 lines
include/linux/memcontrol.h +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.
Thank you for your reply.
The vm_swappiness variable is not utilized within mm/swap.c. Furthermore, since memcontrol.h does not include swap.h, retaining the extern int vm_swappiness declaration in mm/swap.h will result in a compilation failure.
Signature · 2 lines
Best regards Ridong
Barry Song
reviewerRe: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
Quoted 36 lines · Ridong Chen
Quoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {Quoted 8 lines
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 4 lines
include/linux/memcontrol.h +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.
Quoted 6 lines
Thank you for your reply.
The
vm_swappinessvariable is not utilized withinmm/swap.c. Furthermore, sincememcontrol.hdoes not includeswap.h, retaining the extern intvm_swappinessdeclaration inmm/swap.hwill result in a compilation failure.
If this is the case, it still seems better to keep extern int vm_swappiness in include/linux/swap.h.
Then we don't need the comment:
/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */
It also makes it clearer that vm_swappiness is an extern variable belonging to the swap module, rather than the memcontrol module.
Thanks
Barry
Barry Song
reviewerRe: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
Quoted 45 lines · Barry Song
Quoted 36 lines · Ridong Chen
Quoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {Quoted 8 lines
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 4 lines
include/linux/memcontrol.h +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.Quoted 6 lines
Thank you for your reply.
The
vm_swappinessvariable is not utilized withinmm/swap.c. Furthermore, sincememcontrol.hdoes not includeswap.h, retaining the extern intvm_swappinessdeclaration inmm/swap.hwill result in a compilation failure.
Quoted 8 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.
BTW, if mem_c_group_swappiness() and vm_swappiness are only used within mm/, could all of these be moved to mm/swap.h and mm/internal.h instead?
We are making a big effort to move many unrelated things out of include/linux/swap.h recently. Could you check?
Re: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
Quoted 55 lines · Barry Song
Quoted 45 lines · Barry Song
Quoted 36 lines · Ridong Chen
Quoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {Quoted 8 lines
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 4 lines
include/linux/memcontrol.h +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.Quoted 6 lines
Thank you for your reply.
The
vm_swappinessvariable is not utilized withinmm/swap.c. Furthermore, sincememcontrol.hdoes not includeswap.h, retaining the extern intvm_swappinessdeclaration inmm/swap.hwill result in a compilation failure.Quoted 8 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.
Quoted 8 lines
BTW, if
mem_c_group_swappiness()andvm_swappinessare only used withinmm/, could all of these be moved tomm/swap.handmm/internal.hinstead?We are making a big effort to move many unrelated things out of
include/linux/swap.hrecently. Could you check?
Good suggestion. Moving them to mm/internal.h makes sense. Will update in the next version.
Signature · 2 lines
Best regards Ridong
Re: [PATCH 2/2] mm: vmscan: fix node reclaim ignoring swappiness parameter
In reply to Johannes WeinerHi Johannes,
Quoted 2 lines
Probably warrants a stable CC for 6.16 as well since this is pretty user-visible breakage.
Thanks for the stable tag suggestion.
I checked the commit baseline:
git name-rev b980077899eab980077899ea tags/v6.17-rc1
So this should be tagged for 6.17+ rather than 6.16. I'll add:
Signature · 2 lines
Best regards Ridong
Barry Song
reviewerRe: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
In reply to Ridong ChenQuoted 63 lines · Ridong Chen
Quoted 59 lines · Barry Song
Quoted 45 lines · Barry Song
Quoted 36 lines · Ridong Chen
Quoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {Quoted 8 lines
include/linux/memcontrol.h enum objext_flags { · line 370
Quoted 4 lines
include/linux/memcontrol.h +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.Quoted 6 lines
Thank you for your reply.
The
vm_swappinessvariable is not utilized withinmm/swap.c. Furthermore, sincememcontrol.hdoes not includeswap.h, retaining the extern intvm_swappinessdeclaration inmm/swap.hwill result in a compilation failure.Quoted 8 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.BTW, if
mem_c_group_swappiness()andvm_swappinessare only used withinmm/, could all of these be moved tomm/swap.handmm/internal.hinstead?
Quoted 7 lines
Quoted 4 lines
We are making a big effort to move many unrelated things out of
include/linux/swap.hrecently. Could you check?Good suggestion. Moving them to
mm/internal.hmakes sense. Will update in the next version.
Either mm/swap.h or mm/internal.h. vm_swappiness probably belongs in mm/swap.h rather than mm/internal.h, right?
BTW, I am not particularly eager about this cleanup; it could be done later as a separate patch.
If you decide not to do the cleanup, I think it would be better to leave "extern int vm_swappiness" in include/linux/swap.h rather than declaring it in include/linux/memcontrol.h?
Best Regards
Barry
Re: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
Quoted 76 lines · Barry Song
Quoted 63 lines · Ridong Chen
Quoted 59 lines · Barry Song
Quoted 45 lines · Barry Song
Quoted 36 lines · Ridong Chen
Quoted 24 lines · Barry Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
The per-memcg swappiness knob is v1-only; v2 always uses global
vm_swappinessand ignores the per-cgroup field.Quoted 7 lines
Guard
memcg->swappinesswithCONFIG_MEMCG_V1, and move the helper tomemcontrol.hwhere it belongs.No functional change for v1; v2-only kernels drop the unused field.
Signed-off-by Ridong Chen <[email protected]>Acked-by Johannes Weiner <[email protected]>Reviewed-by Barry Song <[email protected]>With some nits.
Quoted 1 line
---
[...]
Quoted 3 lines
struct mem_cgroup_per_node *nodeinfo[];(quoted diff) +0
-0@@ -365,6 +366,9 @@ enum objext_flags {Quoted 8 lines
Review enum objext_flags { · line 370
Quoted 4 lines
(quoted diff) +2
-0#define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) +/* Defined in mm/vmscan.c; used by mem_cgroup_swappiness(). */ +extern int vm_swappiness;This is a bit unusual. I'm not sure whether
mm/swap.hwould be a more appropriate place for this.Quoted 6 lines
Thank you for your reply.
The
vm_swappinessvariable is not utilized withinmm/swap.c. Furthermore, sincememcontrol.hdoes not includeswap.h, retaining the extern intvm_swappinessdeclaration inmm/swap.hwill result in a compilation failure.Quoted 8 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.BTW, if
mem_c_group_swappiness()andvm_swappinessare only used withinmm/, could all of these be moved tomm/swap.handmm/internal.hinstead?Quoted 7 lines
Quoted 4 lines
We are making a big effort to move many unrelated things out of
include/linux/swap.hrecently. Could you check?Good suggestion. Moving them to
mm/internal.hmakes sense. Will update in the next version.Either
mm/swap.hormm/internal.h.vm_swappinessprobably belongs inmm/swap.hrather thanmm/internal.h, right?
Quoted 6 lines
BTW, I am not particularly eager about this cleanup; it could be done later as a separate patch.
If you decide not to do the cleanup, I think it would be better to leave "extern int
vm_swappiness" ininclude/linux/swap.hrather than declaring it ininclude/linux/memcontrol.h?
I noticed that some swap-related macros are already defined in mm/internal.h, so I'm planning to place the code right after them for better grouping. Does that work for you?
```
...
#define MEMCG_RECLAIM_MAY_SWAP (1 << 1)
#define MEMCG_RECLAIM_PROACTIVE (1 << 2)
#define MIN_SWAPPINESS 0
#define MAX_SWAPPINESS 200
/* Just reclaim from anon folios in proactive memory reclaim */
#define SWAPPINESS_ANON_ONLY (MAX_SWAPPINESS + 1)
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);
#endif
}
...
```Signature · 2 lines
Best regards Ridong
Barry Song
reviewerRe: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
On Tue, Jul 14, 2026 at 7:31 PM Ridong Chen <[email protected]> wrote:
[...]
Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.BTW, if
mem_c_group_swappiness()andvm_swappinessare only used withinmm/, could all of these be moved tomm/swap.handmm/internal.hinstead?Quoted 7 lines
Quoted 4 lines
We are making a big effort to move many unrelated things out of
include/linux/swap.hrecently. Could you check?Good suggestion. Moving them to
mm/internal.hmakes sense. Will update in the next version.Either
mm/swap.hormm/internal.h.vm_swappinessprobably belongs inmm/swap.hrather thanmm/internal.h, right?BTW, I am not particularly eager about this cleanup; it could be done later as a separate patch.
Quoted 6 lines
Quoted 3 lines
If you decide not to do the cleanup, I think it would be better to leave "extern int
vm_swappiness" ininclude/linux/swap.hrather than declaring it ininclude/linux/memcontrol.h?I noticed that some swap-related macros are already defined in
mm/internal.h, so I'm planning to place the code right after them for better grouping. Does that work for you?
We also have mm/swap.h, which is dedicated to exporting swap-related things. Is it a better place than mm/internal.h?
Quoted 31 lines
```
...
#define MEMCG_RECLAIM_MAY_SWAP (1 << 1)
#define MEMCG_RECLAIM_PROACTIVE (1 << 2)
#define MIN_SWAPPINESS 0
#define MAX_SWAPPINESS 200
/* Just reclaim from anon folios in proactive memory reclaim */
#define SWAPPINESS_ANON_ONLY (MAX_SWAPPINESS + 1)
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);
#endif
}
...
```Re: [PATCH 1/2] memcg: move mem_cgroup_swappiness to memcontrol.h
Quoted 35 lines · Barry Song
On Tue, Jul 14, 2026 at 7:31 PM Ridong Chen <[email protected]> wrote:
[...]
Quoted 32 lines
Quoted 32 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
If this is the case, it still seems better to keep extern int
vm_swappinessininclude/linux/swap.h.Then we don't need the comment:
/* Defined inmm/vmscan.c; used bymem_cgroup_swappiness(). */It also makes it clearer that
vm_swappinessis an extern variable belonging to the swap module, rather than the memcontrol module.BTW, if
mem_c_group_swappiness()andvm_swappinessare only used withinmm/, could all of these be moved tomm/swap.handmm/internal.hinstead?Quoted 7 lines
Quoted 4 lines
We are making a big effort to move many unrelated things out of
include/linux/swap.hrecently. Could you check?Good suggestion. Moving them to
mm/internal.hmakes sense. Will update in the next version.Either
mm/swap.hormm/internal.h.vm_swappinessprobably belongs inmm/swap.hrather thanmm/internal.h, right?BTW, I am not particularly eager about this cleanup; it could be done later as a separate patch.
If you decide not to do the cleanup, I think it would be better to leave "extern int
vm_swappiness" ininclude/linux/swap.hrather than declaring it ininclude/linux/memcontrol.h?
Quoted 7 lines
Quoted 3 lines
I noticed that some swap-related macros are already defined in
mm/internal.h, so I'm planning to place the code right after them for better grouping. Does that work for you?We also have
mm/swap.h, which is dedicated to exporting swap-related things. Is it a better place thanmm/internal.h?
Placing it in mm/swap.h is fine with me. Will update.
```
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -4,6 +4,7 @@
#include <linux/atomic.h> /* for atomic_long_t */
#include <linux/mm.h> /* for PAGE_SHIFT */
+#include <linux/memcontrol.h>
struct mempolicy;
struct swap_iocb;
struct swap_memcg_table;
@@ -76,6 +77,25 @@ enum swap_cluster_flags {
CLUSTER_FLAG_MAX,
};
+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);
+#endif
+}
+
```Signature · 2 lines
Best regards Ridong