summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2014-01-08 18:49:14 -0500
committerRobert Haas <rhaas@postgresql.org>2014-01-08 18:58:00 -0500
commitdaa7527afc2274432094ebe7ceb03aa41f916607 (patch)
treeb866fc0ceefc0e0be723bb0574f290c05f9487bc /src/include
parent3739e5ab93afb21b69da2e42f6e161ef63aa95c8 (diff)
Reduce the number of semaphores used under --disable-spinlocks.
Instead of allocating a semaphore from the operating system for every spinlock, allocate a fixed number of semaphores (by default, 1024) from the operating system and multiplex all the spinlocks that get created onto them. This could self-deadlock if a process attempted to acquire more than one spinlock at a time, but since processes aren't supposed to execute anything other than short stretches of straight-line code while holding a spinlock, that shouldn't happen. One motivation for this change is that, with the introduction of dynamic shared memory, it may be desirable to create spinlocks that last for less than the lifetime of the server. Without this change, attempting to use such facilities under --disable-spinlocks would quickly exhaust any supply of available semaphores. Quite apart from that, it's desirable to contain the quantity of semaphores needed to run the server simply on convenience grounds, since using too many may make it harder to get PostgreSQL running on a new platform, which is mostly the point of --disable-spinlocks in the first place. Patch by me; review by Tom Lane.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/pg_config_manual.h8
-rw-r--r--src/include/storage/s_lock.h2
-rw-r--r--src/include/storage/spin.h6
3 files changed, 15 insertions, 1 deletions
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index 2387a434aa4..20c5ff0e902 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -57,6 +57,14 @@
#define NUM_USER_DEFINED_LWLOCKS 4
/*
+ * When we don't have native spinlocks, we use semaphores to simulate them.
+ * Decreasing this value reduces consumption of OS resources; increasing it
+ * may improve performance, but supplying a real spinlock implementation is
+ * probably far better.
+ */
+#define NUM_SPINLOCK_SEMAPHORES 1024
+
+/*
* Define this if you want to allow the lo_import and lo_export SQL
* functions to be executed by ordinary users. By default these
* functions are only available to the Postgres superuser. CAUTION:
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index b52f0e7f852..2297f772805 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -915,7 +915,7 @@ spin_delay(void)
* to fall foul of kernel limits on number of semaphores, so don't use this
* unless you must! The subroutines appear in spin.c.
*/
-typedef PGSemaphoreData slock_t;
+typedef int slock_t;
extern bool s_lock_free_sema(volatile slock_t *lock);
extern void s_unlock_sema(volatile slock_t *lock);
diff --git a/src/include/storage/spin.h b/src/include/storage/spin.h
index e7201652499..2ac510db7a0 100644
--- a/src/include/storage/spin.h
+++ b/src/include/storage/spin.h
@@ -69,5 +69,11 @@
extern int SpinlockSemas(void);
+extern Size SpinlockSemaSize(void);
+
+#ifndef HAVE_SPINLOCKS
+extern void SpinlockSemaInit(PGSemaphore);
+extern PGSemaphore SpinlockSemaArray;
+#endif
#endif /* SPIN_H */