Re: [RFC][PATCH 7/7] kref: Implement using refcount_t

From: Will Deacon
Date: Thu Nov 17 2016 - 12:00:05 EST


On Thu, Nov 17, 2016 at 10:28:00AM +0100, Peter Zijlstra wrote:
> On Tue, Nov 15, 2016 at 10:19:09PM +0800, Boqun Feng wrote:
> > But as I said, we actually only need the pairing of orderings:
> >
> > 1) load part of cmpxchg -> free()
> > 2) object accesses -> store part of cmpxchg
> >
> > Ordering #1 can be achieved via control dependency as you pointed out
> > that free()s very much includes stores. And ordering #2 can be achieved
> > with RELEASE.
> >
> > So the code is right, I just thought the comment may be misleading. The
> > reason we use cmpxchg_release() is just for achieving ordering #2, and
> > not to order "prior loads and stores" with "a subsequent free".
> >
> > Am I missing some subtle orderings here?
>
> I would want to further quality 1), it must be no earlier than the load
> of the last / successful ll/sc round.
>
> At that point we're guaranteed a reference count of 1 that _will_ drop
> to 0, and thus nobody else (should) reference that memory anymore.
>
> If we agree on this, I'll update the comment :-) Will, do you too agree?

All sounds reasonable to me. It's worth pointing out that you can't create
order using a control dependency hanging off the status flag of a
store-conditional, but the code in question here has the dependency from
the loaded value, which is sufficient.

Will