Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFjk9-00045s-Tf for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Jun 2016 15:07:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bFjk9-0001ap-Ga for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Jun 2016 15:07:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bFje2-0006el-UH for pgsql-bugs@postgresql.org; Wed, 22 Jun 2016 15:00:47 +0000 Received: from kib.kiev.ua ([2001:470:d5e7:1::1]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bFjdz-000230-HA for pgsql-bugs@postgresql.org; Wed, 22 Jun 2016 15:00:45 +0000 Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u5MF0UQR089166 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 22 Jun 2016 18:00:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u5MF0UQR089166 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u5MF0UT0089165; Wed, 22 Jun 2016 18:00:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 22 Jun 2016 18:00:30 +0300 From: Konstantin Belousov To: Tom Lane Cc: Maxim Sobolev , pgsql-bugs@postgresql.org Subject: Re: BUG #14206: Switch to using POSIX semaphores on FreeBSD Message-ID: <20160622150030.GT38613@kib.kiev.ua> References: <20160621193412.5792.65085@wrigleys.postgresql.org> <16860.1466539165@sss.pgh.pa.us> <18145.1466541362@sss.pgh.pa.us> <20160622100014.GL38613@kib.kiev.ua> <30087.1466606930@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30087.1466606930@sss.pgh.pa.us> User-Agent: Mutt/1.6.1 (2016-04-27) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Wed, Jun 22, 2016 at 10:48:50AM -0400, Tom Lane wrote: > Konstantin Belousov 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