pgsql: Get rid of WALBufMappingLock

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Get rid of WALBufMappingLock
Date: 2025-04-02 09:45:59
Message-ID: E1tzufX-002Gbo-2j@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Get rid of WALBufMappingLock

Allow multiple backends to initialize WAL buffers concurrently. This way
`MemSet((char *) NewPage, 0, XLOG_BLCKSZ);` can run in parallel without
taking a single LWLock in exclusive mode.

The new algorithm works as follows:
* reserve a page for initialization using XLogCtl->InitializeReserved,
* ensure the page is written out,
* once the page is initialized, try to advance XLogCtl->InitializedUpTo and
signal to waiters using XLogCtl->InitializedUpToCondVar condition
variable,
* repeat previous steps until we reserve initialization up to the target
WAL position,
* wait until concurrent initialization finishes using a
XLogCtl->InitializedUpToCondVar.

Now, multiple backends can, in parallel, concurrently reserve pages,
initialize them, and advance XLogCtl->InitializedUpTo to point to the latest
initialized page.

Author: Yura Sokolov <y(dot)sokolov(at)postgrespro(dot)ru>
Co-authored-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Reviewed-by: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Reviewed-by: Tomas Vondra <tomas(at)vondra(dot)me>
Tested-by: Michael Paquier <michael(at)paquier(dot)xyz>

Branch
------
master

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

Modified Files
--------------
src/backend/access/transam/xlog.c | 234 +++++++++++++++++++-----
src/backend/utils/activity/wait_event_names.txt | 2 +-
src/include/storage/lwlocklist.h | 2 +-
3 files changed, 189 insertions(+), 49 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2025-04-02 10:32:15 Re: pgsql: Allow parallel CREATE INDEX for GIN indexes
Previous Message Fujii Masao 2025-04-02 06:16:20 pgsql: Improve error message when standby does accept connections.