Re: [PATCH] generic dynamic per cpu refcounting

From: Tejun Heo
Date: Mon Jan 28 2013 - 16:50:33 EST


Hello, Kent.

On Mon, Jan 28, 2013 at 01:45:06PM -0800, Kent Overstreet wrote:
> Ahh. Bias value sounds... hacky (i.e. harder to convince myself it's
> correct) but I see what you're getting at.

I don't think it's that hacky. Just push the base point to the
opposite of zero - LLONG_MAX. The global counter can start biased so
that it gets unbiased only once dying is confirmed and everything can
blindly do atomic64_dec_and_test() and trust the result.

> Something to consider is wrapping; after we set state to dying but
> before we've collected the percpu counters, the atomic counter may be
> negative.

There's a reason why we use 64bit vars for this type of global
counting. They virtually don't wrap. Here, you'll need 1<<63 for the
counter to unintentionally reach 0, which we consider practically
impossible.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/