From: Rik van Riel <riel@surriel.com>
To: linux-kernel@vger.kernel.org
Cc: Rik van Riel <riel@surriel.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
cgroups@vger.kernel.org, linux-mm@kvack.org,
kernel-team@meta.com, stable@vger.kernel.org
Subject: [PATCH] mm/memcontrol: avoid stuck FLUSHING_CACHED_CHARGE bit on isolated cpus
Date: Fri, 28 Aug 2026 09:46:21 -0400 [thread overview]
Message-ID: <a611f2bc40d30f9c14a6f41b173185975c46a203.1787890328.git.riel@surriel.com> (raw)
In-Reply-To: <cover.1787890328.git.riel@surriel.com>
drain_all_stock() can leave FLUSHING_CACHED_CHARGE set after the
work is dropped. It sets the bit before checking isolation and
schedule_drain_work() checks isolation and queues in a separate RCU
critical section, so housekeeping_update()'s synchronize_rcu() can
race the second check.
drain_local_stock() only clears the bit for work that ran, so the bit
remains set and the stock is never drained again.
Reorganize the drain_all_stock() loop, reducing nesting, splitting
out local vs remote cpu handling, and skipping everything on isolated
cpus, which solves the stuck FLUSHING_CACHED_CHARGE flag.
Fixes: 6a792697a53a ("memcg: do not drain charge pcp caches on remote isolated cpus")
Cc: stable@vger.kernel.org
Assisted-by: Hermes:muse-spark-1.2
Signed-off-by: Rik van Riel <riel@surriel.com>
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a660ea0f820b..b0d8ec042d48 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2330,19 +2330,6 @@ static bool obj_stock_should_drain(struct obj_stock_pcp *stock,
return true;
}
-static void schedule_drain_work(int cpu, struct work_struct *work)
-{
- /*
- * Protect housekeeping cpumask read and work enqueue together
- * in the same RCU critical section so that later cpuset isolated
- * partition update only need to wait for an RCU GP and flush the
- * pending work on newly isolated CPUs.
- */
- guard(rcu)();
- if (!cpu_is_isolated(cpu))
- queue_work_on(cpu, memcg_wq, work);
-}
-
/*
* Drains all per-CPU charge caches for given root_memcg resp. subtree
* of the hierarchy under it.
@@ -2366,19 +2353,23 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
struct memcg_stock_pcp *memcg_st = &per_cpu(memcg_stock, cpu);
struct obj_stock_pcp *obj_st = &per_cpu(obj_stock, cpu);
- if (memcg_stock_should_drain(memcg_st, root_memcg)) {
- if (cpu == curcpu)
+ if (cpu == curcpu) {
+ if (memcg_stock_should_drain(memcg_st, root_memcg))
drain_local_memcg_stock(&memcg_st->work);
- else
- schedule_drain_work(cpu, &memcg_st->work);
- }
-
- if (obj_stock_should_drain(obj_st, root_memcg)) {
- if (cpu == curcpu)
+ if (obj_stock_should_drain(obj_st, root_memcg))
drain_local_obj_stock(&obj_st->work);
- else
- schedule_drain_work(cpu, &obj_st->work);
+ continue;
}
+
+ /* Pairs with RCU barrier in housekeeping_update(). */
+ guard(rcu)();
+ if (cpu_is_isolated(cpu))
+ continue;
+
+ if (memcg_stock_should_drain(memcg_st, root_memcg))
+ queue_work_on(cpu, memcg_wq, &memcg_st->work);
+ if (obj_stock_should_drain(obj_st, root_memcg))
+ queue_work_on(cpu, memcg_wq, &obj_st->work);
}
migrate_enable();
mutex_unlock(&percpu_charge_mutex);
next prev parent reply other threads:[~2026-08-28 13:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 13:46 [PATCH 0/2] mm/memcontrol: fix stuck FLUSHING_CACHED_CHARGE bit on isolated cpus Rik van Riel
2026-08-28 13:46 ` [PATCH] mm/memcontrol: extract stock drain predicates into helpers Rik van Riel
2026-08-28 13:46 ` Rik van Riel [this message]
2026-08-28 14:25 ` [PATCH] mm/memcontrol: avoid stuck FLUSHING_CACHED_CHARGE bit on isolated cpus Michal Hocko
2026-08-28 14:56 ` Rik van Riel
2026-08-28 15:41 ` Shakeel Butt
2026-08-28 16:13 ` Rik van Riel
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=a611f2bc40d30f9c14a6f41b173185975c46a203.1787890328.git.riel@surriel.com \
--to=riel@surriel.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
/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