From: Andrew Morton Cc: Ravikiran Thirumalai Signed-off-by: Andrew Morton --- include/linux/percpu_counter.h | 5 +---- lib/percpu_counter.c | 9 +++++++-- Makefile | 0 swap.c | 0 4 files changed, 8 insertions(+), 6 deletions(-) diff -puN include/linux/percpu_counter.h~percpu-counters-add-percpu_counter_exceeds-tidy include/linux/percpu_counter.h --- devel/include/linux/percpu_counter.h~percpu-counters-add-percpu_counter_exceeds-tidy 2006-03-11 00:38:30.000000000 -0800 +++ devel-akpm/include/linux/percpu_counter.h 2006-03-11 00:38:30.000000000 -0800 @@ -110,10 +110,7 @@ static inline void percpu_counter_mod_bh static inline int percpu_counter_exceeds(struct percpu_counter *fbc, long limit) { - if (percpu_counter_read(fbc) > limit) - return 1; - else - return 0; + return percpu_counter_read(fbc) > limit; } #endif /* CONFIG_SMP */ diff -puN lib/Makefile~percpu-counters-add-percpu_counter_exceeds-tidy lib/Makefile diff -puN lib/percpu_counter.c~percpu-counters-add-percpu_counter_exceeds-tidy lib/percpu_counter.c --- devel/lib/percpu_counter.c~percpu-counters-add-percpu_counter_exceeds-tidy 2006-03-11 00:38:30.000000000 -0800 +++ devel-akpm/lib/percpu_counter.c 2006-03-11 00:38:30.000000000 -0800 @@ -60,8 +60,14 @@ long percpu_counter_sum(struct percpu_co EXPORT_SYMBOL(percpu_counter_sum); /* - * Returns zero if the counter is within limit. Returns non zero if counter + * Returns zero if the counter is within limit. Returns non zero if counter * is over limit. + * + * The idea is that we avoid doing the expensive percpu_counter_sum() unless + * some limit looks like it is exceeded, which will cause some serious failure. + * In that case we do the percpu_counter_sum() to make the counts accurate. If + * it turns out that the limit wasn't exceeded, there will be no more calls to + * percpu_counter_sum() until significant counter skew has reoccurred. */ int percpu_counter_exceeds(struct percpu_counter *fbc, long limit) { @@ -71,4 +77,3 @@ int percpu_counter_exceeds(struct percpu return 0; } EXPORT_SYMBOL(percpu_counter_exceeds); - diff -puN mm/swap.c~percpu-counters-add-percpu_counter_exceeds-tidy mm/swap.c _