0

I am trying to understand False sharing and cache alignment and its impact on performance on Multi core systems.Here is my case and I am trying to understand at the very high level.

Threads : 2 
CPUS/Cores : 4
Locks : 1 per each Thread T1, T2
Data Structures : Each thread has 32k Size Structure which has several nested arrays and structures.
Language : C 

I have 2 threads and 4 cores/CPU that can service the 2 threads at any given time.Now my threads continuously deal with writing and reading their respective data structures which are fairly large close to 32K size. Each threads are independent of each other and do not write/read Data structures of other threads.Threads always held a lock starting of their time slice.

Given my above case, are there any chances of false sharing or any negative impact that can hinder the performance. I assume there wouldnt be any false sharing since each thread works on their own data Structure and takes a lock at the very beginning of thread time slice.

vip
  • 53
  • 1
  • 6

1 Answers1

0

I can think of two unlikely scenarios where false sharing can happen.

Suppose your thread 1 is running on core 1. After a while, it migrate to core 2 and resume execution. When running on core 2, it could try to access a cache line that is already cached in core 1. So the situation is similar to the cache line being shared across core 1 and 2.

Per thread data structures have been allocated from the shared memory. If you are not been careful to pad them to align to cache lines, last element of one data structure and first of the next, could be allocated in the same cache line.

Isuru H
  • 1,191
  • 1
  • 8
  • 11