pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Konstantin Belousov <kostikbel@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Maxim Sobolev <sobomax@freebsd.org>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14206: Switch to using POSIX semaphores on FreeBSD
Date: Wed, 22 Jun 2016 18:00:30 +0300
Message-ID: <20160622150030.GT38613@kib.kiev.ua> (raw)
In-Reply-To: <30087.1466606930@sss.pgh.pa.us>
References: <20160621193412.5792.65085@wrigleys.postgresql.org>
	<16860.1466539165@sss.pgh.pa.us>
	<CAH7qZfuEgJ4RfRy2NXEn1CMy8QRDjbaqmrne6f3NYgekjRLBzg@mail.gmail.com>
	<18145.1466541362@sss.pgh.pa.us>
	<20160622100014.GL38613@kib.kiev.ua>
	<30087.1466606930@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Wed, Jun 22, 2016 at 10:48:50AM -0400, Tom Lane wrote:
> Konstantin Belousov <kostikbel@gmail.com> writes:
> > On Tue, Jun 21, 2016 at 04:36:02PM -0400, Tom Lane wrote:
> >> If that seems like a competitive alternative for you, it'd be nice to have
> >> a platform where we use unnamed POSIX semaphores by default.  I'm a little
> >> worried about whether that code has suffered bit-rot, since it's been
> >> sitting there basically unused for so long.
> 
> > On FreeBSD, there is no practical difference in the resource consumption
> > for named vs. unnamed semaphore. I mean that after sem_open(3) call, an
> > open file descriptor is not kept in the process fd table. The semaphore
> > is represented by the mmaped page, libc+kernel operate solely on the
> > page content and use umtx(2) to implement counted semaphore.
> 
> Is there any kernel-side resource at all?  The thing that concerns me
> about the POSIX APIs is that it's not very clear whether anything gets
> left behind if the database crashes.  The Linux man page for sem_destroy
> says
> 
>        An unnamed semaphore should be destroyed with sem_destroy() before  the
>        memory  in  which it is located is deallocated.  Failure to do this can
>        result in resource leaks on some implementations.
> 
> and while they don't say that their own implementation has such a problem,
> it's worrisome.  We go to some lengths to ensure that we can recycle SysV
> semaphores after a crash, but there's no equivalent logic in the POSIX
> semaphore code, and I don't see how it would even be possible to identify
> leftover "unnamed" semaphores.
On FreeBSD, it is only a memory page which is mmaped into all
processes-consumers of the unnamed semaphore. Of course, if the process
is blocked on semaphore, there is some bookkeeping done in kernel so
that post would find all waiters. But it is lightweight and automatically
released on wakeup.  In other words, there is nothing to worry about
WRT cleanup after kill of unnamed semaphore consumers.  Same for named,
but there the file is left around.

> 
> > That said, the problem with the SysV semaphores is that API allows
> > operations on arbitrary sets of the semaphores. Unless some unordinary
> > and complex measures are taken, implementation has to use global
> > internal lock to synchronize semop(2). This is what I noted in the
> > paper.
> 
> It's certainly true that semop(2) is more complicated than we need.
> But in practice, we only call semop(2) when we need to sleep, or to
> awaken a sleeping process, so I'm not sure that performance of it
> matters a lot to us.
Issue is that the sleeps and wakeups on SysV semaphores do not scale,
at least on FreeBSD.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (14+ messages)  latest in thread

Message-ID: <20160622150030.GT38613@kib.kiev.ua>
Permalink:  ../20160622150030.GT38613@kib.kiev.ua/
Also on:    postgresql.org/message-id/20160622150030.GT38613@kib.kiev.ua

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kostikbel@gmail.com, tgl@sss.pgh.pa.us, sobomax@freebsd.org
  Subject: Re: BUG #14206: Switch to using POSIX semaphores on FreeBSD
  In-Reply-To: <20160622150030.GT38613@kib.kiev.ua>
  References: <20160621193412.5792.65085@wrigleys.postgresql.org> <16860.1466539165@sss.pgh.pa.us> <CAH7qZfuEgJ4RfRy2NXEn1CMy8QRDjbaqmrne6f3NYgekjRLBzg@mail.gmail.com> <18145.1466541362@sss.pgh.pa.us> <20160622100014.GL38613@kib.kiev.ua> <30087.1466606930@sss.pgh.pa.us> <20160622150030.GT38613@kib.kiev.ua>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox