Re: [PATCH v2 3/7] memcg: reduce memory for the lruvec and memcg stats

From: Shakeel Butt
Date: Mon Apr 29 2024 - 16:13:23 EST


On Mon, Apr 29, 2024 at 10:35:38AM -0700, T.J. Mercier wrote:
> On Fri, Apr 26, 2024 at 5:37 PM Shakeel Butt <shakeel.butt@xxxxxxxxx> wrote:
> >
[...]
> > +
> > +static const unsigned int memcg_stat_items[] = {
> > + MEMCG_SWAP,
> > + MEMCG_SOCK,
> > + MEMCG_PERCPU_B,
> > + MEMCG_VMALLOC,
> > + MEMCG_KMEM,
> > + MEMCG_ZSWAP_B,
> > + MEMCG_ZSWAPPED,
> > +};
>
> Unsigned for these? All the values are positive now, but I don't think
> we'll get a build warning if a negative one ever got added, just a
> crash or corruption. BUG_ON in init_memcg_stats if a
> memcg_stat_items[i] < 0?

We are depending on NR_VM_NODE_STAT_ITEMS to tell the number of elements
for vmstats. So, I think there is an implicit assumption that there are
no negative enums in enum node_stat_item. So, if we want to verify those
assumptions then we should be adding such warnings/build-bugs in vmstat
first.