From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752550AbcDBQ3N (ORCPT ); Sat, 2 Apr 2016 12:29:13 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:44226 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751299AbcDBQ3M (ORCPT ); Sat, 2 Apr 2016 12:29:12 -0400 Date: Sat, 2 Apr 2016 18:29:03 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: LKML , Sebastian Andrzej Siewior , Darren Hart , Ingo Molnar , Michael Kerrisk , Davidlohr Bueso , Chris Mason , "Carlos O'Donell" , Torvald Riegel , Eric Dumazet Subject: Re: [RFC patch 4/7] futex: Add support for attached futexes Message-ID: <20160402162903.GR3448@twins.programming.kicks-ass.net> References: <20160402095108.894519835@linutronix.de> <20160402110035.753145539@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160402110035.753145539@linutronix.de> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 02, 2016 at 11:09:18AM -0000, Thomas Gleixner wrote: > +/** > + * futex_detach_task - Detach task from global state > + * @slot: Slot number in the task local cache > + * > + * If the global state refcount drops to zero, the global state is destroyed. > + */ > +static void futex_detach_task(int slot) > +{ > + struct futex_cache *tc = current->futex_cache; > + struct futex_state *fs = tc->slots[slot].fs; > + struct futex_hash_bucket *hb = fs->global_hb; > + struct futex_q *q = &fs->q; > + > + /* Remove it from the task local cache */ > + __clear_bit(slot, tc->cache_map); > + tc->slots[slot].uaddr = NULL; > + tc->slots[slot].fs = NULL; > + > + /* > + * 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. > + kfree(fs); > +}