Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752199AbZAIQEg (ORCPT ); Fri, 9 Jan 2009 11:04:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752174AbZAIQEH (ORCPT ); Fri, 9 Jan 2009 11:04:07 -0500 Received: from casper.infradead.org ([85.118.1.10]:46317 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbZAIQEE (ORCPT ); Fri, 9 Jan 2009 11:04:04 -0500 Subject: Re: [PATCH -v7][RFC]: mutex: implement adaptive spinning From: Peter Zijlstra To: Steven Rostedt Cc: Linus Torvalds , Chris Mason , Ingo Molnar , paulmck@linux.vnet.ibm.com, Gregory Haskins , Matthew Wilcox , Andi Kleen , Andrew Morton , Linux Kernel Mailing List , linux-fsdevel , linux-btrfs , Thomas Gleixner , Nick Piggin , Peter Morreale , Sven Dietrich In-Reply-To: References: <1231441350.14304.48.camel@think.oraclecorp.com> <1231498062.11687.608.camel@twins> <1231513614.442.11.camel@twins> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Fri, 09 Jan 2009 17:03:51 +0100 Message-Id: <1231517031.442.15.camel@twins> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1223 Lines: 33 On Fri, 2009-01-09 at 10:59 -0500, Steven Rostedt wrote: > > > > Adding that blocking on !owner utterly destroys everything. > > I was going to warn you about that ;-) > > Without the check for !owner, you are almost guaranteed to go to sleep > every time. Here's why: > > You are spinning and thus have a hot cache on that CPU. > > The owner goes to unlock but will be in a cold cache. It sets lock->owner > to NULL, but is still in cold cache so it is a bit slower. > > Once the spinner sees the NULL, it shoots out of the spin but sees the > lock is still not available then goes to sleep. All before the owner could > release it. This could probably happen at every contention. Thus, you lose > the benefit of spinning. You probably make things worse because you add a > spin before every sleep. Which is why I changed the inner loop to: l_owner = ACCESS_ONCE(lock->owner) if (l_owner && l_owner != owner) break So that that would continue spinning. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/