Align all shared memory allocations to cache line boundaries.

Experimentation shows this only costs about 6kB, which seems well
worth it given the major performance effects that can be caused
by insufficient alignment, especially on larger systems.

Discussion: 14166.1458924422@sss.pgh.pa.us
This commit is contained in:
Robert Haas 2016-04-05 15:47:49 -04:00
parent 1d2fe56e42
commit 09adc9a8c0
1 changed files with 10 additions and 2 deletions

View File

@ -171,9 +171,17 @@ ShmemAlloc(Size size)
void *newSpace;
/*
* ensure all space is adequately aligned.
* Ensure all space is adequately aligned. We used to only MAXALIGN this
* space but experience has proved that on modern systems that is not good
* enough. Many parts of the system are very sensitive to critical data
* structures getting split across cache line boundaries. To avoid that,
* attempt to align the beginning of the allocation to a cache line
* boundary. The calling code will still need to be careful about how it
* uses the allocated space - e.g. by padding each element in an array of
* structures out to a power-of-two size - but without this, even that
* won't be sufficient.
*/
size = MAXALIGN(size);
size = CACHELINEALIGN(size);
Assert(ShmemSegHdr != NULL);