diff options
author | Andrew Morton <akpm@osdl.org> | 2006-03-08 00:55:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-08 17:14:01 -0500 |
commit | e2bab3d92486fb781f4d06f56339264ed1492392 (patch) | |
tree | 0295e1ed29794a8e804c4e28a3ea9e72777e533b /mm/swap.c | |
parent | b884e25784f62a1c740d2e4c1ce19cb89644e986 (diff) |
[PATCH] percpu_counter_sum()
Implement percpu_counter_sum(). This is a more accurate but slower version of
percpu_counter_read_positive().
We need this for Alex's speedup-ext3_statfs patch and for the nr_file
accounting fix. Otherwise these things would be too inaccurate on large CPU
counts.
Cc: Ravikiran G Thirumalai <kiran@scalex86.org>
Cc: Alex Tomas <alex@clusterfs.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm/swap.c')
-rw-r--r-- | mm/swap.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -489,13 +489,34 @@ void percpu_counter_mod(struct percpu_counter *fbc, long amount) | |||
489 | if (count >= FBC_BATCH || count <= -FBC_BATCH) { | 489 | if (count >= FBC_BATCH || count <= -FBC_BATCH) { |
490 | spin_lock(&fbc->lock); | 490 | spin_lock(&fbc->lock); |
491 | fbc->count += count; | 491 | fbc->count += count; |
492 | *pcount = 0; | ||
492 | spin_unlock(&fbc->lock); | 493 | spin_unlock(&fbc->lock); |
493 | count = 0; | 494 | } else { |
495 | *pcount = count; | ||
494 | } | 496 | } |
495 | *pcount = count; | ||
496 | put_cpu(); | 497 | put_cpu(); |
497 | } | 498 | } |
498 | EXPORT_SYMBOL(percpu_counter_mod); | 499 | EXPORT_SYMBOL(percpu_counter_mod); |
500 | |||
501 | /* | ||
502 | * Add up all the per-cpu counts, return the result. This is a more accurate | ||
503 | * but much slower version of percpu_counter_read_positive() | ||
504 | */ | ||
505 | long percpu_counter_sum(struct percpu_counter *fbc) | ||
506 | { | ||
507 | long ret; | ||
508 | int cpu; | ||
509 | |||
510 | spin_lock(&fbc->lock); | ||
511 | ret = fbc->count; | ||
512 | for_each_cpu(cpu) { | ||
513 | long *pcount = per_cpu_ptr(fbc->counters, cpu); | ||
514 | ret += *pcount; | ||
515 | } | ||
516 | spin_unlock(&fbc->lock); | ||
517 | return ret < 0 ? 0 : ret; | ||
518 | } | ||
519 | EXPORT_SYMBOL(percpu_counter_sum); | ||
499 | #endif | 520 | #endif |
500 | 521 | ||
501 | /* | 522 | /* |