Re: [PATCH 4/8] mm: memcontrol: track MEMCG_KMEM per NUMA node
From: Shakeel Butt
Date: Thu May 21 2026 - 13:40:48 EST
On Mon, May 11, 2026 at 10:20:39PM +0200, Alexandre Ghiti wrote:
> This patch gets rid of MEMCG_KMEM and wires all the "generic" functions
> by introducing per-node obj_cgroup objects.
>
> Note that it does not convert the kmem users to proper per-memcg-per-node
> accounting now, this is done in upcoming patches.
>
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
> ---
> include/linux/memcontrol.h | 23 ++++++++++----
> include/linux/mmzone.h | 1 +
> mm/memcontrol.c | 64 ++++++++++++++++++++++++--------------
> mm/vmstat.c | 1 +
> 4 files changed, 59 insertions(+), 30 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 568ab08f42af..17cf823160e4 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -35,7 +35,6 @@ enum memcg_stat_item {
> MEMCG_SWAP = NR_VM_NODE_STAT_ITEMS,
> MEMCG_SOCK,
> MEMCG_PERCPU_B,
> - MEMCG_KMEM,
> MEMCG_ZSWAP_B,
> MEMCG_ZSWAPPED,
> MEMCG_ZSWAP_INCOMP,
> @@ -126,9 +125,10 @@ struct mem_cgroup_per_node {
> struct list_head objcg_list;
>
> #ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
> - /* slab stats for nmi context */
> + /* slab and kmem stats for nmi context */
> atomic_t slab_reclaimable;
> atomic_t slab_unreclaimable;
> + atomic_t kmem;
> #endif
> };
>
> @@ -190,6 +190,7 @@ struct obj_cgroup {
> struct rcu_head rcu;
> };
> bool is_root;
> + int nid;
> };
>
> /*
> @@ -254,10 +255,6 @@ struct mem_cgroup {
> atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
> atomic_long_t memory_events_local[MEMCG_NR_MEMORY_EVENTS];
>
> -#ifdef CONFIG_MEMCG_NMI_SAFETY_REQUIRES_ATOMIC
> - /* MEMCG_KMEM for nmi context */
> - atomic_t kmem_stat;
> -#endif
> /*
> * Hint of reclaim pressure for socket memroy management. Note
> * that this indicator should NOT be used in legacy cgroup mode
> @@ -776,6 +773,20 @@ static inline void obj_cgroup_put(struct obj_cgroup *objcg)
> percpu_ref_put(&objcg->refcnt);
> }
>
> +static inline struct obj_cgroup *obj_cgroup_get_nid(struct obj_cgroup *objcg,
> + int nid)
> +{
> + struct obj_cgroup *nid_objcg;
> + struct mem_cgroup *memcg;
> +
> + rcu_read_lock();
> + memcg = obj_cgroup_memcg(objcg);
> + nid_objcg = rcu_dereference(memcg->nodeinfo[nid]->objcg);
> + rcu_read_unlock();
> +
> + return nid_objcg;
What is guarating the life of nid_objcg?