aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-04-05 15:47:49 -0400
committerRobert Haas <rhaas@postgresql.org>2016-04-05 15:47:49 -0400
commit09adc9a8c09c9640de05c7023b27fb83c761e91c (patch)
treed49e850574d39aa1204b2ad332d729f2a0725bcc
parent1d2fe56e42640613781fc17ab1534fd0551de9bd (diff)
downloadpostgresql-09adc9a8c09c9640de05c7023b27fb83c761e91c.tar.gz
postgresql-09adc9a8c09c9640de05c7023b27fb83c761e91c.zip
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
-rw-r--r--src/backend/storage/ipc/shmem.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 81506eaffd0..1ad68cda4e5 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -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);