False Sharing - Cache misses and cache line contention

Naprawdę ciekawy artykuł. Otwiera oczy na całkiem ciekawe powody problemów z wydajnością na kilku procesorach.


The general case to watch out for is when you have two objects or fields that are frequently accessed (either read or written) by different threads, at least one of the threads is doing writes, and the objects are so close in memory that they're on the same cache line because they are:

  • objects nearby in the same array, as in Example 1 above;

  • fields nearby in the same object, as in Example 4 of [3] where the head and tail pointers into the message queue had to be kept apart;

  • objects allocated close together in time (C++, Java) or by the same thread (C#, Java), as in Example 4 of [3] where the underlying list nodes had to be kept apart to eliminate contention when threads used adjacent or head/tail nodes;

  • static or global objects that the linker decided to lay out close together in memory;

  • objects that become close in memory dynamically, as when during compacting garbage collection two objects can become adjacent in memory because intervening objects became garbage and were collected; or

  • objects that for some other reason accidentally end up close together in memory.

0 komentarze:

Prześlij komentarz

Tomasz Kulig