lib/percpu_counter.c: __this_cpu_write() doesn't need to be protected by spinlock
authorFan Du <fan.du@windriver.com>
Wed, 3 Jul 2013 22:05:19 +0000 (15:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Jul 2013 23:07:43 +0000 (16:07 -0700)
__this_cpu_write doesn't need to be protected by spinlock, AS we are doing
per cpu write with preempt disabled.  And another reason to remove
__this_cpu_write outside of spinlock: __percpu_counter_sum is not an
accurate counter.

Signed-off-by: Fan Du <fan.du@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/percpu_counter.c

index ba6085d9c7411f33bbb6aa0077423e822ad1c3dc..1fc23a3277e13794eca7d230ae2ff79aa9c1e4b5 100644 (file)
@@ -80,8 +80,8 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
        if (count >= batch || count <= -batch) {
                raw_spin_lock(&fbc->lock);
                fbc->count += count;
-               __this_cpu_write(*fbc->counters, 0);
                raw_spin_unlock(&fbc->lock);
+               __this_cpu_write(*fbc->counters, 0);
        } else {
                __this_cpu_write(*fbc->counters, count);
        }