Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: update state_local when flushing NMI stats
@ 2026-07-13  8:50 Guopeng Zhang
  2026-07-13 10:22 ` Tao Cui
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Guopeng Zhang @ 2026-07-13  8:50 UTC (permalink / raw)
  To: Andrew Morton, Shakeel Butt, Johannes Weiner
  Cc: Michal Hocko, Roman Gushchin, Muchun Song, Vlastimil Babka,
	Alexandre Ghiti, cgroups, linux-mm, linux-kernel, stable,
	Guopeng Zhang

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

flush_nmi_stats() updates state[] for kmem and slab counters but leaves
the corresponding state_local[] counters unchanged. Local kmem and
slab statistics therefore miss updates collected through the NMI-safe
atomic path.

Update state_local[] together with state[].

Fixes: 940b01fc8dc1 ("memcg: nmi safe memcg stats for specific archs")
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
 mm/memcontrol.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 22f55aeb94f3..02599b8b6bd5 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4443,6 +4443,7 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
 		int index = memcg_stats_index(MEMCG_KMEM);
 
 		memcg->vmstats->state[index] += kmem;
+		memcg->vmstats->state_local[index] += kmem;
 		if (parent)
 			parent->vmstats->state_pending[index] += kmem;
 	}
@@ -4460,9 +4461,11 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
 			int index = memcg_stats_index(NR_SLAB_RECLAIMABLE_B);
 
 			lstats->state[index] += slab;
+			lstats->state_local[index] += slab;
 			if (plstats)
 				plstats->state_pending[index] += slab;
 			memcg->vmstats->state[index] += slab;
+			memcg->vmstats->state_local[index] += slab;
 			if (parent)
 				parent->vmstats->state_pending[index] += slab;
 		}
@@ -4471,9 +4474,11 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
 			int index = memcg_stats_index(NR_SLAB_UNRECLAIMABLE_B);
 
 			lstats->state[index] += slab;
+			lstats->state_local[index] += slab;
 			if (plstats)
 				plstats->state_pending[index] += slab;
 			memcg->vmstats->state[index] += slab;
+			memcg->vmstats->state_local[index] += slab;
 			if (parent)
 				parent->vmstats->state_pending[index] += slab;
 		}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: memcontrol: update state_local when flushing NMI stats
  2026-07-13  8:50 [PATCH] mm: memcontrol: update state_local when flushing NMI stats Guopeng Zhang
@ 2026-07-13 10:22 ` Tao Cui
  2026-07-13 11:39 ` Johannes Weiner
  2026-07-14 19:52 ` Shakeel Butt
  2 siblings, 0 replies; 5+ messages in thread
From: Tao Cui @ 2026-07-13 10:22 UTC (permalink / raw)
  To: Guopeng Zhang, Andrew Morton, Shakeel Butt, Johannes Weiner
  Cc: cui.tao, Michal Hocko, Roman Gushchin, Muchun Song,
	Vlastimil Babka, Alexandre Ghiti, cgroups, linux-mm, linux-kernel,
	stable, Guopeng Zhang



在 2026/7/13 16:50, Guopeng Zhang 写道:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
> 
> flush_nmi_stats() updates state[] for kmem and slab counters but leaves
> the corresponding state_local[] counters unchanged. Local kmem and
> slab statistics therefore miss updates collected through the NMI-safe
> atomic path.
> 
> Update state_local[] together with state[].
> 
> Fixes: 940b01fc8dc1 ("memcg: nmi safe memcg stats for specific archs")
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> ---
>  mm/memcontrol.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 22f55aeb94f3..02599b8b6bd5 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4443,6 +4443,7 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
>  		int index = memcg_stats_index(MEMCG_KMEM);
>  
>  		memcg->vmstats->state[index] += kmem;
> +		memcg->vmstats->state_local[index] += kmem;
>  		if (parent)
>  			parent->vmstats->state_pending[index] += kmem;
>  	}
> @@ -4460,9 +4461,11 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
>  			int index = memcg_stats_index(NR_SLAB_RECLAIMABLE_B);
>  
>  			lstats->state[index] += slab;
> +			lstats->state_local[index] += slab;
>  			if (plstats)
>  				plstats->state_pending[index] += slab;
>  			memcg->vmstats->state[index] += slab;
> +			memcg->vmstats->state_local[index] += slab;
>  			if (parent)
>  				parent->vmstats->state_pending[index] += slab;
>  		}
> @@ -4471,9 +4474,11 @@ static void flush_nmi_stats(struct mem_cgroup *memcg, struct mem_cgroup *parent,
>  			int index = memcg_stats_index(NR_SLAB_UNRECLAIMABLE_B);
>  
>  			lstats->state[index] += slab;
> +			lstats->state_local[index] += slab;
>  			if (plstats)
>  				plstats->state_pending[index] += slab;
>  			memcg->vmstats->state[index] += slab;
> +			memcg->vmstats->state_local[index] += slab;
>  			if (parent)
>  				parent->vmstats->state_pending[index] += slab;
>  		}

Looks correct — state_local[] mirrors state[] for this cgroup's own NMI-accounted kmem/slab charges, and pending→local is properly left untouched.

Acked-by: Tao Cui <cuitao@kylinos.cn>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: memcontrol: update state_local when flushing NMI stats
  2026-07-13  8:50 [PATCH] mm: memcontrol: update state_local when flushing NMI stats Guopeng Zhang
  2026-07-13 10:22 ` Tao Cui
@ 2026-07-13 11:39 ` Johannes Weiner
  2026-07-14 19:51   ` Shakeel Butt
  2026-07-14 19:52 ` Shakeel Butt
  2 siblings, 1 reply; 5+ messages in thread
From: Johannes Weiner @ 2026-07-13 11:39 UTC (permalink / raw)
  To: Guopeng Zhang
  Cc: Andrew Morton, Shakeel Butt, Michal Hocko, Roman Gushchin,
	Muchun Song, Vlastimil Babka, Alexandre Ghiti, cgroups, linux-mm,
	linux-kernel, stable, Guopeng Zhang

On Mon, Jul 13, 2026 at 04:50:53PM +0800, Guopeng Zhang wrote:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
> 
> flush_nmi_stats() updates state[] for kmem and slab counters but leaves
> the corresponding state_local[] counters unchanged. Local kmem and
> slab statistics therefore miss updates collected through the NMI-safe
> atomic path.
> 
> Update state_local[] together with state[].
> 
> Fixes: 940b01fc8dc1 ("memcg: nmi safe memcg stats for specific archs")
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>

This issue affects memcg1 but also the workingset shrinker.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

And we should probably CC: stable # 6.15. Shakeel?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: memcontrol: update state_local when flushing NMI stats
  2026-07-13 11:39 ` Johannes Weiner
@ 2026-07-14 19:51   ` Shakeel Butt
  0 siblings, 0 replies; 5+ messages in thread
From: Shakeel Butt @ 2026-07-14 19:51 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Guopeng Zhang, Andrew Morton, Michal Hocko, Roman Gushchin,
	Muchun Song, Vlastimil Babka, Alexandre Ghiti, cgroups, linux-mm,
	linux-kernel, stable, Guopeng Zhang

On Mon, Jul 13, 2026 at 07:39:01AM -0400, Johannes Weiner wrote:
> On Mon, Jul 13, 2026 at 04:50:53PM +0800, Guopeng Zhang wrote:
> > From: Guopeng Zhang <zhangguopeng@kylinos.cn>
> > 
> > flush_nmi_stats() updates state[] for kmem and slab counters but leaves
> > the corresponding state_local[] counters unchanged. Local kmem and
> > slab statistics therefore miss updates collected through the NMI-safe
> > atomic path.
> > 
> > Update state_local[] together with state[].
> > 
> > Fixes: 940b01fc8dc1 ("memcg: nmi safe memcg stats for specific archs")
> > Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> 
> This issue affects memcg1 but also the workingset shrinker.
> 
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> 
> And we should probably CC: stable # 6.15. Shakeel?

Yes it makes sense.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: memcontrol: update state_local when flushing NMI stats
  2026-07-13  8:50 [PATCH] mm: memcontrol: update state_local when flushing NMI stats Guopeng Zhang
  2026-07-13 10:22 ` Tao Cui
  2026-07-13 11:39 ` Johannes Weiner
@ 2026-07-14 19:52 ` Shakeel Butt
  2 siblings, 0 replies; 5+ messages in thread
From: Shakeel Butt @ 2026-07-14 19:52 UTC (permalink / raw)
  To: Guopeng Zhang
  Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Muchun Song, Vlastimil Babka, Alexandre Ghiti, cgroups, linux-mm,
	linux-kernel, stable, Guopeng Zhang

On Mon, Jul 13, 2026 at 04:50:53PM +0800, Guopeng Zhang wrote:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
> 
> flush_nmi_stats() updates state[] for kmem and slab counters but leaves
> the corresponding state_local[] counters unchanged. Local kmem and
> slab statistics therefore miss updates collected through the NMI-safe
> atomic path.
> 
> Update state_local[] together with state[].
> 
> Fixes: 940b01fc8dc1 ("memcg: nmi safe memcg stats for specific archs")
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-14 19:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  8:50 [PATCH] mm: memcontrol: update state_local when flushing NMI stats Guopeng Zhang
2026-07-13 10:22 ` Tao Cui
2026-07-13 11:39 ` Johannes Weiner
2026-07-14 19:51   ` Shakeel Butt
2026-07-14 19:52 ` Shakeel Butt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox