Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650AbZAIQgQ (ORCPT ); Fri, 9 Jan 2009 11:36:16 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754219AbZAIQfg (ORCPT ); Fri, 9 Jan 2009 11:35:36 -0500 Received: from smtp1.linux-foundation.org ([140.211.169.13]:44755 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753381AbZAIQfd (ORCPT ); Fri, 9 Jan 2009 11:35:33 -0500 Date: Fri, 9 Jan 2009 08:34:34 -0800 (PST) From: Linus Torvalds X-X-Sender: torvalds@localhost.localdomain To: Steven Rostedt cc: Peter Zijlstra , 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 Subject: Re: [PATCH -v7][RFC]: mutex: implement adaptive spinning In-Reply-To: Message-ID: References: <1231441350.14304.48.camel@think.oraclecorp.com> <1231498062.11687.608.camel@twins> <1231513614.442.11.camel@twins> User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2122 Lines: 53 On Fri, 9 Jan 2009, Steven Rostedt wrote: > > I was going to say a while ago... > In PREEMPT=y the need_resched() is not needed at all. If you have > preemption enabled, you will get preempted in that loop. No need for the > need_resched() in the outer loop. Although I'm not sure how it would even > hit the "need_resched". If it was set, then it is most likely going to be > cleared when coming back from being preempted. No, no, you miss the point entirely. It's not about correctness. Remember: the whole (and only) point of spinning is about performance. And the thing is, we should only spin if it makes sense. So the if (need_resched()) break; is not there because of any "ok, I need to sleep now", it's there because of something TOTALLY DIFFERENT, namely "ok, it makes no sense to spin now, since I should be sleeping". See? WE DO NOT WANT TO BE PREEMPTED in this region, because that totally destroys the whole point of the spinning. If we go through the scheduler, then we should go through the scheduler AND GO TO SLEEP, so that we don't go through the scheduler any more than absolutely necessary. So this code - by design - is always only going to get worse if you have involuntary preemption. The preemption is going to do _two_ bad things: - it's going to call the scheduler at the wrong point, meaning that we now scheduler _more_ (or at least not less) than if we didn't have that spin-loop in the first place. - .. and to make things worse, since it scheduled "for us", it is going to clear that "need_resched()" flag, so we'll _stay_ in the bad spinning loop too long! So quite frankly, if you have CONFIG_PREEMPT, then the spinning really is the wrong thing to do, or the whole mutex slow-path thing should be done with preemption disabled so that we only schedule where we _should_ be scheduling. Linus -- 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/