Nameless IPC on POSIX systems

From: des(at)des(dot)no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=)
To: pgsql-patches(at)postgresql(dot)org
Subject: Nameless IPC on POSIX systems
Date: 2005-05-06 12:36:33
Message-ID: 868y2s1qge.fsf@xps.des.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

The attached patch implements new semaphore and shared memory
mechanisms for POSIX systems.

Semaphores are implemented using unnamed pipes. A semaphore is
incremented by writing a single character to the pipe, and decremented
by reading a single character. The only semaphore operation we can't
reliably simulate in this manner is sem_getvalue(), but PostgreSQL
doesn't use it.

Shared memory is implemented using file-less (swap-backed) mmap(),
either with MAP_ANON on systems which support it, or with /dev/zero
(SysV-style). Note that I've only tested this on systems which
support MAP_ANON, so there may be bugs in the /dev/zero code.

One system which will definitely benefit from this is FreeBSD.
FreeBSD has both SysV and POSIX semaphores and shared memory, but
unnamed POSIX semaphores can't be shared between processes, and POSIX
shared memory is implemented using plain files, so the POSIX
primitives can't be used. The SysV primitives use a global namespace,
which causes problems when multiple PostgreSQL instances run in
separate jails (they can't run on the same port, and a compromised
postmaster in one jail can be used to crash postmasters in other
jails)

The patch was developed and tested on FreeBSD 6, and has also been
tested cursorily on SuSE Linux 9.2. It passes 'make check', and osdb
(for what it's worth) shows no difference in performance between
patched and unpatched postmasters built from the same source.

Remember to run autoconf and configure before testing, as the patch
modifies configure.in and the FreeBSD and Linux templates.

DES
--
Dag-Erling Smørgrav - des(at)des(dot)no

Attachment Content-Type Size
pgsql_ipc.diff text/x-patch 16.3 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-05-06 15:01:47 Re: Nameless IPC on POSIX systems
Previous Message Emmanuel Bernard 2005-05-06 10:13:03 Blob .getBytes position should start at 1