]> granicus.if.org Git - postgresql/commit
Reduce the number of semaphores used under --disable-spinlocks.
authorRobert Haas <rhaas@postgresql.org>
Wed, 8 Jan 2014 23:49:14 +0000 (18:49 -0500)
committerRobert Haas <rhaas@postgresql.org>
Wed, 8 Jan 2014 23:58:00 +0000 (18:58 -0500)
commitdaa7527afc2274432094ebe7ceb03aa41f916607
treeb866fc0ceefc0e0be723bb0574f290c05f9487bc
parent3739e5ab93afb21b69da2e42f6e161ef63aa95c8
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.
src/backend/postmaster/postmaster.c
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/shmem.c
src/backend/storage/lmgr/spin.c
src/include/pg_config_manual.h
src/include/storage/s_lock.h
src/include/storage/spin.h