Re: [patch] spinlock debug: make looping nicer

From: Linus Torvalds
Date: Thu Jun 21 2007 - 17:00:56 EST




On Thu, 21 Jun 2007, Ingo Molnar wrote:
>
> btw., back then we also tried a spin_is_locked() based inner loop but it
> didnt help the ->tree_lock lockups either. In any case i very much agree
> that the 'nicer' looping should be added again - the patch below does
> that. (build and boot tested)

Ok, I'm definitely not going to apply it right now, though.

> and the reason that this didnt help the ->tree_lock lockup is likely the
> same why wait_task_inactive() broke _independently_ of the 'niceness' of
> the spin-lock operation: there were too few instructions between
> releasing the lock and re-acquiring it again can cause permanent
> starvation of another CPU. No amount of logic on the spinning side can
> overcome this, if acquire/release critical sections are following each
> other too fast.

Exactly.

The only way to handle that case is to make sure that the person who
*gets* the spinlock will slow down. The person who doesn't get it can't do
anything at all about the fact that he's locked out.

A way to do that (as already mentioned) is to have a "this lock is
contended" flag, and have the person who gets the lock do something about
it (where the "something" might actually be as simple as saying "When I
release a lock that somebody marked as having lots of contention, I will
clear the contention flag, and then just delay myself").

Side note: that trivial approach only really helps for a *single* thread
that gets it very much (like the example in wait_task_inactive). For true
contention with multiple different CPU's that can *all* have the bad
behaviour, you do actually need real queueing.

Linus
-
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/