From: Ravikiran G Thirumalai percpu_counter used a lock+lock because at the time, atomic_t was only guaranteed to hold 24 bits of data. Nowadays we can use atomic_long_t. Signed-off-by: Ravikiran Thirumalai Signed-off-by: Shai Fultheim Signed-off-by: Andrew Morton --- include/linux/percpu_counter.h | 10 ++++------ mm/swap.c | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff -puN include/linux/percpu_counter.h~avoid-use-of-spinlock-for-percpu_counter include/linux/percpu_counter.h --- devel/include/linux/percpu_counter.h~avoid-use-of-spinlock-for-percpu_counter 2006-02-07 13:19:38.000000000 -0800 +++ devel-akpm/include/linux/percpu_counter.h 2006-02-07 13:19:38.000000000 -0800 @@ -15,8 +15,7 @@ #ifdef CONFIG_SMP struct percpu_counter { - spinlock_t lock; - long count; + atomic_long_t count; long *counters; }; @@ -28,8 +27,7 @@ struct percpu_counter { static inline void percpu_counter_init(struct percpu_counter *fbc) { - spin_lock_init(&fbc->lock); - fbc->count = 0; + atomic_long_set(&fbc->count, 0); fbc->counters = alloc_percpu(long); } @@ -42,7 +40,7 @@ void percpu_counter_mod(struct percpu_co static inline long percpu_counter_read(struct percpu_counter *fbc) { - return fbc->count; + return atomic_long_read(&fbc->count); } /* @@ -51,7 +49,7 @@ static inline long percpu_counter_read(s */ static inline long percpu_counter_read_positive(struct percpu_counter *fbc) { - long ret = fbc->count; + long ret = atomic_long_read(&fbc->count); barrier(); /* Prevent reloads of fbc->count */ if (ret > 0) diff -puN mm/swap.c~avoid-use-of-spinlock-for-percpu_counter mm/swap.c --- devel/mm/swap.c~avoid-use-of-spinlock-for-percpu_counter 2006-02-07 13:19:38.000000000 -0800 +++ devel-akpm/mm/swap.c 2006-02-07 13:19:38.000000000 -0800 @@ -489,9 +489,7 @@ void percpu_counter_mod(struct percpu_co pcount = per_cpu_ptr(fbc->counters, cpu); count = *pcount + amount; if (count >= FBC_BATCH || count <= -FBC_BATCH) { - spin_lock(&fbc->lock); - fbc->count += count; - spin_unlock(&fbc->lock); + atomic_long_add(count, &fbc->count); count = 0; } *pcount = count; _