Re: Poor thread performance on Linux vs. Solaris
Jakub Jelinek <[email protected]>
| Newsgroups | gmane.comp.lib.phil |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Sep 09, 2003 at 03:38:57PM +0800, Hu, Boris wrote:
> Try the futex_q_lock-0.2 patch. It is also against linux-2.6.0-test4.
>
> It does the following things:
> * Remove the global futex_lock as the previous futex_q_lock patch did.
> * Add bucket spinlock recursively check as Jakub mentioned.
> * Move vcache_lock out of lock/unlock_futex_mm() and only to protect the actual vcache operations.
> * Shrink some lock/unlock_futex_mm() scopes.
> @@ -231,26 +244,38 @@
> if (!page2)
> goto out;
>
> - head1 = hash_futex(page1, offset1);
> - head2 = hash_futex(page2, offset2);
> + unlock_futex_mm();
>
> + bh1 = hash_futex(page1, offset1);
> + bh2 = hash_futex(page2, offset2);
> + spin_lock(&bh1->lock);
> + if (bh1 != bh2)
> + spin_lock(&bh2->lock);
> + head1 = &bh1->chain;
> + head2 = &bh2->chain;
> +
But the AB BA deadlock is still there unless I'm missing something.
I'd write:
+ bh1 = hash_futex(page1, offset1);
+ bh2 = hash_futex(page2, offset2);
+ if (bh1 < bh2) {
+ spin_lock(&bh1->lock);
+ spin_lock(&bh2->lock);
+ } else {
+ spin_lock(&bh2->lock);
+ if (bh1 > bh2)
+ spin_lock(&bh1->lock);
+ }
+ head1 = &bh1->chain;
+ head2 = &bh2->chain;
> @@ -260,7 +285,9 @@
> }
>
> out:
> - unlock_futex_mm();
> + if (bh1 != bh2)
> + spin_unlock(&bh2->lock);
> + spin_unlock(&bh1->lock);
+ if (bh1 < bh2) {
+ spin_unlock(&bh2->lock);
+ spin_unlock(&bh1->lock);
+ } else {
+ if (bh1 > bh2)
+ spin_unlock(&bh1->lock);
+ spin_unlock(&bh2->lock);
+ }
Jakub