title: Performance difference between IPC shared memory and threads memory
body: <p>I hear frequently that accessing a shared memory segment between processes has no performance penalty compared to accessing process memory between threads. In other words, a multi-threaded application will not be faster than a set of processes using shared memory (excluding locking or other synchronization issues).</p>
  
  <p>But I have my doubts:</p>
  
  <p>1) shmat() maps the local process virtual memory to the shared segment. This translation has to be performed for each shared memory address and can represent a significant cost. In a multi-threaded application there is no extra translation required: all VM addresses are converted to physical addresses, just like in a regular process that does not access shared memory.</p>
  
  <p>2) The shared memory segment must be maintained <em>somehow</em> by the kernel. For example, when all processes attached to the shm are taken down, the shm segment is still up and can be eventually re-accessed by newly started processes. There could be some overhead related to kernel operations on the shm segment.</p>
  
  <p>Is a multi-process shared memory system as fast as a multi-threaded application?</p>