mm: vmscan: don't count per-node proactive reclaim as memory pressure
Subsystems (4)
PATCH 1/1 mm: vmscan: don't count per-node proactive reclaim as memory pressure
From: Vernon Yang <[email protected]>
When the cgroup has no memory pressure at all, writing to /sys/devices/system/nodeX/reclaim triggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.
Due to this reclaim is performed in the context of the write(), accounted as memory pressure on the writer, like
commit e22c6ed90aa9 ("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.
The Documentation/ABI/stable/sysfs-devices-node documentation also notes that "This interface is equivalent to the memcg variant."
This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.
I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
[1] https://github.com/vernon2gh/app_and_module/tree/main/reclaim_node_psi
--- mm/vmscan.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
mm/vmscan.c +5 -4
@@ -7988,13 +7988,10 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat, {struct task_struct *p = current;unsigned int noreclaim_flag; -unsigned long pflags;trace_mm_vmscan_node_reclaim_begin (pgdat->node_id, sc->order, sc->gfp_mask); -cond_resched (); -psi_memstall_enter (&pflags);delayacct_freepages_start ();fs_reclaim_acquire (sc->gfp_mask);/*
@@ -8011,7 +8008,6 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat,memalloc_noreclaim_restore (noreclaim_flag);fs_reclaim_release (sc->gfp_mask);delayacct_freepages_end (); -psi_memstall_leave (&pflags);trace_mm_vmscan_node_reclaim_end (sc->nr_reclaimed,NULL );
@@ -8021,6 +8017,7 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat,unsigned long node_reclaim (struct pglist_data *pgdat,gfp_t gfp_mask,unsigned int order) {unsigned long ret; +unsigned long pflags;/* Minimum pages needed in order to stay on node */ const unsigned long nr_pages =1 << order;struct scan_control sc = {
@@ -8067,7 +8064,10 @@ unsigned long node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned iif (test_and_set_bit_lock (PGDAT_RECLAIM_LOCKED , &pgdat->flags))return 0 ; +cond_resched (); +psi_memstall_enter (&pflags); ret =__node_reclaim (pgdat, nr_pages, &sc); +psi_memstall_leave (&pflags);clear_bit_unlock (PGDAT_RECLAIM_LOCKED , &pgdat->flags);if (ret >= nr_pages)
@@ -8193,6 +8193,7 @@ int user_proactive_reclaim(char *buf, &pgdat->flags))return -EBUSY ; +cond_resched (); reclaimed =__node_reclaim (pgdat, batch_size, &sc);clear_bit_unlock (PGDAT_RECLAIM_LOCKED , &pgdat->flags); }
Signature · 1 line
2.53.0
Barry Song
reviewerQuoted 34 lines · Vernon Yang
From: Vernon Yang <[email protected]>
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Quoted 6 lines
[1] https://github.com/vernon2gh/app_and_module/tree/main/reclaim_node_psi
Fixes b980077899ea ("mm: introduce per-node proactive reclaim interface")Signed-off-by Vernon Yang <[email protected]>---
This seems to be a valid concern. Personally, I don't like having the code depend on whether __node_reclaim() and node_reclaim() are called from proactive reclaim or page allocation.
Can't we check whether sc->proactive is true? Am I missing something?
Best Regards
Barry
Quoted 42 lines · Barry Song
Quoted 34 lines · Vernon Yang
From: Vernon Yang <[email protected]>
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Quoted 6 lines
[1] https://github.com/vernon2gh/app_and_module/tree/main/reclaim_node_psi
Fixes b980077899ea ("mm: introduce per-node proactive reclaim interface")Signed-off-by Vernon Yang <[email protected]>---
Quoted 7 lines
This seems to be a valid concern. Personally, I don't like having the code depend on whether
__node_reclaim()andnode_reclaim()are called from proactive reclaim or page allocation.Can't we check whether
sc->proactiveis true? Am I missing something?
It is also fine to directly check sc->proactive in __node_reclaim().
I chose the current coding because a previous similar fix commit e22c6ed90aa9 was written this way, and it is also very clear.
Of course, it depends on everyone's preference. If everyone prefers to directly check sc->proactive, please let me know clearly. Thanks!
--
Cheers,
Vernon
Barry Song
reviewerQuoted 52 lines · Vernon Yang
Quoted 42 lines · Barry Song
Quoted 34 lines · Vernon Yang
From: Vernon Yang <[email protected]>
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Quoted 6 lines
[1] https://github.com/vernon2gh/app_and_module/tree/main/reclaim_node_psi
Fixes b980077899ea ("mm: introduce per-node proactive reclaim interface")Signed-off-by Vernon Yang <[email protected]>---
Quoted 7 lines
This seems to be a valid concern. Personally, I don't like having the code depend on whether
__node_reclaim()andnode_reclaim()are called from proactive reclaim or page allocation.Can't we check whether
sc->proactiveis true? Am I missing something?
Quoted 7 lines
It is also fine to directly check
sc->proactivein__node_reclaim().I chose the current coding because a previous similar fix commit
e22c6ed90aa9was written this way, and it is also very clear.Of course, it depends on everyone's preference. If everyone prefers to directly check
sc->proactive, please let me know clearly. Thanks!
I personally think the following is much more explicit than the current implicit code based on path dependency. no?
mm/vmscan.c +0 -0
@@ -7997,7 +7997,8 @@ static unsigned long __node_reclaim(struct
pglist_data *pgdat,
sc->gfp_mask);
cond_resched();
- psi_memstall_enter(&pflags);
+ if (!sc->proactive)
+ psi_memstall_enter(&pflags);
delayacct_freepages_start();
fs_reclaim_acquire(sc->gfp_mask);
/*
@@ -8014,7 +8015,8 @@ static unsigned long __node_reclaim(struct
pglist_data *pgdat,
memalloc_noreclaim_restore(noreclaim_flag);
fs_reclaim_release(sc->gfp_mask);
delayacct_freepages_end();- psi_memstall_leave(&pflags);
+ if (!sc->proactive)
+ psi_memstall_leave(&pflags);
trace_mm_vmscan_node_reclaim_end(sc->nr_reclaimed, NULL);
Quoted 4 lines
--
Cheers,
Vernon
Quoted 55 lines · Barry Song
Quoted 54 lines · Vernon Yang
Quoted 42 lines · Barry Song
Quoted 34 lines · Vernon Yang
From: Vernon Yang <[email protected]>
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Quoted 6 lines
[1] https://github.com/vernon2gh/app_and_module/tree/main/reclaim_node_psi
Fixes b980077899ea ("mm: introduce per-node proactive reclaim interface")Signed-off-by Vernon Yang <[email protected]>---
Quoted 7 lines
This seems to be a valid concern. Personally, I don't like having the code depend on whether
__node_reclaim()andnode_reclaim()are called from proactive reclaim or page allocation.Can't we check whether
sc->proactiveis true? Am I missing something?It is also fine to directly check
sc->proactivein__node_reclaim().
Quoted 8 lines
Quoted 5 lines
I chose the current coding because a previous similar fix commit
e22c6ed90aa9was written this way, and it is also very clear.Of course, it depends on everyone's preference. If everyone prefers to directly check
sc->proactive, please let me know clearly. Thanks!I personally think the following is much more explicit than the current implicit code based on path dependency. no?
Yes, both implementations are fine with me.
I usually wait 1~2 weeks to give all maintainer/reviewer to review. As long as no one raises objections during that period, all suggestions will be accepted in the next version, don't worry. Thanks for your suggestions!
Quoted 26 lines
mm/vmscan.c +2
-1@@ -7997,7 +7997,8 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat, sc->gfp_mask);cond_resched (); -psi_memstall_enter (&pflags); +if (!sc->proactive) +psi_memstall_enter (&pflags);delayacct_freepages_start ();fs_reclaim_acquire (sc->gfp_mask);/*mm/vmscan.c +2
-1@@ -8014,7 +8015,8 @@ static unsigned long __node_reclaim(structpglist_data *pgdat,memalloc_noreclaim_restore (noreclaim_flag );fs_reclaim_release (sc->gfp_mask);delayacct_freepages_end (); -psi_memstall_leave (&pflags); +if (!sc->proactive) +psi_memstall_leave (&pflags);trace_mm_vmscan_node_reclaim_end (sc->nr_reclaimed,NULL );
Andrew Morton
maintainerQuoted 9 lines · On Mon, 5 Oct 2026 14:22:36 +0800 Vernon Yang <[email protected]> wrote:
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.
What is this?
Quoted 20 lines
The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Mon, 5 Oct 2026 14:22:36 +0800 Vernon Yang <[email protected]> wrote:
When the cgroup has no memory pressure at all, writing to
/sys/devices/system/nodeX/reclaimtriggers proactive reclaim on NUMA node, causing increase in the writer cgroup's memory PSI.
Quoted 7 lines
Quoted 5 lines
Due to this reclaim is performed in the context of the
write(), accounted as memory pressure on the writer, like
commite22c6ed90aa9("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). This is unexpected, the phenomenon resembling senpai will appear again.What is this?
This is commit e22c6ed90aa9, which addresses a scenario mentioned in memory limits of a cgroup, in detail as follows:
Currently, this reclaim activity is accounted as memory pressure in the cgroup that the writer(!) belongs to. This is unexpected. It specifically causes problems for senpai
(https://github.com/facebookincubator/senpai), which is an agent that routinely adjusts the memory limits and performs associated reclaim work in tens or even hundreds of cgroups running on the host. The cgroup that senpai is running in itself will report elevated levels of memory pressure, even though it itself is under no memory shortage or any sort of distress.
This is just to explain that similar scenarios will continue to occur, only this time it is for the /sys/devices/system/nodeX/reclaim knob.
--
Cheers,
Vernon
Quoted 21 lines
Quoted 20 lines
The
Documentation/ABI/stable/sysfs-devices-nodedocumentation also notes that "This interface is equivalent to the memcg variant."This patch unifies the semantics of the memcg and node interfaces:
per-node proactive reclaim is no longer counted as memory pressure, and the per-node proactive reclaim interface no longer produces phantom pressure.I ran demo[1] that performs per-node proactive reclaim 10000 times in qemu, writer cgroup memory.pressure as follows:
without patch:
some avg10=31.53 avg60=13.42 avg300=3.31 total=10602985 full avg10=31.53 avg60=13.42 avg300=3.31 total=10602985
with patch:
some avg10=9.59 avg60=3.41 avg300=0.81 total=2686221 full avg10=9.59 avg60=3.41 avg300=0.81 total=2686221
Andrew Morton
maintainerQuoted 8 lines · On Mon, 5 Oct 2026 18:10:45 +0800 Vernon Yang <[email protected]> wrote:
the phenomenon resembling
Quoted 3 lines
Quoted 1 line
senpai will appear again.
What is this?
This is commit
e22c6ed90aa9, which addresses a scenario mentioned in memory limits of a cgroup, in detail as follows:
Quoted 9 lines
Currently, this reclaim activity is accounted as memory pressure in the cgroup that the writer(!) belongs to. This is unexpected. It specifically causes problems for senpai
(https://github.com/facebookincubator/senpai), which is an agent that routinely adjusts the memory limits and performs associated reclaim work in tens or even hundreds of cgroups running on the host. The cgroup that senpai is running in itself will report elevated levels of memory pressure, even though it itself is under no memory shortage or any sort of distress.
ah, thanks. It's arguably appropriate that the procfs-writing process gets blamed for the I/O which it caused, but clearly that's the wrong place to account the memory pressure.