2011-04-12 08:04:10

by Shaohua Li

[permalink] [raw]
Subject: [PATCH 2/4]percpu_counter: use correct API

percpu_counter_sum_positive never returns negative, since there
is a negative check, I changed it to percpu_counter_sum.

Signed-off-by: Shaohua Li <[email protected]>

---
fs/ext4/balloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/fs/ext4/balloc.c
===================================================================
--- linux.orig/fs/ext4/balloc.c 2011-04-12 15:48:42.000000000 +0800
+++ linux/fs/ext4/balloc.c 2011-04-12 15:48:50.000000000 +0800
@@ -506,7 +506,7 @@ static int ext4_has_free_blocks(struct e
if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
EXT4_FREEBLOCKS_WATERMARK) {
free_blocks = percpu_counter_sum_positive(fbc);
- dirty_blocks = percpu_counter_sum_positive(dbc);
+ dirty_blocks = percpu_counter_sum(dbc);
if (dirty_blocks < 0) {
printk(KERN_CRIT "Dirty block accounting "
"went wrong %lld\n",


2011-04-12 18:52:29

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 2/4]percpu_counter: use correct API

On Tue, Apr 12, 2011 at 04:04:01PM +0800, Shaohua Li wrote:
> percpu_counter_sum_positive never returns negative, since there
> is a negative check, I changed it to percpu_counter_sum.
>
> Signed-off-by: Shaohua Li <[email protected]>
>
> ---
> fs/ext4/balloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux/fs/ext4/balloc.c
> ===================================================================
> --- linux.orig/fs/ext4/balloc.c 2011-04-12 15:48:42.000000000 +0800
> +++ linux/fs/ext4/balloc.c 2011-04-12 15:48:50.000000000 +0800
> @@ -506,7 +506,7 @@ static int ext4_has_free_blocks(struct e
> if (free_blocks - (nblocks + root_blocks + dirty_blocks) <
> EXT4_FREEBLOCKS_WATERMARK) {
> free_blocks = percpu_counter_sum_positive(fbc);
> - dirty_blocks = percpu_counter_sum_positive(dbc);
> + dirty_blocks = percpu_counter_sum(dbc);
> if (dirty_blocks < 0) {
> printk(KERN_CRIT "Dirty block accounting "
> "went wrong %lld\n",

The right thing to do would be removing if (dirty_blocks < 0) and keep
using _positive. perpcu_counter_sum() may return a negative number
spuriously (that's the whole point of _positive functions) and may
trigger the critial error path when nothing is really wrong.

Thanks.

--
tejun