pgsql: Avoid BufferGetLSNAtomic() calls during nbtree scans. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Avoid BufferGetLSNAtomic() calls during nbtree scans.
Date
Msg-id E1uNXwK-000S1e-0r@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid BufferGetLSNAtomic() calls during nbtree scans.

Delay calling BufferGetLSNAtomic() until we finish reading a page that
actually contains items that btgettuple will return to the executor.
This reduces the number of calls during plain index scans (we'll only
call BufferGetLSNAtomic() when _bt_readpage returns true), and totally
eliminates calls during index-only scans, bitmap index scans, and plain
index scans of an unlogged relation.

Currently, when checksums (or wal_log_hints) are enabled, acquiring a
page's LSN in BufferGetLSNAtomic() involves locking the buffer header
(which involves the use of spinlocks).  Testing has shown that enabling
page-level checksums causes large regressions with certain workloads,
especially on larger multi-socket systems.

The regression isn't tied to any Postgres 18 commit.  However, Postgres
18 commit 04bec894 made initdb use checksums by default, so it seems
prudent to address the problem now.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/941f0190-e3c6-4622-9ac7-c04e936e5fdb@vondra.me
Discussion: https://postgr.es/m/CAH2-Wzk-Dg5XWs_jDuiHt4_7ryrSY+n=vxmHY51EVqPDFsKXmg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e6eed40e44419e3268d01fe0d2daec08a7df68f7

Modified Files
--------------
src/backend/access/nbtree/nbtree.c    | 30 +++++++++++++++
src/backend/access/nbtree/nbtsearch.c | 70 ++++++++++++++++++-----------------
src/backend/access/nbtree/nbtutils.c  | 68 ++++++++++++++++------------------
src/include/access/nbtree.h           |  5 ++-
4 files changed, 102 insertions(+), 71 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: pg_prewarm: Allow autoprewarm to use more than 1GB to dump block
Next
From: Nathan Bossart
Date:
Subject: pgsql: Fixed signed/unsigned mismatch in test_dsm_registry.