pgsql: Remove volatiles from {procarray, volatile}.c and fix memory orde

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Remove volatiles from {procarray, volatile}.c and fix memory orde
Date: 2018-11-11 00:19:28
Message-ID: E1gLdTM-0001rU-Uf@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Remove volatiles from {procarray,volatile}.c and fix memory ordering issue.

The use of volatiles in procarray.c largely originated from the time
when postgres did not have reliable compiler and memory
barriers. That's not the case anymore, so we can do better.

Several of the functions in procarray.c can be bottlenecks, and
removal of volatile yields mildly better code.

The new state, with explicit memory barriers, is also more
correct. The previous use of volatile did not actually deliver
sufficient guarantees on weakly ordered machines, in particular the
logic in GetNewTransactionId() does not look safe. It seems unlikely
to be a problem in practice, but worth fixing.

Thomas and I independently wrote a patch for this.

Reported-By: Andres Freund and Thomas Munro
Author: Andres Freund, with cherrypicked changes from a patch by Thomas Munro
Discussion:
https://postgr.es/m/20181005172955.wyjb4fzcdzqtaxjq@alap3.anarazel.de
https://postgr.es/m/CAEepm=1nff0x=7i3YQO16jLA2qw-F9O39YmUew4oq-xcBQBs0g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/450c7defa6d5f3c9fdb6efc92cca106c7b582cb3

Modified Files
--------------
src/backend/access/transam/varsup.c | 52 +++++-------
src/backend/storage/ipc/procarray.c | 155 ++++++++++++++++++++----------------
2 files changed, 108 insertions(+), 99 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2018-11-11 01:24:10 pgsql: Disable MSVC warning caused by recent snprintf.c changes
Previous Message Andres Freund 2018-11-10 22:35:27 Re: pgsql: Remove ineffective check against dropped columns from slot_getat