Re: [PATCH] mm: memcontrol: update state_local when flushing NMI stats

Tao Cui <[email protected]>
Newsgroups org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kernel.vger.stable,org.kvack.linux-mm
Message-ID <[email protected]>

在 2026/7/13 16:50, Guopeng Zhang 写道:
> From: Guopeng Zhang <[email protected]>
> 
> 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 <[email protected]>
> ---
>  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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.