Thread (31 messages) 31 messages, 7 authors, 2011-03-30

Re: [PATCH 2/2] mutex: Apply adaptive spinning on mutex_trylock()

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2011-03-25 13:10:05
Also in: lkml

On Fri, 2011-03-25 at 07:53 +0100, Tejun Heo wrote:
Hello, Steven, Linus.

On Thu, Mar 24, 2011 at 09:38:58PM -0700, Linus Torvalds wrote:
quoted
On Thu, Mar 24, 2011 at 8:39 PM, Steven Rostedt [off-list ref] wrote:
quoted
But now, mutex_trylock(B) becomes a spinner too, and since the B's owner
is running (spinning on A) it will spin as well waiting for A's owner to
release it. Unfortunately, A's owner is also spinning waiting for B to
release it.

If both A and B's owners are real time tasks, then boom! deadlock.
Hmm. I think you're right. And it looks pretty fundamental - I don't
see any reasonable approach to avoid it.
Hmmm... I have an idea.  Will play with it a bit and post if it works
out okay.
One solution is to have this be only done on explicit trylocks. Perhaps
introduce a mutex_trylock_spin()? Then when the developer knows that
this scenario does not exist, they can convert mutex_trylocks() into
this spinning version.
quoted
I think the RT issue is a red herring too - afaik, you can get a
deadlock with two perfectly normal processes too. Of course, for
non-RT tasks, any other process will eventually disturb the situation
and you'd get kicked out due to need_resched(), but even that might be
avoided for a long time if there are other CPU's - leading to tons of
wasted CPU time.
Yeap, need_resched() currently is the only thing which limits the
duration of spinning when the owner continues to run.
Yeah, I was about to complain about the long latencies that this could
cause, then I realized that RT tasks would in fact deadlock the system
here, which I thought was a bigger problem, and focused on that issue.

-- Steve
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help