]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
mm, memcg: protect mem_cgroup_read_events for cpu hotplug
authorDavid Rientjes <rientjes@google.com>
Wed, 16 Oct 2013 20:46:43 +0000 (13:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Oct 2013 04:35:52 +0000 (21:35 -0700)
commit9c56751271e7a917783fb57ec49fe8382e0dc867
tree7b3b11cc74ebbe7d6c30593e2803535ad4b23ccb
parent34ec4de42be5006abdd8d0c08b306ffaa64d0d5d
mm, memcg: protect mem_cgroup_read_events for cpu hotplug

for_each_online_cpu() needs the protection of {get,put}_online_cpus() so
cpu_online_mask doesn't change during the iteration.

cpu_hotplug.lock is held while a cpu is going down, it's a coarse lock
that is used kernel-wide to synchronize cpu hotplug activity.  Memcg has
a cpu hotplug notifier, called while there may not be any cpu hotplug
refcounts, which drains per-cpu event counts to memcg->nocpu_base.events
to maintain a cumulative event count as cpus disappear.  Without
get_online_cpus() in mem_cgroup_read_events(), it's possible to account
for the event count on a dying cpu twice, and this value may be
significantly large.

In fact, all memcg->pcp_counter_lock use should be nested by
{get,put}_online_cpus().

This fixes that issue and ensures the reported statistics are not vastly
over-reported during cpu hotplug.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/memcontrol.c