• Glauber Costa's avatar
    memcg: kmem accounting lifecycle management · 7de37682
    Glauber Costa authored
    Because kmem charges can outlive the cgroup, we need to make sure that we
    won't free the memcg structure while charges are still in flight.  For
    reviewing simplicity, the charge functions will issue mem_cgroup_get() at
    every charge, and mem_cgroup_put() at every uncharge.
    
    This can get expensive, however, and we can do better.  mem_cgroup_get()
    only really needs to be issued once: when the first limit is set.  In the
    same spirit, we only need to issue mem_cgroup_put() when the last charge
    is gone.
    
    We'll need an extra bit in kmem_account_flags for that:
    KMEM_ACCOUNTED_DEAD.  it will be set when the cgroup dies, if there are
    charges in the group.  If there aren't, we can proceed right away.
    
    Our uncharge function will have to test that bit every time the charges
    drop to 0.  Because that is not the likely output of res_counter_uncharge,
    this should not impose a big hit on us: it is certainly much better than a
    reference count decrease at every operation.
    Signed-off-by: default avatarGlauber Costa <glommer@parallels.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.cz>
    Acked-by: default avatarKamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Pekka Enberg <penberg@cs.helsinki.fi>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Suleiman Souhlal <suleiman@google.com>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: David Rientjes <rientjes@google.com>
    Cc: Frederic Weisbecker <fweisbec@redhat.com>
    Cc: Greg Thelen <gthelen@google.com>
    Cc: JoonSoo Kim <js1304@gmail.com>
    Cc: Mel Gorman <mel@csn.ul.ie>
    Cc: Rik van Riel <riel@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    7de37682
memcontrol.c 156 KB