Re: LogwrtResult contended spinlock
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, pgsql-hackers@lists.postgresql.org,
Jaime Casanova <jcasanov@systemguards.com.ec>
Date: 2024-04-07T12:19:29Z
Lists: pgsql-hackers
I pushed the "copy" pointer now, except that I renamed it to "insert", which is what we call the operation being tracked. I also added some comments. One perhaps significant change from what Bharath submitted is that we now use the return value from monotonic advance to return an updated value of finishedUpto from WaitXLogInsertionsToFinish. I think this is a useful optimization: the only caller of WaitXLogInsertionsToFinish which cares about its return value is XLogFlush, which AFAICS benefits from having a more up-to-date value. Also, I did adopt your (Jeff's) idea of using a barrier when reading logInsertResult in WaitXLogInsertionsToFinish. If I understand correctly, this is actually useful: if some other CPU core was also recently busy waiting for xlog insertions and wrote an updated version of logInsertResult that's past what we last saw, we benefit from an updated value because we can skip the spinlock dance and WAL-insert-var stuff altogether. With no barrier, we would potentially see an outdated value of logInsertResult and waste a lot of effort to get it updated. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Those who use electric razors are infidels destined to burn in hell while we drink from rivers of beer, download free vids and mingle with naked well shaved babes." (http://slashdot.org/comments.pl?sid=44793&cid=4647152)
Commits
-
Remove bogus assertion in pg_atomic_monotonic_advance_u64
- 768f0c3e21b3 18.0 landed
- 3a9d0d774d90 17.0 landed
-
Add XLogCtl->logInsertResult
- f3ff7bf83bce 17.0 cited
-
Operate XLogCtl->log{Write,Flush}Result with atomics
- ee1cbe806dad 17.0 landed
-
Split XLogCtl->LogwrtResult into separate struct members
- c9920a9068ea 17.0 landed
-
Introduce atomic read/write functions with full barrier semantics.
- bd5132db558b 17.0 cited
-
Reduce the number of GetFlushRecPtr() calls done by walsenders.
- e369f3708636 13.0 cited
-
Remove most volatile qualifiers from xlog.c
- 6ba4ecbf477e 9.5.0 cited