• Roman Gushchin's avatar
    bpf: reparent bpf maps on memcg offlining · 4201d9ab
    Roman Gushchin authored
    The memory consumed by a bpf 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.
    
    v2:
      added a missing const qualifier
    Signed-off-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
    Reviewed-by: default avatarShakeel Butt <shakeelb@google.com>
    Link: https://lore.kernel.org/r/20220711162827.184743-1-roman.gushchin@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    4201d9ab
syscall.c 127 KB