aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2018-07-25 10:58:44 +1200
committerThomas Munro <tmunro@postgresql.org>2018-07-25 11:00:42 +1200
commitf2db5f3bb0b5d429e9fa5b093936f8524e4192b1 (patch)
tree89bc0090f8ae3a72871ba984f0d180a64ad5ff8f /src
parente0a2a4c87f22a9031fd5af7ca70fa76809609c12 (diff)
downloadpostgresql-f2db5f3bb0b5d429e9fa5b093936f8524e4192b1.tar.gz
postgresql-f2db5f3bb0b5d429e9fa5b093936f8524e4192b1.zip
Pad semaphores to avoid false sharing.
In a USE_UNNAMED_SEMAPHORES build, the default on Linux and FreeBSD since commit ecb0d20a, we have an array of sem_t objects. This turned out to reduce performance compared to the previous default USE_SYSV_SEMAPHORES on an 8 socket system. Testing showed that the lost performance could be regained by padding the array elements so that they have their own cache lines. This matches what we do for similar hot arrays (see LWLockPadded, WALInsertLockPadded). Back-patch to 10, where unnamed semaphores were adopted as the default semaphore interface on those operating systems. Author: Thomas Munro Reviewed-by: Andres Freund Reported-by: Mithun Cy Tested-by: Mithun Cy, Tom Lane, Thomas Munro Discussion: https://postgr.es/m/CAD__OugYDM3O%2BdyZnnZSbJprSfsGFJcQ1R%3De59T3hcLmDug4_w%40mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/port/posix_sema.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c
index a2cabe58fcb..5174550794b 100644
--- a/src/backend/port/posix_sema.c
+++ b/src/backend/port/posix_sema.c
@@ -41,13 +41,19 @@
#error cannot use named POSIX semaphores with EXEC_BACKEND
#endif
+typedef union SemTPadded
+{
+ sem_t pgsem;
+ char pad[PG_CACHE_LINE_SIZE];
+} SemTPadded;
+
/* typedef PGSemaphore is equivalent to pointer to sem_t */
typedef struct PGSemaphoreData
{
- sem_t pgsem;
+ SemTPadded sem_padded;
} PGSemaphoreData;
-#define PG_SEM_REF(x) (&(x)->pgsem)
+#define PG_SEM_REF(x) (&(x)->sem_padded.pgsem)
#define IPCProtection (0600) /* access/modify by user only */