* [RFC PATCH 0/1] mm: pcp->high is never decayed on isolated CPUs
@ 2026-11-26 13:44 Ionut Nechita (Wind River)
2026-11-26 13:44 ` [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd Ionut Nechita (Wind River)
0 siblings, 1 reply; 2+ messages in thread
From: Ionut Nechita (Wind River) @ 2026-11-26 13:44 UTC (permalink / raw)
To: Andrew Morton, linux-mm
Cc: Vlastimil Babka, Michal Hocko, Johannes Weiner,
Suren Baghdasaryan, Brendan Jackman, Zi Yan, David Hildenbrand,
Liam R . Howlett, Mike Rapoport, Huang Ying, Marcelo Tosatti,
Frederic Weisbecker, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, linux-rt-devel, linux-kernel, ionut_n2001,
sunlightlinux, Ionut Nechita
From: Ionut Nechita <ionut.nechita@windriver.com>
Hi,
On isolated (nohz_full) CPUs, pcp->high can be raised by PCP
auto-tuning but is never lowered again, and the pages cached on those
pcp lists are never given back. They are neither counted as free
memory nor attributed in /proc/allocinfo, so on a long-running system
they show up as a growing amount of "unaccounted" kernel memory.
This comes from the combination of two changes:
- be5e015d107d ("vmstat: skip periodic vmstat update for isolated
CPUs"): vmstat_shepherd() no longer queues vmstat_update() on
isolated CPUs, and quiet_vmstat() calls refresh_cpu_vm_stats(false),
which skips the pageset work.
- 51a755c56dc0 ("mm: tune PCP high automatically"): pcp->high can grow
up to about managed/8 of the zone, spread over the node's CPUs, and
the only thing that shrinks it is decay_pcp_high(), called from
refresh_cpu_vm_stats(true).
We hit this on a single-node, 64-CPU Sapphire Rapids system (256 GB)
running a PREEMPT_RT kernel with nohz_full=1-31,33-63 and a
containerized telco workload. After 8 days of uptime about 28 GiB were
sitting on the pcp lists, mostly on isolated CPUs, with pcp->count close
to pcp->high_max on most of them:
- Setting vm.percpu_pagelist_high_fraction to a non-zero value lowered
pcp->high, but idle isolated CPUs still held 300-450 MiB each, well
above the new high, because nothing on those CPUs trims the lists.
- Only a remote drain_all_pages() gave the memory back: MemFree went
from 126.5 to 154.5 GiB and MemAvailable from 157 to 185 GiB.
The patch lets vmstat_shepherd(), which runs on a housekeeping CPU, run
decay_pcp_high() remotely for isolated CPUs, under pcp->lock, the same
way drain_pages_zone() already accesses remote pagesets. The remote lock
is only taken when pcp->high is above high_min or pcp->count is above
pcp->high, so an isolated CPU whose pcp lists were never auto-tuned up
is not touched.
This is sent as RFC because I would like feedback on the approach:
1. Is remote decay from vmstat_shepherd() acceptable for isolated
CPUs? It is remote work on behalf of an isolated CPU, although
bounded and only after auto-tuning raised pcp->high. Alternatives I
considered:
- decaying from quiet_vmstat() on the isolated CPU itself, when it
stops the tick; on PREEMPT_RT zone->lock is a sleeping lock, so
freeing pages from that context is not possible there;
- not auto-tuning pcp->high on isolated CPUs at all, which would
penalize isolated workloads that allocate and free heavily.
2. decay_pcp_high() now also takes pcp->lock for the pcp->high update
on the local vmstat_update() path, which was lockless before.
3. The NUMA remote pageset expiry in refresh_cpu_vm_stats() has the
same problem on isolated CPUs. It is not addressed here.
Testing: so far only built with PREEMPT_RT and NO_HZ_FULL (W=1,
checkpatch clean). The analysis above was done on the affected system
with a 6.18-rt based kernel, but the patch itself has not been run on
hardware yet. I am sending it now to get early feedback on the approach
and will follow up with test results.
Thanks,
Ionut
Ionut Nechita (1):
mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd
mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
mm/page_alloc.h | 1 +
mm/vmstat.c | 14 ++++++++++----
3 files changed, 52 insertions(+), 6 deletions(-)
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd
2026-11-26 13:44 [RFC PATCH 0/1] mm: pcp->high is never decayed on isolated CPUs Ionut Nechita (Wind River)
@ 2026-11-26 13:44 ` Ionut Nechita (Wind River)
0 siblings, 0 replies; 2+ messages in thread
From: Ionut Nechita (Wind River) @ 2026-11-26 13:44 UTC (permalink / raw)
To: Andrew Morton, linux-mm
Cc: Vlastimil Babka, Michal Hocko, Johannes Weiner,
Suren Baghdasaryan, Brendan Jackman, Zi Yan, David Hildenbrand,
Liam R . Howlett, Mike Rapoport, Huang Ying, Marcelo Tosatti,
Frederic Weisbecker, Sebastian Andrzej Siewior, Clark Williams,
Steven Rostedt, linux-rt-devel, linux-kernel, ionut_n2001,
sunlightlinux, Ionut Nechita
From: Ionut Nechita <ionut.nechita@windriver.com>
Since commit be5e015d107d ("vmstat: skip periodic vmstat update for
isolated CPUs"), vmstat_shepherd() never queues vmstat_update() on
isolated CPUs, and quiet_vmstat() only folds the counters with
refresh_cpu_vm_stats(false).
Commit 51a755c56dc0 ("mm: tune PCP high automatically") later made
pcp->high grow on demand, up to roughly 1/8 of the zone's managed
memory spread over the node's CPUs, and relies on decay_pcp_high(),
called from refresh_cpu_vm_stats(true), to shrink it again and to give
back the pages cached above it. That path never runs on isolated CPUs.
As a result, once a workload on an isolated (nohz_full) CPU has frees
that push pcp->high up, both pcp->high and the pages on the pcp lists
stay there for good, even after the workload is gone. Those pages are
neither counted in MemFree/MemAvailable nor attributed in
/proc/allocinfo, so the memory looks lost.
On a single-node, 64-CPU Sapphire Rapids system (256 GB) running a
PREEMPT_RT kernel with nohz_full=1-31,33-63 and a containerized telco
workload, about 28 GiB ended up on the pcp lists of the isolated CPUs
(pcp->count close to pcp->high_max on most of them) after 8 days of
uptime and showed up as unaccounted kernel memory. Lowering
vm.percpu_pagelist_high_fraction lowered pcp->high but left idle
isolated CPUs holding 300-450 MiB each; only drain_all_pages() gave the
memory back (MemFree went from 126.5 to 154.5 GiB, MemAvailable from
157 to 185 GiB).
Do the decay remotely: for isolated CPUs, let vmstat_shepherd(), which
runs on a housekeeping CPU, call decay_pcp_high() on their pagesets.
decay_pcp_high() now takes pcp->lock while it adjusts pcp->high, as the
pageset may belong to a remote CPU; the draining part already took it.
Remote pcp access under pcp->lock is already done by drain_pages_zone().
To keep the interference on isolated CPUs minimal, the remote pcp->lock
is only taken when pcp->high is above high_min or pcp->count is above
pcp->high, which is only the case after auto-tuning raised pcp->high.
Fixes: 51a755c56dc0 ("mm: tune PCP high automatically")
Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
---
mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++--
mm/page_alloc.h | 1 +
mm/vmstat.c | 14 ++++++++++----
3 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ce44b8fc4..aa9904eaf 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2586,8 +2586,13 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
int high_min, to_drain, to_drain_batched, batch;
bool todo = false;
- high_min = READ_ONCE(pcp->high_min);
- batch = READ_ONCE(pcp->batch);
+ /*
+ * pcp->lock is taken because the pageset may belong to a remote CPU,
+ * see decay_pcp_high_cpu().
+ */
+ pcp_spin_lock_nopin(pcp);
+ high_min = pcp->high_min;
+ batch = pcp->batch;
/*
* Decrease pcp->high periodically to try to free possible
* idle PCP pages. And, avoid to free too many pages to
@@ -2601,6 +2606,7 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
}
to_drain = pcp->count - pcp->high;
+ pcp_spin_unlock_nopin(pcp);
while (to_drain > 0) {
to_drain_batched = min(to_drain, batch);
pcp_spin_lock_nopin(pcp);
@@ -2614,6 +2620,39 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
return todo;
}
+/*
+ * Isolated CPUs are skipped by vmstat_shepherd() and therefore never run
+ * vmstat_update(), which is the only caller of decay_pcp_high() for the
+ * local pagesets. Once PCP auto-tuning has raised pcp->high on such a CPU,
+ * neither pcp->high nor the pages cached above high_min are ever given back,
+ * and they are not accounted as free memory either.
+ *
+ * Decay the pagesets of @cpu remotely instead. This is called from the
+ * housekeeping CPU running vmstat_shepherd() and only takes the remote
+ * pcp->lock when there is something to do, so an isolated CPU whose
+ * pagesets are at or below high_min sees no interference.
+ */
+void decay_pcp_high_cpu(unsigned int cpu)
+{
+ struct zone *zone;
+
+ for_each_populated_zone(zone) {
+ struct per_cpu_pages *pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu);
+
+ /*
+ * Lockless peek to avoid taking the remote pcp->lock when
+ * there is nothing to decay; a stale value only delays the
+ * decay until the next vmstat_shepherd() run.
+ */
+ if (data_race(pcp->high <= pcp->high_min &&
+ pcp->count <= pcp->high))
+ continue;
+
+ decay_pcp_high(zone, pcp);
+ cond_resched();
+ }
+}
+
#ifdef CONFIG_NUMA
/*
* Called from the vmstat counter updater to drain pagesets of this
diff --git a/mm/page_alloc.h b/mm/page_alloc.h
index 58386512e..85cd958cc 100644
--- a/mm/page_alloc.h
+++ b/mm/page_alloc.h
@@ -334,6 +334,7 @@ static inline int gfp_migratetype(const gfp_t gfp_flags)
#undef GFP_MOVABLE_SHIFT
bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp);
+void decay_pcp_high_cpu(unsigned int cpu);
void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp);
void drain_all_pages(struct zone *zone);
diff --git a/mm/vmstat.c b/mm/vmstat.c
index c6beac6be..5742ca508 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -2148,6 +2148,7 @@ static void vmstat_shepherd(struct work_struct *w)
/* Check processors whose vmstat worker threads have been disabled */
for_each_online_cpu(cpu) {
struct delayed_work *dw = &per_cpu(vmstat_work, cpu);
+ bool isolated;
/*
* In kernel users of vmstat counters either require the precise value and
@@ -2161,13 +2162,18 @@ static void vmstat_shepherd(struct work_struct *w)
* for all isolated CPUs to avoid interference with the isolated workload.
*/
scoped_guard(rcu) {
- if (cpu_is_isolated(cpu))
- continue;
-
- if (!work_busy(&dw->work) && need_update(cpu))
+ isolated = cpu_is_isolated(cpu);
+ if (!isolated && !work_busy(&dw->work) && need_update(cpu))
queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0);
}
+ /*
+ * Isolated CPUs never run vmstat_update(), so the pcp->high
+ * decay it performs has to be done remotely from here.
+ */
+ if (isolated)
+ decay_pcp_high_cpu(cpu);
+
cond_resched();
}
cpus_read_unlock();
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 13:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 13:44 [RFC PATCH 0/1] mm: pcp->high is never decayed on isolated CPUs Ionut Nechita (Wind River)
2026-11-26 13:44 ` [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd Ionut Nechita (Wind River)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®