* [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug
@ 2013-10-01 23:31 David Rientjes
2013-10-02 0:47 ` KOSAKI Motohiro
[not found] ` <alpine.DEB.2.02.1310011629350.27758-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
0 siblings, 2 replies; 4+ messages in thread
From: David Rientjes @ 2013-10-01 23:31 UTC (permalink / raw)
To: Linus Torvalds, Andrew Morton
Cc: Johannes Weiner, Michal Hocko, KAMEZAWA Hiroyuki, cgroups,
linux-mm, linux-kernel
for_each_online_cpu() needs the protection of {get,put}_online_cpus() so
cpu_online_mask doesn't change during the iteration.
Signed-off-by: David Rientjes <rientjes@google.com>
---
mm/memcontrol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -866,6 +866,7 @@ static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
unsigned long val = 0;
int cpu;
+ get_online_cpus();
for_each_online_cpu(cpu)
val += per_cpu(memcg->stat->events[idx], cpu);
#ifdef CONFIG_HOTPLUG_CPU
@@ -873,6 +874,7 @@ static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
val += memcg->nocpu_base.events[idx];
spin_unlock(&memcg->pcp_counter_lock);
#endif
+ put_online_cpus();
return val;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug
2013-10-01 23:31 [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug David Rientjes
@ 2013-10-02 0:47 ` KOSAKI Motohiro
[not found] ` <alpine.DEB.2.02.1310011629350.27758-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
1 sibling, 0 replies; 4+ messages in thread
From: KOSAKI Motohiro @ 2013-10-02 0:47 UTC (permalink / raw)
To: David Rientjes
Cc: Linus Torvalds, Andrew Morton, Johannes Weiner, Michal Hocko,
KAMEZAWA Hiroyuki, cgroups, linux-mm, linux-kernel,
kosaki.motohiro
(10/1/13 7:31 PM), David Rientjes wrote:
> for_each_online_cpu() needs the protection of {get,put}_online_cpus() so
> cpu_online_mask doesn't change during the iteration.
>
> Signed-off-by: David Rientjes <rientjes@google.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <alpine.DEB.2.02.1310011629350.27758-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>]
* Re: [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug
[not found] ` <alpine.DEB.2.02.1310011629350.27758-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
@ 2013-10-02 2:22 ` Johannes Weiner
2013-10-02 3:08 ` David Rientjes
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Weiner @ 2013-10-02 2:22 UTC (permalink / raw)
To: David Rientjes
Cc: Linus Torvalds, Andrew Morton, Michal Hocko, KAMEZAWA Hiroyuki,
cgroups-u79uwXL29TY76Z2rM5mHXA, linux-mm-Bw31MaZKKs3YtjvyW6yDsg,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Tue, Oct 01, 2013 at 04:31:23PM -0700, David Rientjes wrote:
> for_each_online_cpu() needs the protection of {get,put}_online_cpus() so
> cpu_online_mask doesn't change during the iteration.
There is no problem report here.
Is there a crash?
If it's just accuracy of the read, why would we care about some
inaccuracies in counters that can change before you even get the
results to userspace? And care to the point where we hold up CPU
hotplugging for this?
Also, the fact that you directly sent this to Linus suggests there is
some urgency for this fix. What's going on?
Thanks,
Johannes
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug
2013-10-02 2:22 ` Johannes Weiner
@ 2013-10-02 3:08 ` David Rientjes
0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2013-10-02 3:08 UTC (permalink / raw)
To: Johannes Weiner
Cc: Linus Torvalds, Andrew Morton, Michal Hocko, KAMEZAWA Hiroyuki,
cgroups, linux-mm, linux-kernel
On Tue, 1 Oct 2013, Johannes Weiner wrote:
> On Tue, Oct 01, 2013 at 04:31:23PM -0700, David Rientjes wrote:
> > for_each_online_cpu() needs the protection of {get,put}_online_cpus() so
> > cpu_online_mask doesn't change during the iteration.
>
> There is no problem report here.
>
> Is there a crash?
>
No.
> If it's just accuracy of the read, why would we care about some
> inaccuracies in counters that can change before you even get the
> results to userspace? And care to the point where we hold up CPU
> hotplugging for this?
>
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.
> Also, the fact that you directly sent this to Linus suggests there is
> some urgency for this fix. What's going on?
>
I believe users of cpu hotplug still want event counts that are
approximate to the real value and that this is 3.12 material.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-02 3:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-01 23:31 [patch for-3.12] mm, memcg: protect mem_cgroup_read_events for cpu hotplug David Rientjes
2013-10-02 0:47 ` KOSAKI Motohiro
[not found] ` <alpine.DEB.2.02.1310011629350.27758-X6Q0R45D7oAcqpCFd4KODRPsWskHk0ljAL8bYrjMMd8@public.gmane.org>
2013-10-02 2:22 ` Johannes Weiner
2013-10-02 3:08 ` David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox