From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754802AbcESMWA (ORCPT ); Thu, 19 May 2016 08:22:00 -0400 Received: from merlin.infradead.org ([205.233.59.134]:39090 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754453AbcESMV6 (ORCPT ); Thu, 19 May 2016 08:21:58 -0400 Date: Thu, 19 May 2016 14:21:48 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: LKML , Sebastian Andrzej Siewior , Linus Torvalds , Darren Hart , Ingo Molnar , Michael Kerrisk , Davidlohr Bueso , Chris Mason , "Carlos O'Donell" , Torvald Riegel , Eric Dumazet Subject: Re: [patch V2 2/7] futex: Hash private futexes per process Message-ID: <20160519122148.GZ3192@twins.programming.kicks-ass.net> References: <20160505204230.932454245@linutronix.de> <20160505204353.973009518@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160505204353.973009518@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 Thu, May 05, 2016 at 08:44:04PM -0000, Thomas Gleixner wrote: > +struct futex_hash { > + struct raw_spinlock lock; raw_spinlock_t ? > + unsigned int hash_bits; > + struct futex_hash_bucket *hash; > +}; > +static void futex_populate_hash(unsigned int hash_bits) > +{ > + struct mm_struct *mm = current->mm; > + struct futex_hash_bucket *hb = NULL; > + > + /* > + * We don't need an explicit smp_mb() when the hash is populated > + * because before we dereference mm->futex_hash.hash_bits in the hash > + * function we have an smp_mb() in futex_get_key_refs() already. > + */ > + if (mm->futex_hash.hash) > + return; > + > + /* > + * If we failed to allocate a hash on the fly, fall back to the global > + * hash. > + */ > + hb = futex_alloc_hash(hash_bits); > + if (!hb) > + hb = FUTEX_USE_GLOBAL_HASH; > + > + raw_spin_lock(&mm->futex_hash.lock); > + /* We might have raced with another task allocating the hash. */ > + if (!mm->futex_hash.hash) { > + mm->futex_hash.hash_bits = hash_bits; > + /* > + * Ensure that the above is visible before we store > + * the pointer. > + */ > + smp_wmb(); /* (A0) Pairs with (B) */ > + mm->futex_hash.hash = hb; smp_store_release(&mm->futex_hash.hash, hb); ? > + hb = NULL; > + } > + raw_spin_unlock(&mm->futex_hash.lock); > + kfree(hb); > +}