Re: atomics.h may not be included from frontend code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Anastasia Lubennikova <a(dot)lubennikova(at)postgrespro(dot)ru>
Subject: Re: atomics.h may not be included from frontend code
Date: 2018-02-27 15:36:01
Message-ID: CA+TgmoYNKTJB6S1FS4Sj0t1qJxUazay-urRxhkjDgzSh8aCgAA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Feb 27, 2018 at 8:49 AM, Aleksander Alekseev
<a(dot)alekseev(at)postgrespro(dot)ru> wrote:
> We would like to know whether you share this concern and whether it
> would be a good idea to try to refactor the code so that atomics could
> be used not only from the backend.

I think the concern on the referenced threads was that atomics might
be implemented using spinlocks if we don't have a real atomics
implementation; and those in turn might be implemented as semaphores
if we don't have a real spinlock implementation. When we emulate
atomics using spinlocks, we use a fixed-size array of spinlocks stored
in shared memory; and when we emulate spinlocks using semaphore, we
use the semaphores in each PGPROC. So those emulation layers are
deeply tied into the backend's shared-memory architecture, and
untangling them might be a bit complicated.

However, those are presumably rare configurations that many people
(including many developers) don't care about. If #include "atomics.h"
worked from all frontend code except where one of those emulation
layers were in use, that would represent an improvement over the
current status quo for people doing out-of-core development against
PostgreSQL. On the other hand, it would also make it quite easy for
the use of atomics to creep into frontend code within PG itself, and
that's not OK so long as configurations that lack atomics and/or
spinlocks are considered supported. So that's something to think
about.

I have to imagine that systems which lack atomics and/or spinlocks are
almost extinct. It looks like we have at least one buildfarm member
running with each of --disable-spinlocks and --disable-atomics, but
systems that organically lack spinlocks and/or atomics must by now be
extremely rare. At some point, I think we should just de-support such
configurations, but I'm not sure if we're at that point yet.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Claudio Freire 2018-02-27 15:54:04 Re: [HACKERS] [PATCH] Vacuum: Update FSM more frequently
Previous Message Noah Misch 2018-02-27 15:21:26 Re: MSVC builld of 9.5.12 is broken?