diff options
author | Tim Chen <tim.c.chen@linux.intel.com> | 2010-08-09 20:19:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-09 23:44:58 -0400 |
commit | 27f5e0f694fd0600274a76854636c0749e3bb1f6 (patch) | |
tree | 0d3a0387b42eb0a830fa5ba896a205b2a3807b8b /include/linux/percpu_counter.h | |
parent | 4e60c86bd9e5a7110ed28874d0b6592186550ae8 (diff) |
tmpfs: add accurate compare function to percpu_counter library
Add percpu_counter_compare that allows for a quick but accurate comparison
of percpu_counter with a given value.
A rough count is provided by the count field in percpu_counter structure,
without accounting for the other values stored in individual cpu counters.
The actual count is a sum of count and the cpu counters. However, count
field is never different from the actual value by a factor of
batch*num_online_cpu. We do not need to get actual count for comparison
if count is different from the given value by this factor and allows for
quick comparison without summing up all the per cpu counters.
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/percpu_counter.h')
-rw-r--r-- | include/linux/percpu_counter.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h index c88d67b59394..8a7d510ffa9c 100644 --- a/include/linux/percpu_counter.h +++ b/include/linux/percpu_counter.h | |||
@@ -40,6 +40,7 @@ void percpu_counter_destroy(struct percpu_counter *fbc); | |||
40 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount); | 40 | void percpu_counter_set(struct percpu_counter *fbc, s64 amount); |
41 | void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch); | 41 | void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch); |
42 | s64 __percpu_counter_sum(struct percpu_counter *fbc); | 42 | s64 __percpu_counter_sum(struct percpu_counter *fbc); |
43 | int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs); | ||
43 | 44 | ||
44 | static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) | 45 | static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) |
45 | { | 46 | { |
@@ -98,6 +99,16 @@ static inline void percpu_counter_set(struct percpu_counter *fbc, s64 amount) | |||
98 | fbc->count = amount; | 99 | fbc->count = amount; |
99 | } | 100 | } |
100 | 101 | ||
102 | static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) | ||
103 | { | ||
104 | if (fbc->count > rhs) | ||
105 | return 1; | ||
106 | else if (fbc->count < rhs) | ||
107 | return -1; | ||
108 | else | ||
109 | return 0; | ||
110 | } | ||
111 | |||
101 | static inline void | 112 | static inline void |
102 | percpu_counter_add(struct percpu_counter *fbc, s64 amount) | 113 | percpu_counter_add(struct percpu_counter *fbc, s64 amount) |
103 | { | 114 | { |