Re: Alloc refcount increments to fail

From: Al Viro
Date: Thu May 02 2019 - 11:47:14 EST


On Thu, May 02, 2019 at 08:26:21AM -0700, Matthew Wilcox wrote:

> +/**
> + * refcount_try_inc - Increment a refcount if it's below INT_MAX
> + * @r: the refcount to increment
> + *
> + * Avoid the counter saturating by declining to increment the counter
> + * if it is more than halfway to saturation.
> + */
> +static inline __must_check bool refcount_try_inc(refcount_t *r)
> +{
> + if (refcount_read(r) < 0)
> + return false;
> + refcount_inc(r);
> + return true;
> +}

So two of those in parallel with have zero protection, won't they?