title: Is there any performance advantage to tightly packing allocations in memory greater than page size?
body: <p>It's fairly standard optimization lore at this point that if you can keep your data structures smaller and flatter (fewer levels of indirection) you can often reap performance benefits because you will fit more data in cache, and later loads will have a greater chance of being on the same cache line as earlier loads, and later loads will have a greater chance of being on the same page so they will benefit from the same hot TLB entry.</p>
  <p>However it's unclear to me if there is much benefit to trying to keep large allocations tightly packed. For example if you have two allocations, each of which is made up of many pages, is there still any benefit to trying to make sure those two allocations are adjacent? They necessarily are going to have disjoint TLB entries and cache lines anyway. Maybe there is some small benefit that if you are reading one allocation to the end the processor might prefetch the beginning of the next allocation, but I suspect this situation is rare in most applications, because if it were the common case you probably would have just made one larger allocation in the first place (although I would be curious to hear examples to the contrary).</p>
  <p>Are there any other architectural artifacts that make tight in memory packing worthwhile, when your allocations are larger than page size?</p>
  <p>If not the practical implication is that you should never bother to try packing very large allocations/objects next to each other and can save yourself some optimization headache.</p>