0

In our system, I try to modify all the main data structure with

__attribute__((__aligned__(CACHE_LINE_SIZE)))

It does not improve any performance actually. How can we use cache align and measure how it helps?

1

1 Answer 1

2

Cache aligning only improves performance if the data is false shared across threads. what does that mean? If you have 2 fields, one of them shared and updated frequently, and one not, and they are in the same cache line then accessing the 'cold' field (the one not frequently updated) imposes the same penalty as accessing the 'hot' one, because updates of the 'hot' field invalidate other threads (CPU threads) entire cache line, thus invalidating the 'cold' field too. A similar case is when two 'hot' fields share the cache line and invalidate each other.

For other cases, cache align does not improve performance and may in fact hurt performance by increasing data size.

To consider cache align you need:

  • concurrency
  • hot data (frequent InterlockCompareExchange or similar ops)
  • some other data in the cache line (hot or cold, depends on the use case)

I recommend Scott Meyer's talk CPU Caches and Why You Care.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.