diff options
author | Dave Chinner <dchinner@redhat.com> | 2015-05-28 17:39:34 -0400 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2015-05-28 17:39:34 -0400 |
commit | 80188b0d77d7426b494af739ac129e0e684acb84 (patch) | |
tree | ba795195e42d33c4fc8436a1c80d954a1057ab7f | |
parent | 74f9ce1cf2830b94e189f4e99678dbf19aa3bc90 (diff) |
percpu_counter: batch size aware __percpu_counter_compare()
XFS uses non-stanard batch sizes for avoiding frequent global
counter updates on it's allocated inode counters, as they increment
or decrement in batches of 64 inodes. Hence the standard percpu
counter batch of 32 means that the counter is effectively a global
counter. Currently Xfs uses a batch size of 128 so that it doesn't
take the global lock on every single modification.
However, Xfs also needs to compare accurately against zero, which
means we need to use percpu_counter_compare(), and that has a
hard-coded batch size of 32, and hence will spuriously fail to
detect when it is supposed to use precise comparisons and hence
the accounting goes wrong.
Add __percpu_counter_compare() to take a custom batch size so we can
use it sanely in XFS and factor percpu_counter_compare() to use it.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r-- | include/linux/percpu_counter.h | 13 | ||||
-rw-r--r-- | lib/percpu_counter.c | 6 |
2 files changed, 15 insertions, 4 deletions
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h index 50e50095c8d1..84a109449610 100644 --- a/include/linux/percpu_counter.h +++ b/include/linux/percpu_counter.h | |||
@@ -41,7 +41,12 @@ void percpu_counter_destroy(struct percpu_counter *fbc); | |||
41 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount); | 41 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount); |
42 | void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch); | 42 | void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch); |
43 | s64 __percpu_counter_sum(struct percpu_counter *fbc); | 43 | s64 __percpu_counter_sum(struct percpu_counter *fbc); |
44 | int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs); | 44 | int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch); |
45 | |||
46 | static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) | ||
47 | { | ||
48 | return __percpu_counter_compare(fbc, rhs, percpu_counter_batch); | ||
49 | } | ||
45 | 50 | ||
46 | static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) | 51 | static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) |
47 | { | 52 | { |
@@ -116,6 +121,12 @@ static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) | |||
116 | return 0; | 121 | return 0; |
117 | } | 122 | } |
118 | 123 | ||
124 | static inline int | ||
125 | __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch) | ||
126 | { | ||
127 | return percpu_counter_compare(fbc, rhs); | ||
128 | } | ||
129 | |||
119 | static inline void | 130 | static inline void |
120 | percpu_counter_add(struct percpu_counter *fbc, s64 amount) | 131 | percpu_counter_add(struct percpu_counter *fbc, s64 amount) |
121 | { | 132 | { |
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 48144cdae819..f051d69f0910 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c | |||
@@ -197,13 +197,13 @@ static int percpu_counter_hotcpu_callback(struct notifier_block *nb, | |||
197 | * Compare counter against given value. | 197 | * Compare counter against given value. |
198 | * Return 1 if greater, 0 if equal and -1 if less | 198 | * Return 1 if greater, 0 if equal and -1 if less |
199 | */ | 199 | */ |
200 | int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) | 200 | int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch) |
201 | { | 201 | { |
202 | s64 count; | 202 | s64 count; |
203 | 203 | ||
204 | count = percpu_counter_read(fbc); | 204 | count = percpu_counter_read(fbc); |
205 | /* Check to see if rough count will be sufficient for comparison */ | 205 | /* Check to see if rough count will be sufficient for comparison */ |
206 | if (abs(count - rhs) > (percpu_counter_batch*num_online_cpus())) { | 206 | if (abs(count - rhs) > (batch * num_online_cpus())) { |
207 | if (count > rhs) | 207 | if (count > rhs) |
208 | return 1; | 208 | return 1; |
209 | else | 209 | else |
@@ -218,7 +218,7 @@ int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) | |||
218 | else | 218 | else |
219 | return 0; | 219 | return 0; |
220 | } | 220 | } |
221 | EXPORT_SYMBOL(percpu_counter_compare); | 221 | EXPORT_SYMBOL(__percpu_counter_compare); |
222 | 222 | ||
223 | static int __init percpu_counter_startup(void) | 223 | static int __init percpu_counter_startup(void) |
224 | { | 224 | { |