Skip to content
  • Johannes Weiner's avatar
    mm: memcontrol: clean up alloc, online, offline, free functions · 0b8f73e1
    Johannes Weiner authored
    
    
    The creation and teardown of struct mem_cgroup is fairly messy and
    that has attracted mistakes and subtle bugs before.
    
    The main cause for this is that there is no clear model about what
    needs to happen when, and that attracts more chaos. So create one:
    
    1. mem_cgroup_alloc() should allocate struct mem_cgroup and its
       auxiliary members and initialize work items, locks etc. so that the
       object it returns is fully initialized and in a neutral state.
    
    2. mem_cgroup_css_alloc() will use mem_cgroup_alloc() to obtain a new
       memcg object and configure it and the system according to the role
       of the new memory-controlled cgroup in the hierarchy.
    
    3. mem_cgroup_css_online() is no longer needed to synchronize with
       iterators, but it verifies css->id which isn't available earlier.
    
    4. mem_cgroup_css_offline() implements stuff that needs to happen upon
       the user-visible destruction of a cgroup, which includes stopping
       all user interfacing as well as releasing certain structures when
       continued memory consumption would be unexpected at that point.
    
    5. mem_cgroup_css_free() prepares the system and the memcg object for
       the object's disappearance, neutralizes its state, and then gives
       it back to mem_cgroup_free().
    
    6. mem_cgroup_free() releases struct mem_cgroup and auxiliary memory.
    
    [arnd@arndb.de: fix SLOB build regression]
    Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
    Acked-by: default avatarVladimir Davydov <vdavydov@virtuozzo.com>
    Cc: Michal Hocko <mhocko@suse.cz>
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    0b8f73e1