From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Prevent potentially hazardous compiler/cpu reordering during lwl |
Date: | 2014-12-19 14:01:42 |
Message-ID: | E1Y1y7i-0002rZ-Rx@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Prevent potentially hazardous compiler/cpu reordering during lwlock release.
In LWLockRelease() (and in 9.4+ LWLockUpdateVar()) we release enqueued
waiters using PGSemaphoreUnlock(). As there are other sources of such
unlocks backends only wake up if MyProc->lwWaiting is set to false;
which is only done in the aforementioned functions.
Before this commit there were dangers because the store to lwWaitLink
could become visible before the store to lwWaitLink. This could both
happen due to compiler reordering (on most compilers) and on some
platforms due to the CPU reordering stores.
The possible consequence of this is that a backend stops waiting
before lwWaitLink is set to NULL. If that backend then tries to
acquire another lock and has to wait there the list could become
corrupted once the lwWaitLink store is finally performed.
Add a write memory barrier to prevent that issue.
Unfortunately the barrier support has been only added in 9.2. Given
that the issue has not knowingly been observed in praxis it seems
sufficient to prohibit compiler reordering using volatile for 9.0 and
9.1. Actual problems due to compiler reordering are more likely
anyway.
Discussion: 20140210134625(dot)GA15246(at)awork2(dot)anarazel(dot)de
Branch
------
REL9_0_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/fce3a719839e5e283c819a552ef81d3f684672e4
Modified Files
--------------
src/backend/storage/lmgr/lwlock.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2014-12-19 15:07:38 | pgsql: Fix timestamp in end-of-recovery WAL records. |
Previous Message | Andres Freund | 2014-12-19 14:01:23 | pgsql: Prevent potentially hazardous compiler/cpu reordering during lwl |