Re: [PATCH v2 10/28] mm: memcg: introduce mod_lruvec_memcg_state()

From: Johannes Weiner
Date: Mon Feb 03 2020 - 12:42:11 EST


On Mon, Jan 27, 2020 at 09:34:35AM -0800, Roman Gushchin wrote:
> To prepare for per-object accounting of slab objects, let's introduce
> __mod_lruvec_memcg_state() and mod_lruvec_memcg_state() helpers,
> which are similar to mod_lruvec_state(), but do not update global
> node counters, only lruvec and per-cgroup.
>
> It's necessary because soon node slab counters will be used for
> accounting of all memory used by slab pages, however on memcg level
> only the actually used memory will be counted. The free space will be
> shared between all cgroups, so it can't be accounted to any
> specific cgroup.

Makes perfect sense. However, I think the existing mod_lruvec_state()
has a bad and misleading name, and adding to it in the same style
makes things worse.

Can we instead rename lruvec_state to node_memcg_state to capture that
it changes all levels. And then do the following, clean API?

- node_state for node only

- memcg_state for memcg only

- lruvec_state for lruvec only

- node_memcg_state convenience wrapper to change node, memcg, lruvec counters

You can then open-code the disjunct node and memcg+lruvec counters.

[ Granted, lruvec counters are never modified on their own - always in
conjunction with the memcg counters. And frankly, the only memcg
counters that are modified *without* the lruvec counter-part are the
special-case MEMCG_ counters.

It would be nice to have 1) a completely separate API for the MEMCG_
counters; and then 2) the node API for node and 3) a cgroup API for
memcg+lruvec VM stat counters that allow you to easily do the
disjunct accounting for slab memory.

But I can't think of poignant names for these. At least nothing that
would be better than separate memcg_state and lruvec_state calls. ]