# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1491  -> 1.1492 
#	           mm/swap.c	1.54    -> 1.55   
#	include/linux/percpu_counter.h	1.2     -> 1.3    
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/11/24	jbarnes@tomahawk.engr.sgi.com	1.1492
# fix ext2 per-cpu info for large cpu counts
# --------------------------------------------
#
diff -Nru a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h
--- a/include/linux/percpu_counter.h	Mon Nov 24 12:43:11 2003
+++ b/include/linux/percpu_counter.h	Mon Nov 24 12:43:11 2003
@@ -8,6 +8,7 @@
 #include <linux/spinlock.h>
 #include <linux/smp.h>
 #include <linux/threads.h>
+#include <linux/percpu.h>
 
 #ifdef CONFIG_SMP
 
@@ -18,7 +19,7 @@
 struct percpu_counter {
 	spinlock_t lock;
 	long count;
-	struct __percpu_counter counters[NR_CPUS];
+	struct __percpu_counter *counters;
 };
 
 #if NR_CPUS >= 16
@@ -29,12 +30,14 @@
 
 static inline void percpu_counter_init(struct percpu_counter *fbc)
 {
-	int i;
-
 	spin_lock_init(&fbc->lock);
 	fbc->count = 0;
-	for (i = 0; i < NR_CPUS; i++)
-		fbc->counters[i].count = 0;
+	fbc->counters = alloc_percpu(struct __percpu_counter);
+}
+
+static inline void percpu_counter_destroy(struct percpu_counter *fbc)
+{
+	free_percpu(fbc->counters);
 }
 
 void percpu_counter_mod(struct percpu_counter *fbc, long amount);
@@ -67,6 +70,10 @@
 static inline void percpu_counter_init(struct percpu_counter *fbc)
 {
 	fbc->count = 0;
+}
+
+static inline void percpu_counter_destroy(struct percpu_counter *fbc)
+{
 }
 
 static inline void
diff -Nru a/mm/swap.c b/mm/swap.c
--- a/mm/swap.c	Mon Nov 24 12:43:11 2003
+++ b/mm/swap.c	Mon Nov 24 12:43:11 2003
@@ -386,9 +386,10 @@
 #ifdef CONFIG_SMP
 void percpu_counter_mod(struct percpu_counter *fbc, long amount)
 {
-	int cpu = get_cpu();
-	long count = fbc->counters[cpu].count;
+	long count;
 
+	count = *(long *)get_cpu_ptr(fbc->counters);
+	put_cpu_ptr();
 	count += amount;
 	if (count >= FBC_BATCH || count <= -FBC_BATCH) {
 		spin_lock(&fbc->lock);
@@ -396,8 +397,8 @@
 		spin_unlock(&fbc->lock);
 		count = 0;
 	}
-	fbc->counters[cpu].count = count;
-	put_cpu();
+	*(long *)get_cpu_ptr(fbc->counters) = count;
+	put_cpu_ptr();
 }
 EXPORT_SYMBOL(percpu_counter_mod);
 #endif
