pgsql: Add memory barriers for PgBackendStatus.st_changecount protocol.

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add memory barriers for PgBackendStatus.st_changecount protocol.
Date: 2014-12-18 14:08:09
Message-ID: E1Y1bkP-0005S2-73@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add memory barriers for PgBackendStatus.st_changecount protocol.

st_changecount protocol needs the memory barriers to ensure that
the apparent order of execution is as it desires. Otherwise,
for example, the CPU might rearrange the code so that st_changecount
is incremented twice before the modification on a machine with
weak memory ordering. This surprising result can lead to bugs.

This commit introduces the macros to load and store st_changecount
with the memory barriers. These are called before and after
PgBackendStatus entries are modified or copied into private memory,
in order to prevent CPU from reordering PgBackendStatus access.

Per discussion on pgsql-hackers, we decided not to back-patch this
to 9.4 or before until we get an actual bug report about this.

Patch by me. Review by Robert Haas.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/38628db8d8caff21eb6cf8d775c0b2d04cf07b9b

Modified Files
--------------
src/backend/postmaster/pgstat.c | 51 +++++++++++++++++++++------------------
src/include/pgstat.h | 44 +++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2014-12-18 18:25:19 pgsql: Change how first WAL segment on new timeline after promotion is
Previous Message Fujii Masao 2014-12-18 12:15:32 pgsql: Ensure variables live across calls in generate_series(numeric, n