title: Does the distance between a program's stack and data segment have an effect on CPU caching?
body: <p>I've read that on linux, program memory layout can be broadly visualized as follows (and I assume it's similar on most other operating systems):</p>
  
  <p><img src="https://i.stack.imgur.com/71WYo.png" alt="memory layout"></p>
  
  <p>Now, I'm not sure if I remember correctly, but I think CPUs read fairly large chunks of adjacent RAM addresses into their largest cache level in a single go. If so, it would make sense from a performance point of view to keep all of a program's data within the shortest possible memory range in order to prevent cache misses.</p>
  
  <p>However, if that's the case, it would seem better to flip things around and put the upward growing part (text, global data, and heap) on top of the downward growing part (cl args, env vars, and stack). But I guess the truth is a little more complicated than that? Does it matter at all if the data segment is in a completely different part of memory from the stack?</p>