linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -v5 0/5] x86,smp: make ticket spinlock proportional backoff w/ auto tuning
@ 2013-02-06 20:03 Rik van Riel
  2013-02-06 20:04 ` [PATCH -v5 1/5] x86,smp: move waiting on contended ticket lock out of line Rik van Riel
                   ` (5 more replies)
  0 siblings, 6 replies; 54+ messages in thread
From: Rik van Riel @ 2013-02-06 20:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: aquini, eric.dumazet, lwoodman, knoel, chegu_vinod,
	raghavendra.kt, mingo

[-- Attachment #1: Type: text/plain, Size: 3555 bytes --]

Many spinlocks are embedded in data structures; having many CPUs
pounce on the cache line the lock is in will slow down the lock
holder, and can cause system performance to fall off a cliff.

The paper "Non-scalable locks are dangerous" is a good reference:

	http://pdos.csail.mit.edu/papers/linux:lock.pdf

In the Linux kernel, spinlocks are optimized for the case of
there not being contention. After all, if there is contention,
the data structure can be improved to reduce or eliminate
lock contention.

Likewise, the spinlock API should remain simple, and the
common case of the lock not being contended should remain
as fast as ever.

However, since spinlock contention should be fairly uncommon,
we can add functionality into the spinlock slow path that keeps
system performance from falling off a cliff when there is lock
contention.

Proportional delay in ticket locks is delaying the time between
checking the ticket based on a delay factor, and the number of
CPUs ahead of us in the queue for this lock. Checking the lock
less often allows the lock holder to continue running, resulting
in better throughput and preventing performance from dropping
off a cliff.

The test case has a number of threads locking and unlocking a
semaphore. With just one thread, everything sits in the CPU
cache and throughput is around 2.6 million operations per
second, with a 5-10% variation.

Once a second thread gets involved, data structures bounce
from CPU to CPU, and performance deteriorates to about 1.25
million operations per second, with a 5-10% variation.

However, as more and more threads get added to the mix,
performance with the vanilla kernel continues to deteriorate.
Once I hit 24 threads, on a 24 CPU, 4 node test system,
performance is down to about 290k operations/second.

With a proportional backoff delay added to the spinlock
code, performance with 24 threads goes up to about 400k
operations/second with a 50x delay, and about 900k operations/second
with a 250x delay. However, with a 250x delay, performance with
2-5 threads is worse than with a 50x delay.

Making the code auto-tune the delay factor results in a system
that performs well with both light and heavy lock contention,
and should also protect against the (likely) case of the fixed
delay factor being wrong for other hardware.

The attached graph shows the performance of the multi threaded
semaphore lock/unlock test case, with 1-24 threads, on the
vanilla kernel, with 10x, 50x, and 250x proportional delay,
as well as the v1 patch series with autotuning for 2x and 2.7x
spinning before the lock is obtained, and with the v2 series.

The v2 series integrates several ideas from Michel Lespinasse
and Eric Dumazet, which should result in better throughput and
nicer behaviour in situations with contention on multiple locks.

For the v3 series, I tried out all the ideas suggested by
Michel. They made perfect sense, but in the end it turned
out they did not work as well as the simple, aggressive
"try to make the delay longer" policy I have now. Several
small bug fixes and cleanups have been integrated.

For the v4 series, I added code to keep the maximum spinlock
delay to a small value when running in a virtual machine. That
should solve the performance regression seen in virtual machines.

The v5 series has cleanups suggested by Ingo Molnar and Borislav
Petkov.

Performance is within the margin of error of v2, so the graph
has not been update.

Please let me know if you manage to break this code in any way,
so I can fix it...

-- 
All rights reversed.


[-- Attachment #2: spinlock-backoff-v2.png --]
[-- Type: image/png, Size: 21964 bytes --]

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2013-03-01 18:52 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06 20:03 [PATCH -v5 0/5] x86,smp: make ticket spinlock proportional backoff w/ auto tuning Rik van Riel
2013-02-06 20:04 ` [PATCH -v5 1/5] x86,smp: move waiting on contended ticket lock out of line Rik van Riel
2013-02-13 12:06   ` [tip:core/locking] x86/smp: Move " tip-bot for Rik van Riel
2013-02-13 16:20     ` Linus Torvalds
2013-02-13 18:30       ` Linus Torvalds
2013-02-14  0:54         ` H. Peter Anvin
2013-02-14  1:31           ` Linus Torvalds
2013-02-14  1:56             ` H. Peter Anvin
2013-02-14 10:50         ` Ingo Molnar
2013-02-14 16:10           ` Linus Torvalds
2013-02-15 15:57             ` Ingo Molnar
2013-02-15  6:48         ` Benjamin Herrenschmidt
2013-02-13 19:08       ` Rik van Riel
2013-02-13 19:36         ` Linus Torvalds
2013-02-13 22:21           ` Rik van Riel
2013-02-13 22:40             ` Linus Torvalds
2013-02-13 23:41               ` Rik van Riel
2013-02-14  1:21                 ` Linus Torvalds
2013-02-14  1:46                   ` Linus Torvalds
2013-02-14 10:43                   ` Ingo Molnar
2013-02-27 16:42                   ` Rik van Riel
2013-02-27 17:10                     ` Linus Torvalds
2013-02-27 19:53                       ` Rik van Riel
2013-02-27 20:18                         ` Linus Torvalds
2013-02-27 21:55                           ` Rik van Riel
     [not found]                             ` <CA+55aFwa0EjGG2NUDYVLVBmXJa2k81YiuNO2yggk=GLRQxhhUQ@mail.gmail.com>
2013-02-28  2:58                               ` Rik van Riel
2013-02-28  3:19                                 ` Linus Torvalds
2013-02-28  4:06                                 ` Davidlohr Bueso
2013-02-28  4:49                                   ` Linus Torvalds
2013-02-28 15:13                                     ` Rik van Riel
2013-02-28 18:22                                       ` Linus Torvalds
2013-02-28 20:26                                         ` Linus Torvalds
2013-02-28 21:14                                           ` Rik van Riel
2013-02-28 21:58                                             ` Linus Torvalds
2013-02-28 22:38                                               ` Rik van Riel
2013-02-28 23:09                                                 ` Linus Torvalds
2013-03-01  6:42                                                   ` Rik van Riel
2013-03-01 18:18                                                     ` Davidlohr Bueso
2013-03-01 18:50                                                       ` Rik van Riel
2013-03-01 18:52                                                       ` Linus Torvalds
2013-02-06 20:04 ` [PATCH -v5 2/5] x86,smp: proportional backoff for ticket spinlocks Rik van Riel
2013-02-13 12:07   ` [tip:core/locking] x86/smp: Implement " tip-bot for Rik van Riel
2013-02-06 20:05 ` [PATCH -v5 3/5] x86,smp: auto tune spinlock backoff delay factor Rik van Riel
2013-02-13 12:08   ` [tip:core/locking] x86/smp: Auto " tip-bot for Rik van Riel
2013-02-06 20:06 ` [PATCH -v5 4/5] x86,smp: keep spinlock delay values per hashed spinlock address Rik van Riel
2013-02-13 12:09   ` [tip:core/locking] x86/smp: Keep " tip-bot for Eric Dumazet
2013-02-06 20:07 ` [PATCH -v5 5/5] x86,smp: limit spinlock delay on virtual machines Rik van Riel
2013-02-07 11:11   ` Ingo Molnar
2013-02-07 21:24     ` [PATCH fix " Rik van Riel
2013-02-13 12:10       ` [tip:core/locking] x86/smp: Limit " tip-bot for Rik van Riel
2013-02-07 11:25   ` [PATCH -v5 5/5] x86,smp: limit " Stefano Stabellini
2013-02-07 11:59     ` Raghavendra K T
2013-02-07 13:28     ` Rik van Riel
2013-02-06 20:08 ` [PATCH -v5 6/5] x86,smp: add debugging code to track spinlock delay value Rik van Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).