3 ms·
There are two points. One is that having just one thread access the data structure gives optimal cache locality. The other is that locking causes full seriali
by jsnell 9y ago
There are two points.
One is that having just one thread access the data structure gives optimal cache locality.
The other is that locking causes full serialization: if 8 threads want to access a data structure protected by a lock at the same time, you need 8 full cache coherency round-trips. Locking also causes lots of ping-pong on the cache line that contains the lock. This scheme does away with the serialization by allowing batching of operations. If 8 threads need to access a data structure at the same time, their requests can be handled in a single round-trip. It does away with the ping-pong by making every single cache-line have just one writer. (I think it doesn't need locks or atomic ops, just TSO.)
Which isn't to say it's a free lunch. Two probable downsides:
You need to care about whether you have the right mix of threads doing real work and threads that are just thin shims on some data structure.
I bet that the data structure threads have to be polling for requests in a busy-loop for this scheme to have good performance. This would be a major problem for most applications.
- jeriksson 9y agoYou are right, the "data structure threads", which we call servers, poll on requests in a busy loop. If your data structures aren't very busy, dedicating a thread to serving the data structures may not be a good trade-off, in which case you don't want to use delegation. Note, however, that a single server can host any number of data structures, core counts are growing rapidly, and hyperthreading doubles the number of available hardware threads, making the trade-off easier to swallow.