From: Michal Hocko <mhocko@suse.com>
To: Rik van Riel <riel@surriel.com>
Cc: linux-kernel@vger.kernel.org,
Johannes Weiner <hannes@cmpxchg.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
Subject: Re: [PATCH v2] mm/memcontrol: fix stuck FLUSHING_CACHED_CHARGE bit on isolated cpus
Date: Mon, 31 Aug 2026 09:29:11 +0200 [thread overview]
Message-ID: <apUtRwonTCUF07u5@tiehlicka> (raw)
In-Reply-To: <20260828135036.7d44361f@fangorn>
On Fri 28-08-26 13:50:36, Rik van Riel wrote:
> When drain_all_stock() sets FLUSHING_CACHED_CHARGE before checking
> isolation, schedule_drain_work() can drop the work in a separate RCU
> critical section, and housekeeping_update()'s synchronize_rcu() can race
> that second check, leaving the flag set.
>
> drain_local_stock() only clears the bit for work that ran, so the flag
> remains set and the stock is never drained again.
>
> Have schedule_drain_work() return whether the work was queued, and clear
> FLUSHING_CACHED_CHARGE in drain_all_stock() when the remote CPU is
> isolated, so future drains can retry.
>
> Fixes: 6a792697a53a ("memcg: do not drain charge pcp caches on remote isolated cpus")
> Cc: stable@vger.kernel.org
> Suggested-by: Michal Hocko <mhocko@suse.com>
> Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
> Signed-off-by: Rik van Riel <riel@surriel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks
> ---
> v2: use the approach suggested by Michal and Shakeel
>
> Link: https://lore.kernel.org/all/cover.1787890328.git.riel@surriel.com/
>
> mm/memcontrol.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1271d390b617..309398e943ca 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2306,7 +2306,7 @@ static bool is_memcg_drain_needed(struct memcg_stock_pcp *stock,
> return flush;
> }
>
> -static void schedule_drain_work(int cpu, struct work_struct *work)
> +static bool schedule_drain_work(int cpu, struct work_struct *work)
> {
> /*
> * Protect housekeeping cpumask read and work enqueue together
> @@ -2315,8 +2315,11 @@ static void schedule_drain_work(int cpu, struct work_struct *work)
> * pending work on newly isolated CPUs.
> */
> guard(rcu)();
> - if (!cpu_is_isolated(cpu))
> - queue_work_on(cpu, memcg_wq, work);
> + if (cpu_is_isolated(cpu))
> + return false;
> +
> + queue_work_on(cpu, memcg_wq, work);
> + return true;
> }
>
> /*
> @@ -2348,8 +2351,9 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
> &memcg_st->flags)) {
> if (cpu == curcpu)
> drain_local_memcg_stock(&memcg_st->work);
> - else
> - schedule_drain_work(cpu, &memcg_st->work);
> + else if (!schedule_drain_work(cpu, &memcg_st->work))
> + clear_bit(FLUSHING_CACHED_CHARGE,
> + &memcg_st->flags);
> }
>
> if (!test_bit(FLUSHING_CACHED_CHARGE, &obj_st->flags) &&
> @@ -2358,8 +2362,9 @@ void drain_all_stock(struct mem_cgroup *root_memcg)
> &obj_st->flags)) {
> if (cpu == curcpu)
> drain_local_obj_stock(&obj_st->work);
> - else
> - schedule_drain_work(cpu, &obj_st->work);
> + else if (!schedule_drain_work(cpu, &obj_st->work))
> + clear_bit(FLUSHING_CACHED_CHARGE,
> + &obj_st->flags);
> }
> }
> migrate_enable();
> --
> 2.55.0
>
>
--
Michal Hocko
SUSE Labs
prev parent reply other threads:[~2026-08-31 7:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 17:50 [PATCH v2] mm/memcontrol: fix stuck FLUSHING_CACHED_CHARGE bit on isolated cpus Rik van Riel
2026-08-28 18:56 ` Shakeel Butt
2026-08-28 19:20 ` Andrew Morton
2026-08-28 19:26 ` Shakeel Butt
2026-08-28 19:55 ` Andrew Morton
2026-08-28 20:01 ` Rik van Riel
2026-08-31 7:29 ` Michal Hocko [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=apUtRwonTCUF07u5@tiehlicka \
--to=mhocko@suse.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=muchun.song@linux.dev \
--cc=riel@surriel.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
/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