Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Benjamin Herrenschmidt
Date: Thursday, May 6, 2010 - 11:01 pm

On Fri, 2010-05-07 at 07:30 +0200, Frederic Weisbecker wrote:

And I hate not having it :-)


Yes and no. There's two reasons why the timeout is good. One is the
safeguard part and it's arguable whether it helps hiding bugs or not,
but there are very real cases where I believe we should get out and go
to sleep as well that aren't bugs.

IE. If the mutex owner is running for a long time and nobody is
contending on your CPU, you're simply not going to hit the
need_resched() test. That means you will spin, which means you will suck
a lot more power as well, not counting the potentially bad effect on
rebalance, load average etc...

There's also the fact that 2 CPUs or more trying to obtain it at once
may all go into spinning, which can lead to interesting results in term
of power consumption (and cpu_relax doesn't help that much).

I really don't think it's a good idea to turns mutex into potential
multi-jiffies spinning things like that.


Well, the thing is that it may not be a bug.

The thing is that the actual livelock with the BKL should really only
happen with the BKL since that's the only thing we have that allows for
AB->BA semantics. Anything else should hopefully be caught by lockdep.

So I don't think there's that much to fear about hidden bugs.

But I -also- don't see the point of spinning potentially for a very long
time instead of going to sleep and saving power. The adaptive spinning
goal is to have an opportunistic optimization based on the idea that the
mutex is likely to be held for a very short period of time by its owner
and nobody's waiting for it yet. Ending up doing multi-jiffies spins
just doesn't fit in that picture. In fact, I was tempted to make the
timeout a lot shorter but decided against calling into clock sources
etc... and instead kept it simple with jiffies.


Uh ? So ? This is the contended path where we are .. spinning :-) The
overhead of reading jiffies and comparing here is simply never going to
show on any measurement I bet you :-)


No, what I would potentially add as part of lockdep however is a way to
instrument how often we get out of the spin via the timeout. That might
be a useful information to figure out some of those runaway code path,
but they may well happen for very legit reasons and aren't a bug per-se.


Ben.


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Tue Apr 27, 9:38 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Tue Apr 27, 9:39 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Arnd Bergmann, (Wed Apr 28, 5:06 am)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Wed Apr 28, 3:35 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Frederic Weisbecker, (Thu May 6, 10:30 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Thu May 6, 11:01 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Mike Galbraith, (Thu May 6, 11:16 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Frederic Weisbecker, (Fri May 7, 2:29 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Fri May 7, 3:27 pm)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Peter Zijlstra, (Mon May 10, 12:55 am)
[tip:core/locking] mutex: Fix optimistic spinning vs. BKL, tip-bot for Tony Breeds, (Tue May 11, 8:43 am)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Linus Torvalds, (Tue May 11, 11:06 am)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Peter Zijlstra, (Tue May 11, 11:19 am)
Re: [PATCH/RFC] mutex: Fix optimistic spinning vs. BKL, Benjamin Herrenschmidt, (Tue May 11, 2:13 pm)
[tip:core/urgent] mutex: Fix optimistic spinning vs. BKL, tip-bot for Tony Breeds, (Wed May 19, 12:56 am)