aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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