Re: [PATCH v2] memcg: add per-memcg vmalloc stat

From: Shakeel Butt
Date: Thu Dec 30 2021 - 14:06:32 EST


Hi Michal,

On Mon, Dec 27, 2021 at 2:48 AM Michal Hocko <mhocko@xxxxxxxx> wrote:
>
[...]
> > atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
> > + mod_memcg_page_state(area->pages[0], MEMCG_VMALLOC, area->nr_pages);
> >
> > /*
> > * If not enough pages were obtained to accomplish an
>
> Is it safe to assume that the whole area is always charged to the same
> memcg? I am not really deeply familiar with vmalloc internals but is it
> possible that an area could get resized/partially reused with a
> different charging context?

>From what I understand, vmalloc areas are not resized or partially
reused at the moment. There is some ongoing discussion on caching it
but caching would also require updating the accounting part as well.

Regarding the whole area charged to the same memcg, the only way it
may get charged to different memcgs is if the process in which the
allocations are happening is migrated to a different memcg. We can
resolve this by traversing the pages in area->pages array (and use
lruvec based stats instead).

I did contemplate on making this a lruvec stat but decided to start
simple and if we ever need per-node stat then we can easily move to
lruvec based stats. Let me know what you think.

thanks,
Shakeel