diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-11-02 16:38:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-02 19:07:00 -0400 |
commit | 4799401fef9d5951b2da384c5eb08034c48e08a0 (patch) | |
tree | 94f9113c6870f46811aaa0f08cdb3ca2beba1e9c /mm | |
parent | a61ed3cec51cfd4877855c24890ab8d3e2b143e3 (diff) |
memcg: Fix race condition in memcg_check_events() with this_cpu usage
Various code in memcontrol.c () calls this_cpu_read() on the calculations
to be done from two different percpu variables, or does an open-coded
read-modify-write on a single percpu variable.
Disable preemption throughout these operations so that the writes go to
the correct palces.
[hannes@cmpxchg.org: added this_cpu to __this_cpu conversion]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Greg Thelen <gthelen@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Christoph Lameter <cl@linux.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 01e0c725de65..7af1d5ee1598 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -686,8 +686,8 @@ static bool __memcg_event_check(struct mem_cgroup *memcg, int target) | |||
686 | { | 686 | { |
687 | unsigned long val, next; | 687 | unsigned long val, next; |
688 | 688 | ||
689 | val = this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); | 689 | val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); |
690 | next = this_cpu_read(memcg->stat->targets[target]); | 690 | next = __this_cpu_read(memcg->stat->targets[target]); |
691 | /* from time_after() in jiffies.h */ | 691 | /* from time_after() in jiffies.h */ |
692 | return ((long)next - (long)val < 0); | 692 | return ((long)next - (long)val < 0); |
693 | } | 693 | } |
@@ -696,7 +696,7 @@ static void __mem_cgroup_target_update(struct mem_cgroup *memcg, int target) | |||
696 | { | 696 | { |
697 | unsigned long val, next; | 697 | unsigned long val, next; |
698 | 698 | ||
699 | val = this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); | 699 | val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); |
700 | 700 | ||
701 | switch (target) { | 701 | switch (target) { |
702 | case MEM_CGROUP_TARGET_THRESH: | 702 | case MEM_CGROUP_TARGET_THRESH: |
@@ -712,7 +712,7 @@ static void __mem_cgroup_target_update(struct mem_cgroup *memcg, int target) | |||
712 | return; | 712 | return; |
713 | } | 713 | } |
714 | 714 | ||
715 | this_cpu_write(memcg->stat->targets[target], next); | 715 | __this_cpu_write(memcg->stat->targets[target], next); |
716 | } | 716 | } |
717 | 717 | ||
718 | /* | 718 | /* |
@@ -721,6 +721,7 @@ static void __mem_cgroup_target_update(struct mem_cgroup *memcg, int target) | |||
721 | */ | 721 | */ |
722 | static void memcg_check_events(struct mem_cgroup *memcg, struct page *page) | 722 | static void memcg_check_events(struct mem_cgroup *memcg, struct page *page) |
723 | { | 723 | { |
724 | preempt_disable(); | ||
724 | /* threshold event is triggered in finer grain than soft limit */ | 725 | /* threshold event is triggered in finer grain than soft limit */ |
725 | if (unlikely(__memcg_event_check(memcg, MEM_CGROUP_TARGET_THRESH))) { | 726 | if (unlikely(__memcg_event_check(memcg, MEM_CGROUP_TARGET_THRESH))) { |
726 | mem_cgroup_threshold(memcg); | 727 | mem_cgroup_threshold(memcg); |
@@ -740,6 +741,7 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page) | |||
740 | } | 741 | } |
741 | #endif | 742 | #endif |
742 | } | 743 | } |
744 | preempt_enable(); | ||
743 | } | 745 | } |
744 | 746 | ||
745 | static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) | 747 | static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) |