pgsql: bufmgr: Optimize & harmonize LockBufHdr(), LWLockWaitListLock() - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: bufmgr: Optimize & harmonize LockBufHdr(), LWLockWaitListLock()
Date
Msg-id E1vWfD2-001dUr-2E@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
bufmgr: Optimize & harmonize LockBufHdr(), LWLockWaitListLock()

The main optimization is for LockBufHdr() to delay initializing
SpinDelayStatus, similar to what LWLockWaitListLock already did. The
initialization is sufficiently expensive & buffer header lock acquisitions are
sufficiently frequent, to make it worthwhile to instead have a fastpath (via a
likely() branch) that does not initialize the SpinDelayStatus.

While LWLockWaitListLock() already the aforementioned optimization, it did not
use likely(), and inspection of the assembly shows that this indeed leads to
worse code generation (also observed in a microbenchmark). Fix that by adding
the likely().

While the LockBufHdr() improvement is a small gain on its own, it mainly is
aimed at preventing a regression after a future commit, which requires
additional locking to set hint bits.

While touching both, also make the comments more similar to each other.

Reviewed-by: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Discussion: https://postgr.es/m/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/09ae2c8bac8db409a8cd0b8ee438ea7526deb4c3

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c | 36 +++++++++++++++++++++++++++---------
src/backend/storage/lmgr/lwlock.c   |  8 ++++++--
2 files changed, 33 insertions(+), 11 deletions(-)


pgsql-committers by date:

Previous
From: Bruce Momjian
Date:
Subject: pgsql: doc: clarify when physical/logical replication is used
Next
From: Andres Freund
Date:
Subject: pgsql: heapam: Move logic to handle HEAP_MOVED into a helper function