aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percpu_counter.c
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2009-01-06 17:41:04 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:13 -0500
commit179f7ebff6be45738c6e2fa68c8d2cc5c2c6308e (patch)
tree3d48b5f825cfa29f5b39656503c5157872454e9f /lib/percpu_counter.c
parente3d5a27d5862b6425d0879272e24abecf7245105 (diff)
percpu_counter: FBC_BATCH should be a variable
For NR_CPUS >= 16 values, FBC_BATCH is 2*NR_CPUS Considering more and more distros are using high NR_CPUS values, it makes sense to use a more sensible value for FBC_BATCH, and get rid of NR_CPUS. A sensible value is 2*num_online_cpus(), with a minimum value of 32 (This minimum value helps branch prediction in __percpu_counter_add()) We already have a hotcpu notifier, so we can adjust FBC_BATCH dynamically. We rename FBC_BATCH to percpu_counter_batch since its not a constant anymore. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/percpu_counter.c')
-rw-r--r--lib/percpu_counter.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index b255b939bc1b..a60bd8046095 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -9,10 +9,8 @@
9#include <linux/cpu.h> 9#include <linux/cpu.h>
10#include <linux/module.h> 10#include <linux/module.h>
11 11
12#ifdef CONFIG_HOTPLUG_CPU
13static LIST_HEAD(percpu_counters); 12static LIST_HEAD(percpu_counters);
14static DEFINE_MUTEX(percpu_counters_lock); 13static DEFINE_MUTEX(percpu_counters_lock);
15#endif
16 14
17void percpu_counter_set(struct percpu_counter *fbc, s64 amount) 15void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
18{ 16{
@@ -111,13 +109,24 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
111} 109}
112EXPORT_SYMBOL(percpu_counter_destroy); 110EXPORT_SYMBOL(percpu_counter_destroy);
113 111
114#ifdef CONFIG_HOTPLUG_CPU 112int percpu_counter_batch __read_mostly = 32;
113EXPORT_SYMBOL(percpu_counter_batch);
114
115static void compute_batch_value(void)
116{
117 int nr = num_online_cpus();
118
119 percpu_counter_batch = max(32, nr*2);
120}
121
115static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb, 122static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
116 unsigned long action, void *hcpu) 123 unsigned long action, void *hcpu)
117{ 124{
125#ifdef CONFIG_HOTPLUG_CPU
118 unsigned int cpu; 126 unsigned int cpu;
119 struct percpu_counter *fbc; 127 struct percpu_counter *fbc;
120 128
129 compute_batch_value();
121 if (action != CPU_DEAD) 130 if (action != CPU_DEAD)
122 return NOTIFY_OK; 131 return NOTIFY_OK;
123 132
@@ -134,13 +143,14 @@ static int __cpuinit percpu_counter_hotcpu_callback(struct notifier_block *nb,
134 spin_unlock_irqrestore(&fbc->lock, flags); 143 spin_unlock_irqrestore(&fbc->lock, flags);
135 } 144 }
136 mutex_unlock(&percpu_counters_lock); 145 mutex_unlock(&percpu_counters_lock);
146#endif
137 return NOTIFY_OK; 147 return NOTIFY_OK;
138} 148}
139 149
140static int __init percpu_counter_startup(void) 150static int __init percpu_counter_startup(void)
141{ 151{
152 compute_batch_value();
142 hotcpu_notifier(percpu_counter_hotcpu_callback, 0); 153 hotcpu_notifier(percpu_counter_hotcpu_callback, 0);
143 return 0; 154 return 0;
144} 155}
145module_init(percpu_counter_startup); 156module_init(percpu_counter_startup);
146#endif