Re: [RFC patch 4/7] futex: Add support for attached futexes
From: Thomas Gleixner
Date: Sun Apr 03 2016 - 06:00:49 EST
On Sat, 2 Apr 2016, Peter Zijlstra wrote:
> On Sat, Apr 02, 2016 at 11:09:18AM -0000, Thomas Gleixner wrote:
> > + /*
> > + * Lock the global hash bucket. Decrement global state refcount. If 0
> > + * remove it from the global hash and free it.
> > + */
> > + spin_lock(&hb->lock);
> > + if (--fs->refcount == 0)
> > + hb_remove_q(q, hb);
> > + else
> > + fs = NULL;
> > + spin_unlock(&hb->lock);
>
> So you could play funny games like:
>
> if (atomic_add_unless(&fs->recount, -1, 1))
> return;
>
> spin_lock(&hb->lock);
> if (atomic_dec_return(&fs->refcount) == 0)
> hb_remove_q(q, hb);
> else
> fs = NULL;
> spin_unlock(&hb->lock);
>
> To avoid taking that lock entirely in the 'fast' path, but I'm not sure
> how performance critical this path is.
Attach/detach is not really critical. The futex ops are critical and they do
not touch the global hash bucket lock at all.
Thanks,
tglx