Re: [PATCH -v7][RFC]: mutex: implement adaptive spinning

From: Peter Zijlstra
Date: Fri Jan 09 2009 - 11:04:37 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/