[RFC PATCH v2 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd

From: Ionut Nechita

Date: Tue Dec 01 2026 - 08:57:20 EST


Since commit be5e015d107d ("vmstat: skip periodic vmstat update for
isolated CPUs"), vmstat_shepherd() never queues vmstat_update() on CPUs
for which cpu_is_isolated() is true, and quiet_vmstat() only folds the
counters with refresh_cpu_vm_stats(false). In current mainline these
are the CPUs isolated from the scheduler domains (isolcpus=domain or an
isolated cpuset partition); in older kernels such as 6.12 and 6.18,
cpu_is_isolated() also covers nohz_full CPUs (HK_TYPE_TICK).

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 CPU has allocated and freed
enough to 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
6.18-rt kernel with the workload CPUs isolated (isolcpus=domain,nohz,
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. 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).

The same is reproduced on v7.4-rc4 (PREEMPT_RT, 4 vCPUs under KVM,
isolcpus=domain,managed_irq,1-3 nohz_full=1-3): after allocating and
freeing 512 MiB 20 times on CPU 2, its pcp lists held 15180 pages
(59 MiB) and still held all of them 30 seconds later.

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, and evaluates the excess to drain
again under the lock before each batch: the remote CPU may allocate from
or drain its lists while the lock is dropped between batches, and
draining the amount computed before would take its lists below
pcp->high.
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.
No IPI is sent. With this patch, CPU 2 above was back at about
high_min (475 pages) within 30 seconds, decaying at the same 1/8 per
second rate as a housekeeping CPU.

Fixes: 51a755c56dc0 ("mm: tune PCP high automatically")
Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
mm/page_alloc.c | 64 ++++++++++++++++++++++++++++++++++++++++++-------
mm/page_alloc.h | 1 +
mm/vmstat.c | 14 +++++++----
3 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index aa1ed59..4ed3758 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2583,11 +2583,18 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
*/
bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
{
- int high_min, to_drain, to_drain_batched, batch;
+ int high_min, to_drain, batch;
bool todo = false;

+ /* pageset_update() changes these without taking pcp->lock */
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);
/*
* Decrease pcp->high periodically to try to free possible
* idle PCP pages. And, avoid to free too many pages to
@@ -2600,20 +2607,59 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
todo = true;
}

- to_drain = pcp->count - pcp->high;
- while (to_drain > 0) {
- to_drain_batched = min(to_drain, batch);
- pcp_spin_lock_nopin(pcp);
- free_pcppages_bulk(zone, to_drain_batched, pcp, 0);
- pcp_spin_unlock_nopin(pcp);
+ /*
+ * Drain the excess in batches, dropping pcp->lock between them to
+ * bound the time it is held. The excess is evaluated again under the
+ * lock before each batch: the CPU owning the pageset may have
+ * allocated from or drained its lists in the meantime, and draining a
+ * stale amount would take the lists below pcp->high.
+ */
+ while ((to_drain = pcp->count - pcp->high) > 0) {
+ free_pcppages_bulk(zone, min(to_drain, batch), pcp, 0);
todo = true;
-
- to_drain -= to_drain_batched;
+ if (pcp->count <= pcp->high)
+ break;
+ pcp_spin_unlock_nopin(pcp);
+ pcp_spin_lock_nopin(pcp);
}
+ pcp_spin_unlock_nopin(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 917653a..d7f05c2 100644
--- a/mm/page_alloc.h
+++ b/mm/page_alloc.h
@@ -326,6 +326,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 c6beac6..e3257d8 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 = false;

/*
* 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.56.1