• Glauber Costa's avatar
    memcg: decrement static keys at real destroy time · 3f134619
    Glauber Costa authored
    We call the destroy function when a cgroup starts to be removed, such as
    by a rmdir event.
    However, because of our reference counters, some objects are still
    inflight.  Right now, we are decrementing the static_keys at destroy()
    time, meaning that if we get rid of the last static_key reference, some
    objects will still have charges, but the code to properly uncharge them
    won't be run.
    This becomes a problem specially if it is ever enabled again, because now
    new charges will be added to the staled charges making keeping it pretty
    much impossible.
    We just need to be careful with the static branch activation: since there
    is no particular preferred order of their activation, we need to make sure
    that we only start using it after all call sites are active.  This is
    achieved by having a per-memcg flag that is only updated after
    static_key_slow_inc() returns.  At this time, we are sure all sites are
    This is made per-memcg, not global, for a reason: it also has the effect
    of making socket accounting more consistent.  The first memcg to be
    limited will trigger static_key() activation, therefore, accounting.  But
    all the others will then be accounted no matter what.  After this patch,
    only limited memcgs will have its sockets accounted.
    [akpm@linux-foundation.org: move enum sock_flag_bits into sock.h,
                                document enum sock_flag_bits,
                                convert memcg_proto_active() and memcg_proto_activated() to test_bit(),
                                redo tcp_update_limit() comment to 80 cols]
    Signed-off-by: default avatarGlauber Costa <glommer@parallels.com>
    Cc: Tejun Heo <tj@kernel.org>
    Cc: Li Zefan <lizefan@huawei.com>
    Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Michal Hocko <mhocko@suse.cz>
    Acked-by: default avatarDavid Miller <davem@davemloft.net>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
tcp_memcontrol.c 7.17 KB