• Andrew Morton's avatar
    revert "percpu counter: clean up percpu_counter_sum_and_set()" · 71c5576f
    Andrew Morton authored
    Revert
    
        commit 1f7c14c6
        Author: Mingming Cao <cmm@us.ibm.com>
        Date:   Thu Oct 9 12:50:59 2008 -0400
    
            percpu counter: clean up percpu_counter_sum_and_set()
    
    Before this patch we had the following:
    
    percpu_counter_sum(): return the percpu_counter's value
    
    percpu_counter_sum_and_set(): return the percpu_counter's value, copying
    that value into the central value and zeroing the per-cpu counters before
    returning.
    
    After this patch, percpu_counter_sum_and_set() has gone, and
    percpu_counter_sum() gets the old percpu_counter_sum_and_set()
    functionality.
    
    Problem is, as Eric points out, the old percpu_counter_sum_and_set()
    functionality was racy and wrong.  It zeroes out counters on "other" cpus,
    without holding any locks which will prevent races agaist updates from
    those other CPUS.
    
    This patch reverts 1f7c14c6.  This means
    that percpu_counter_sum_and_set() still has the race, but
    percpu_counter_sum() does not.
    
    Note that this is not a simple revert - ext4 has since started using
    percpu_counter_sum() for its dirty_blocks counter as well.
    
    Note that this revert patch changes percpu_counter_sum() semantics.
    
    Before the patch, a call to percpu_counter_sum() will bring the counter's
    central counter mostly up-to-date, so a following percpu_counter_read()
    will return a close value.
    
    After this patch, a call to percpu_counter_sum() will leave the counter's
    central accumulator unaltered, so a subsequent call to
    percpu_counter_read() can now return a significantly inaccurate result.
    
    If there is any code in the tree which was introduced after
    e8ced39d was merged, and which depends
    upon the new percpu_counter_sum() semantics, that code will break.
    Reported-by: default avatarEric Dumazet <dada1@cosmosbay.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Cc: Mingming Cao <cmm@us.ibm.com>
    Cc: <linux-ext4@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    71c5576f
percpu_counter.c 3.2 KB