From owner-freebsd-arch@FreeBSD.ORG Mon Mar 22 16:05:07 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D862B16A4CF for ; Mon, 22 Mar 2004 16:05:07 -0800 (PST) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id CFC4B43D41 for ; Mon, 22 Mar 2004 16:05:06 -0800 (PST) (envelope-from john@baldwin.cx) Received: (qmail 11365 invoked from network); 23 Mar 2004 00:05:06 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) encrypted SMTP for ; 23 Mar 2004 00:05:06 -0000 Received: from 10.50.40.205 (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.12.10/8.12.10) with ESMTP id i2N05228000598; Mon, 22 Mar 2004 19:05:03 -0500 (EST) (envelope-from john@baldwin.cx) From: John Baldwin To: David Schultz Date: Mon, 22 Mar 2004 19:06:47 -0500 User-Agent: KMail/1.6 References: <200403160519.i2G5J0V6023193@urban> <200403220657.i2M6vCrS097750@shojaku.t.axe-inc.co.jp> <20040322234557.GA7661@VARK.homeunix.com> In-Reply-To: <20040322234557.GA7661@VARK.homeunix.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200403221906.47238.john@baldwin.cx> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: arch@FreeBSD.ORG cc: Seigo Tanimura Subject: Re: Is MTX_CONTESTED evil? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2004 00:05:08 -0000 On Monday 22 March 2004 06:45 pm, David Schultz wrote: > On Mon, Mar 22, 2004, Seigo Tanimura wrote: > > On Tue, 16 Mar 2004 10:09:48 -0500, > > John Baldwin said: > > > > john> On Tuesday 16 March 2004 12:19 am, Seigo Tanimura wrote: > > >> _mtx_unlock_sleep() currently wakes up only one thread being blocked, > > >> and leaves MTX_CONTESTED on a mutex. According to Solaris Internals, > > >> that strategy adds an overhead to check for MTX_CONTESTED on a mutex, > > >> even though it is not held by any thread. The thread waken up cannot > > >> grab the mutex immediately by _obtain_lock() and have to go through > > >> _mtx_lock_sleep(). The penalty tends to be large for a mutex with a > > >> high contention, and we have at least one of such a mutex - Giant. > > >> > > >> What would it be like if we axed MTX_CONTEST and let > > >> _mtx_unlock_sleep() wake up all of the blocked threads? > > > > john> We wouldn't be able to axe MTX_CONTEST. We also use it to > > determine on unlock john> if we can unlock easily or if we have waiters > > that we need to awake. The john> only way we might be able to axe > > MTX_CONTEST would be to penalize every john> unlock operation requiring a > > turnstile lookup (spin lock acquire/release + john> hash table lookup) > > even unlocks of an uncontested mutex. However, what I john> think you > > want to do is get rid of the mtx_lock == MTX_CONTESTED case and use john> > > turnstile_wakeup() rather than turnstile_signal()? Is that what you are > > > > Yes. What I an wondering is whether the reduction of the cost due to > > a mutex with waiters and no holders can beat the cost of waking up all > > the waiters on the turnstile. > > By the way, one thing to keep in mind is that Solaris has working > adaptive mutexes. For adaptive mutexes, the waiting case is > almost never supposed to happen, so it's more reasonable for them > to wake all waiters. However, AFAIK, FreeBSD's adaptive mutex > support is incomplete or broken at this point, so you may run into > a thundering herd problem if you wake all waiters. Adaptive mutexes work just fine, but they aren't on by default. In FreeBSD, adaptive mutexes spin so long as the owner is still executing on another CPU. -- John Baldwin <>< http://www.baldwin.cx/~john/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org