From: Noah Misch <noah@leadboat.com>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Bernd Helmle <mailings@oopsware.de>
Subject: Re: Deadlock in XLogInsert at AIX
Date: Fri, 3 Feb 2017 00:26:50 +0000
Message-ID: <20170203002650.GA775605@tornado.leadboat.com> (raw)
In-Reply-To: <15802dd8-4601-d9d2-3388-35dcb326b4a2@iki.fi>
References: <a72cfcb0-37d0-de2f-b3ec-f38ad8d6a8cc@postgrespro.ru>
<0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi>
<85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru>
<2c4037f1-b35d-4d71-0d32-40a97523b31c@postgrespro.ru>
<5de6b64a-f842-9166-e41a-ed7b87a2729b@iki.fi>
<7609057e-b021-56d8-afb6-27acc1dfdeea@postgrespro.ru>
<15802dd8-4601-d9d2-3388-35dcb326b4a2@iki.fi>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On Wed, Feb 01, 2017 at 02:39:25PM +0200, Heikki Linnakangas wrote:
> On 02/01/2017 01:07 PM, Konstantin Knizhnik wrote:
> >Attached please find my patch for XLC/AIX.
> >The most critical fix is adding __sync to pg_atomic_fetch_add_u32_impl.
> >The comment in this file says that:
> >
> > * __fetch_and_add() emits a leading "sync" and trailing "isync",
> >thereby
> > * providing sequential consistency. This is undocumented.
> >
> >But it is not true any more (I checked generated assembler code in
> >debugger).
> >This is why I have added __sync() to this function. Now pgbench working
> >normally.
Konstantin, does "make -C src/bin/pg_bench check" fail >10% of the time in the
bad build?
> Seems like it was not so much undocumented, but an implementation detail
> that was not guaranteed after all..
Seems so.
> There was a long thread on these things the last time this was changed: https://www.postgresql.org/message-id/20160425185204.jrvlghn3jxulsb7i%40alap3.anarazel.de.
> I couldn't find an explanation there of why we thought that fetch_and_add
> implicitly performs sync and isync.
It was in the generated code, for AIX xlc 12.1.0.0.
> >Also there is mysterious disappearance of assembler section function
> >with sync instruction from pg_atomic_compare_exchange_u32_impl.
> >I have fixed it by using __sync() built-in function instead.
>
> __sync() seems more appropriate there, anyway. We're using intrinsics for
> all the other things in generic-xlc.h. But it sure is scary that the "asm"
> sections just disappeared.
That is a problem, but it's a stretch to conclude that asm sections are
generally prone to removal, while intrinsics are generally durable.
> @@ -73,11 +73,19 @@ pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr,
> static inline uint32
> pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_)
> {
> + uint32 ret;
> +
> /*
> - * __fetch_and_add() emits a leading "sync" and trailing "isync", thereby
> - * providing sequential consistency. This is undocumented.
> + * Use __sync() before and __isync() after, like in compare-exchange
> + * above.
> */
> - return __fetch_and_add((volatile int *)&ptr->value, add_);
> + __sync();
> +
> + ret = __fetch_and_add((volatile int *)&ptr->value, add_);
> +
> + __isync();
> +
> + return ret;
> }
Since this emits double syncs with older xlc, I recommend instead replacing
the whole thing with inline asm. As I opined in the last message of the
thread you linked above, the intrinsics provide little value as abstractions
if one checks the generated code to deduce how to use them. Now that the
generated code is xlc-version-dependent, the port is better off with
compiler-independent asm like we have for ppc in s_lock.h.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
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-hackers@postgresql.org
Cc: noah@leadboat.com, hlinnaka@iki.fi, k.knizhnik@postgrespro.ru, mailings@oopsware.de
Subject: Re: Deadlock in XLogInsert at AIX
In-Reply-To: <20170203002650.GA775605@tornado.leadboat.com>
References: <a72cfcb0-37d0-de2f-b3ec-f38ad8d6a8cc@postgrespro.ru> <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi> <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru> <2c4037f1-b35d-4d71-0d32-40a97523b31c@postgrespro.ru> <5de6b64a-f842-9166-e41a-ed7b87a2729b@iki.fi> <7609057e-b021-56d8-afb6-27acc1dfdeea@postgrespro.ru> <15802dd8-4601-d9d2-3388-35dcb326b4a2@iki.fi> <20170203002650.GA775605@tornado.leadboat.com>
* 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