* Re: [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails
2026-11-12 1:32 [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails Shakeel Butt
@ 2026-11-12 2:26 ` Muchun Song
2026-11-12 10:55 ` Vlastimil Babka (SUSE)
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Muchun Song @ 2026-11-12 2:26 UTC (permalink / raw)
To: Shakeel Butt
Cc: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko,
Roman Gushchin, Vlastimil Babka, Meta kernel team, cgroups,
linux-mm, linux-kernel, Chris Mason, stable
> On Nov 12, 2026, at 09:32, Shakeel Butt <shakeel.butt@linux.dev> wrote:
>
> When interrupt code, such as an RCU callback in softirq, runs on top of
> a task that holds the obj stock lock, its trylock fails and the bytes go
> to objcg->nr_charged_bytes. Nothing empties that counter while every CPU
> using the objcg keeps it in its stock, so it can grow without limit.
>
> Users see memory.current and the "kernel" field of memory.stat keep
> growing while the cgroup's real usage does not. With memory.high or
> memory.max set, the cgroup is reclaimed, throttled or even OOM-killed
> for memory it does not use. The counter is 32-bit, so after 4 GiB it
> wraps, and those 4 GiB stay charged to the cgroup and its ancestors
> until reboot, even after the cgroup is removed.
>
> Fix it by uncharging the whole pages in nr_charged_bytes whenever the
> trylock fails.
>
> Fixes: 200577f69f29 ("memcg: objcg stock trylock without irq disabling")
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: stable@vger.kernel.org
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails
2026-11-12 1:32 [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails Shakeel Butt
2026-11-12 2:26 ` Muchun Song
@ 2026-11-12 10:55 ` Vlastimil Babka (SUSE)
2026-11-12 14:30 ` Harry Yoo
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-11-12 10:55 UTC (permalink / raw)
To: Shakeel Butt, Andrew Morton
Cc: Johannes Weiner, David Hildenbrand, Michal Hocko, Roman Gushchin,
Muchun Song, Meta kernel team, cgroups, linux-mm, linux-kernel,
Chris Mason, stable
On 11/12/26 02:32, Shakeel Butt wrote:
> When interrupt code, such as an RCU callback in softirq, runs on top of
> a task that holds the obj stock lock, its trylock fails and the bytes go
> to objcg->nr_charged_bytes. Nothing empties that counter while every CPU
> using the objcg keeps it in its stock, so it can grow without limit.
>
> Users see memory.current and the "kernel" field of memory.stat keep
> growing while the cgroup's real usage does not. With memory.high or
> memory.max set, the cgroup is reclaimed, throttled or even OOM-killed
> for memory it does not use. The counter is 32-bit, so after 4 GiB it
> wraps, and those 4 GiB stay charged to the cgroup and its ancestors
> until reboot, even after the cgroup is removed.
>
> Fix it by uncharging the whole pages in nr_charged_bytes whenever the
> trylock fails.
>
> Fixes: 200577f69f29 ("memcg: objcg stock trylock without irq disabling")
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: stable@vger.kernel.org
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> ---
> mm/memcontrol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index f5f567f7d4a9..091401cecf39 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3553,6 +3553,8 @@ static void __refill_obj_stock(struct obj_cgroup *objcg,
> int i, slot = -1, empty_slot = -1;
>
> if (!stock) {
> + nr_bytes += atomic_read(&objcg->nr_charged_bytes)
> + ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
> nr_pages = nr_bytes >> PAGE_SHIFT;
> nr_bytes = nr_bytes & (PAGE_SIZE - 1);
> atomic_add(nr_bytes, &objcg->nr_charged_bytes);
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails
2026-11-12 1:32 [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails Shakeel Butt
2026-11-12 2:26 ` Muchun Song
2026-11-12 10:55 ` Vlastimil Babka (SUSE)
@ 2026-11-12 14:30 ` Harry Yoo
2026-11-12 15:21 ` Johannes Weiner
2026-11-23 6:25 ` [merged mm-hotfixes-stable] memcg-flush-nr_charged_bytes-when-the-obj-stock-trylock-fails.patch removed from -mm tree Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Harry Yoo @ 2026-11-12 14:30 UTC (permalink / raw)
To: Shakeel Butt
Cc: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko,
Roman Gushchin, Muchun Song, Vlastimil Babka, Meta kernel team,
cgroups, linux-mm, linux-kernel, Chris Mason, stable
On Wed, Nov 11, 2026 at 05:32:20PM -0800, Shakeel Butt wrote:
> When interrupt code, such as an RCU callback in softirq, runs on top of
> a task that holds the obj stock lock, its trylock fails and the bytes go
> to objcg->nr_charged_bytes. Nothing empties that counter while every CPU
> using the objcg keeps it in its stock, so it can grow without limit.
>
> Users see memory.current and the "kernel" field of memory.stat keep
> growing while the cgroup's real usage does not. With memory.high or
> memory.max set, the cgroup is reclaimed, throttled or even OOM-killed
> for memory it does not use. The counter is 32-bit, so after 4 GiB it
> wraps, and those 4 GiB stay charged to the cgroup and its ancestors
> until reboot, even after the cgroup is removed.
>
> Fix it by uncharging the whole pages in nr_charged_bytes whenever the
> trylock fails.
>
> Fixes: 200577f69f29 ("memcg: objcg stock trylock without irq disabling")
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: stable@vger.kernel.org
> ---
Looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
> mm/memcontrol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index f5f567f7d4a9..091401cecf39 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3553,6 +3553,8 @@ static void __refill_obj_stock(struct obj_cgroup *objcg,
> int i, slot = -1, empty_slot = -1;
>
> if (!stock) {
> + nr_bytes += atomic_read(&objcg->nr_charged_bytes)
> + ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
> nr_pages = nr_bytes >> PAGE_SHIFT;
> nr_bytes = nr_bytes & (PAGE_SIZE - 1);
> atomic_add(nr_bytes, &objcg->nr_charged_bytes);
> --
> 2.53.0-Meta
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails
2026-11-12 1:32 [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails Shakeel Butt
` (2 preceding siblings ...)
2026-11-12 14:30 ` Harry Yoo
@ 2026-11-12 15:21 ` Johannes Weiner
2026-11-23 6:25 ` [merged mm-hotfixes-stable] memcg-flush-nr_charged_bytes-when-the-obj-stock-trylock-fails.patch removed from -mm tree Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Johannes Weiner @ 2026-11-12 15:21 UTC (permalink / raw)
To: Shakeel Butt
Cc: Andrew Morton, David Hildenbrand, Michal Hocko, Roman Gushchin,
Muchun Song, Vlastimil Babka, Meta kernel team, cgroups, linux-mm,
linux-kernel, Chris Mason, stable
On Wed, Nov 11, 2026 at 05:32:20PM -0800, Shakeel Butt wrote:
> When interrupt code, such as an RCU callback in softirq, runs on top of
> a task that holds the obj stock lock, its trylock fails and the bytes go
> to objcg->nr_charged_bytes. Nothing empties that counter while every CPU
> using the objcg keeps it in its stock, so it can grow without limit.
>
> Users see memory.current and the "kernel" field of memory.stat keep
> growing while the cgroup's real usage does not. With memory.high or
> memory.max set, the cgroup is reclaimed, throttled or even OOM-killed
> for memory it does not use. The counter is 32-bit, so after 4 GiB it
> wraps, and those 4 GiB stay charged to the cgroup and its ancestors
> until reboot, even after the cgroup is removed.
>
> Fix it by uncharging the whole pages in nr_charged_bytes whenever the
> trylock fails.
>
> Fixes: 200577f69f29 ("memcg: objcg stock trylock without irq disabling")
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: stable@vger.kernel.org
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
^ permalink raw reply [flat|nested] 6+ messages in thread* [merged mm-hotfixes-stable] memcg-flush-nr_charged_bytes-when-the-obj-stock-trylock-fails.patch removed from -mm tree
2026-11-12 1:32 [PATCH] memcg: flush nr_charged_bytes when the obj stock trylock fails Shakeel Butt
` (3 preceding siblings ...)
2026-11-12 15:21 ` Johannes Weiner
@ 2026-11-23 6:25 ` Andrew Morton
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-11-23 6:25 UTC (permalink / raw)
To: mm-commits, vbabka, stable, roman.gushchin, muchun.song, mhocko,
mason, harry, hannes, david, shakeel.butt, akpm
The quilt patch titled
Subject: memcg: flush nr_charged_bytes when the obj stock trylock fails
has been removed from the -mm tree. Its filename was
memcg-flush-nr_charged_bytes-when-the-obj-stock-trylock-fails.patch
This patch was dropped because it was merged into the mm-hotfixes-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Shakeel Butt <shakeel.butt@linux.dev>
Subject: memcg: flush nr_charged_bytes when the obj stock trylock fails
Date: Wed, 11 Nov 2026 17:32:20 -0800
When interrupt code, such as an RCU callback in softirq, runs on top of a
task that holds the obj stock lock, its trylock fails and the bytes go to
objcg->nr_charged_bytes. Nothing empties that counter while every CPU
using the objcg keeps it in its stock, so it can grow without limit.
Users see memory.current and the "kernel" field of memory.stat keep
growing while the cgroup's real usage does not. With memory.high or
memory.max set, the cgroup is reclaimed, throttled or even OOM-killed for
memory it does not use. The counter is 32-bit, so after 4 GiB it wraps,
and those 4 GiB stay charged to the cgroup and its ancestors until reboot,
even after the cgroup is removed.
Fix it by uncharging the whole pages in nr_charged_bytes whenever the
trylock fails.
Link: https://patch.msgid.link/20261112013220.4064478-1-shakeel.butt@linux.dev
Fixes: 200577f69f29 ("memcg: objcg stock trylock without irq disabling")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Chris Mason <mason@kernel.org>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: <stable@vger.kernel.org>
mm/memcontrol.c | 2 ++
1 file changed, 2 insertions(+)
--- a/mm/memcontrol.c~memcg-flush-nr_charged_bytes-when-the-obj-stock-trylock-fails
+++ a/mm/memcontrol.c
@@ -3532,6 +3532,8 @@ static void __refill_obj_stock(struct ob
int i, slot = -1, empty_slot = -1;
if (!stock) {
+ nr_bytes += atomic_read(&objcg->nr_charged_bytes)
+ ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
nr_pages = nr_bytes >> PAGE_SHIFT;
nr_bytes = nr_bytes & (PAGE_SIZE - 1);
atomic_add(nr_bytes, &objcg->nr_charged_bytes);
_
Patches currently in -mm which might be from shakeel.butt@linux.dev are
memcg-move-memoryhigh-enforcement-out-of-try_charge_memcg.patch
memcg-force-charges-from-reclaim-before-trying-the-limits.patch
memcg-use-high_work-for-kernel-threads.patch
memcg-use-high_work-for-remote-charges.patch
memcg-simplify-high-limit-handling-after-a-charge.patch
^ permalink raw reply [flat|nested] 6+ messages in thread