Re: [PATCH 03/34] lib: percpu counter add unless less than functionality

Alex Elder
2010-12-22T02:20:06Z

On Tue, 2010-12-21 at 18:28 +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> To use the generic percpu counter infrastructure for counters that
> require conditional addition based on a threshold value we need
> special handling of the counter. Further, the caller needs to know
> the status of the conditional addition to determine what action to
> take depending on whether the addition occurred or not. Examples of
> this sort of usage are resource counters that cannot go below zero
> (e.g. filesystem free blocks).
>
> To allow XFS to replace it's complex roll-your-own per-cpu
> superblock counters, a single generic conditional function is
> required: percpu_counter_add_unless_lt(). This will add the amount
> to the counter unless the result would be less than the given
> threshold. A caller supplied threshold is required because XFS does
> not necessarily use the same threshold for every counter.
>
> percpu_counter_add_unless_lt() attempts to minimise counter lock
> traversals by only taking the counter lock when the threshold is
> within the error range of the current counter value. Hence when the
> threshold is not within the counter error range, the counter will
> still have the same scalability characteristics as the normal
> percpu_counter_add() function.
>
> Adding this functionality to the generic percpu counters allows us
> to remove the much more complex and less efficient XFS percpu
> counter code (~700 lines of code) and replace it with generic
> percpu counters.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>

I want to look at this one more closely again in the
morning, but for now I'll just mention one nit, and
one easily fixed problem.

-Alex

. . .

> + * Add @amount to @fdc if and only if result of addition is greater than or
^^^ should be fbc

> +EXPORT_SYMBOL(percpu_counter_add_unless_lt);
> +

This has to be:
EXPORT_SYMBOL(__percpu_counter_add_unless_lt);
(with leading underscores).