mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ionut Nechita (Wind River)" <ionut.nechita@windriver.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: Vlastimil Babka <vbabka@kernel.org>,
	Michal Hocko <mhocko@suse.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Brendan Jackman <brendan.jackman@linux.dev>,
	Zi Yan <ziy@nvidia.com>, David Hildenbrand <david@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	Mike Rapoport <rppt@kernel.org>,
	Huang Ying <ying.huang@linux.alibaba.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
	ionut_n2001@yahoo.com, sunlightlinux@gmail.com,
	Ionut Nechita <ionut.nechita@windriver.com>
Subject: [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd
Date: Thu, 26 Nov 2026 15:44:10 +0200	[thread overview]
Message-ID: <20261126134410.17447-2-ionut.nechita@windriver.com> (raw)
In-Reply-To: <20261126134410.17447-1-ionut.nechita@windriver.com>

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


      reply	other threads:[~2026-11-26 13:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126134410.17447-2-ionut.nechita@windriver.com \
    --to=ionut.nechita@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=brendan.jackman@linux.dev \
    --cc=clrkwllms@kernel.org \
    --cc=david@kernel.org \
    --cc=frederic@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=ionut_n2001@yahoo.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mhocko@suse.com \
    --cc=mtosatti@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sunlightlinux@gmail.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®