False Sharing on a Shared Cache Line

Workers updating different memory locations can still contend if those locations occupy the same cache line under a coherence protocol.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two counters
  2. Measure under comparable layout
  3. Trace independent counters that occupy one cache line
  4. Verify layout and measure the claimed effect

Trace two counters

Each of two threads can update its own counter without sharing the counter value. If the adjacent counters occupy one line, writes can still affect which core holds a usable copy. Layout and addresses explain the possible adjacency.

Measure under comparable layout

A changed layout can reduce contention but increase memory use. Check performance and correctness under the actual worker scenario. See paired benchmarks.[1]

Trace independent counters that occupy one cache line

Two threads update distinct counters. If the counters share one cache line, a coherence implementation may move write ownership between cores even though neither reads the other's counter. Separating frequently written fields can help under some layouts and workloads. See performance and allocation metrics.

Thread A writes counter A
Thread B writes counter B
Both counters share one line → possible coherence traffic
Compare with separate lines under the same task mix

Verify layout and measure the claimed effect

Padding can increase working-set size. Distinguish this situation from both threads touching the same counter. Use representative placement and compare correctness and throughput.

References

  1. OpenMP Architecture Review Board, OpenMP API Specifications ↩