On Fri, Jul 08, 2022 at 05:28:58PM -0700, Roman Gushchin wrote: > The memory consumed by a mpf map is always accounted to the memory > cgroup of the process which created the map. The map can outlive > the memory cgroup if it's used by processes in other cgroups or > is pinned on bpffs. In this case the map pins the original cgroup > in the dying state. > > For other types of objects (slab objects, non-slab kernel allocations, > percpu objects and recently LRU pages) there is a reparenting process > implemented: on cgroup offlining charged objects are getting > reassigned to the parent cgroup. Because all charges and statistics > are fully recursive it's a fairly cheap operation. > > For efficiency and consistency with other types of objects, let's do > the same for bpf maps. Fortunately thanks to the objcg API, the > required changes are minimal. > > Please, note that individual allocations (slabs, percpu and large > kmallocs) already have the reparenting mechanism. This commit adds > it to the saved map->memcg pointer by replacing it to map->objcg. > Because dying cgroups are not visible for a user and all charges are > recursive, this commit doesn't bring any behavior changes for a user. > > Signed-off-by: Roman Gushchin <roman.gushchin@xxxxxxxxx> Reviewed-by: Shakeel Butt <shakeelb@xxxxxxxxxx>