pgsql: Reduce the number of semaphores used under --disable-spinlocks.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Reduce the number of semaphores used under --disable-spinlocks.
Date: 2014-01-08 23:58:16
Message-ID: E1W130q-0001E6-5i@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/daa7527afc2274432094ebe7ceb03aa41f916607

Modified Files
--------------
src/backend/postmaster/postmaster.c | 9 +++++++
src/backend/storage/ipc/ipci.c | 1 +
src/backend/storage/ipc/shmem.c | 21 ++++++++++++---
src/backend/storage/lmgr/spin.c | 50 ++++++++++++++++++++++-------------
src/include/pg_config_manual.h | 8 ++++++
src/include/storage/s_lock.h | 2 +-
src/include/storage/spin.h | 6 +++++
7 files changed, 74 insertions(+), 23 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2014-01-09 01:19:16 pgsql: Fix "cannot accept a set" error when only some arms of a CASE re
Previous Message Heikki Linnakangas 2014-01-08 21:33:07 pgsql: If multiple recovery_targets are specified, use the latest one.

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2014-01-09 00:03:55 Re: Standalone synchronous master
Previous Message Josh Berkus 2014-01-08 23:56:06 Re: Standalone synchronous master