Re: [PATCH v5 10/16] mm: list_lru: allocate list_lru_one only when needed

From: Michal Koutný
Date: Wed Jan 19 2022 - 04:33:17 EST


On Tue, Jan 18, 2022 at 08:05:44PM +0800, Muchun Song <songmuchun@xxxxxxxxxxxxx> wrote:
> I have thought about this. It's a little different to rely on objcg
> reparenting since the user can get memcg from objcg and
> then does not realize the memcg has reparented.

When you pointed that out, I'm now also wondering how
memcg_list_lru_alloc() would be synchronized against
reparenting/renumbering of kmemcg_ids. What I suspect is that newly
allocated mlru may be stored into the xarray with a stale kmemcg_id.

> Maybe holding css_set_lock can do that. I do not think this
> is a good choice.

I agree, it doesn't sound well.

> Do you have any thoughts about this?

Thoughts / questions of what I don't undestand well:
- Why do you allocate mlrus for all ancestors in memcg_list_lru_alloc()?
- It'd be sufficient to allocate just for the current memcg.
- Possibly allocate ancestors upon reparenting (to simplify the
allocation from slab_pre_alloc_hook itself).

- What is the per-kmemcg_id lookup good for?
- I observe most calls of list_lru_from_memcg_idx() come from callers
that know memcg (or even objcg).
- The non-specific use case seems list_lru_walk_node() working with
per-node and not per-memcg projection.
- Consequently that is only used over all nodes anyway
(list_lru_walk().
- The idea behind this question is -- attach the list_lrus to
obj_cgroup (and decomission the kmemcg_id completely).
(Not necessarily part of this series but independent approach.)

Thanks,
Michal