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

From: Tao Cui

Date: Mon Jul 13 2026 - 06:22:58 EST




在 2026/7/13 16:50, Guopeng Zhang 写道:
> From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> ---
> 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@xxxxxxxxxx>