Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dual socket vs single socket memory model?

Tags:

c++

c

linux

memory

I am a bit confused about what memory looks like in a dual CPU machine from the perspective of a C/C++ program running on Linux.

Case 1 (understood)

With one quad-core HT CPU, 32GB RAM, I can, in theory, write a single process application, using up to 8 threads and up to 32GB RAM without going into swap or overloading the threading facilities - I am ignore the OS and other processes here for simplicity.

Case 2 (confusion)

What happens with a dual quad-core HT CPU with 64GB RAM set up?

Development-wise, do you need to write an application to run as two processes (8 threads, 32GB each) that communicate or can you write it as one process (16 threads, 64GB full memory)?

If the answer is the former, what are some efficient modern strategies to utilize the entire hardware? shm? IPC? Also, how do you direct Linux to use a different CPU for each process?

like image 849
kfmfe04 Avatar asked Mar 22 '13 04:03

kfmfe04


1 Answers

From the application's viewpoint, the number of physical CPUs (dies) doesn't matter. Only the number of virtual processors. These include all cores on all processors, and double, if hyperthreading is enabled on a core. Threads are scheduled on them in the same way. It doesn't matter if the cores are all on one die or spread across multiple dies.

In general, the best way to handle these things is to not. Don't worry about what's running on which core. Just spawn an appropriate number of threads for your application, (up to a theoretical maximum equal to the total number of cores in the system), and let the OS deal with the scheduling.

The memory is shared amongst all cores in the system, of course. But again, it's up the OS to handle allocation of physical memory. Very few applications really need to worry about how much memory they use, and divvying up that memory between threads. Let the OS handle that.

like image 196
Jonathon Reinhart Avatar answered Oct 24 '22 20:10

Jonathon Reinhart