Re: Atomic operations within spinlocks
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-06-03T21:40:31Z
Lists: pgsql-hackers
On Thu, Jun 4, 2020 at 8:45 AM Andres Freund <andres@anarazel.de> wrote: > On 2020-06-03 14:19:45 -0400, Tom Lane wrote: > > In the second place, this coding seems to me to indicate serious > > confusion about which lock is protecting what. In the above example, > > if writtenUpto is only accessed through atomic operations then it > > seems like we could just move the pg_atomic_read_u64 out of the > > spinlock section; or if the spinlock is adequate protection then we > > could just do a normal fetch. If we actually need both locks then > > this needs significant re-thinking, IMO. > > Yea, it doesn't seem necessary at all that writtenUpto is read with the > spinlock held. That's very recent: > > commit 2c8dd05d6cbc86b7ad21cfd7010e041bb4c3950b > Author: Michael Paquier <michael@paquier.xyz> > Date: 2020-05-17 09:22:07 +0900 > > Make pg_stat_wal_receiver consistent with the WAL receiver's shmem info > > and I assume just was caused by mechanical replacement, rather than > intentionally doing so while holding the spinlock. As far as I can tell > none of the other writtenUpto accesses are under the spinlock. Yeah. It'd be fine to move that after the spinlock release. Although it's really just for informational purposes only, not for any data integrity purpose, reading it before the spinlock acquisition would theoretically allow it to appear to be (reportedly) behind flushedUpto, which would be silly.
Commits
-
Convert SpinLock* macros to static inline functions.
- bfc321b4723e 19 (unreleased) landed
-
Clean up includes of s_lock.h.
- f219167910ad 14.0 landed
-
Fix deadlock danger when atomic ops are done under spinlock.
- 5fffa8fce37b 13.0 landed
- 6cc2866c4cdf 12.4 landed
- 825d89dda5ad 11.9 landed
- c2a84bee1228 10.14 landed
- 8bc13287ed3e 9.6.19 landed
- 3e69bf3b142b 9.5.23 landed
- cf1234a10e50 14.0 landed
-
Add basic spinlock tests to regression tests.
- 3f66e1c5a576 10.14 landed
- e027219f2131 11.9 landed
- 008c119928a3 12.4 landed
- 59225dcefef2 13.0 landed
- 3b37a6de027c 14.0 landed
- e8302f107af9 9.6.19 landed
- 7e91f90a8ed4 9.5.23 landed
-
spinlock emulation: Fix bug when more than INT_MAX spinlocks are initialized.
- dcf3cb60cbef 9.5.23 landed
- 660622053419 9.6.19 landed
- b295f666b7f0 10.14 landed
- 34d29222a0bb 11.9 landed
- b91cfaa34f44 12.4 landed
- 276bdc93924a 13.0 landed
- 4d4ca24efe8e 14.0 landed
-
Avoid potential spinlock in a signal handler as part of global barriers.
- 09bff91b316e 13.0 landed
- fd49d5380757 14.0 landed
-
Make pg_stat_wal_receiver consistent with the WAL receiver's shmem info
- 2c8dd05d6cbc 13.0 cited
-
Improve 64bit atomics support.
- e8fdbd58fe56 10.0 cited