Get rid of WALBufMappingLock
authorAlexander Korotkov
Wed, 2 Apr 2025 09:44:24 +0000 (12:44 +0300)
committerAlexander Korotkov
Wed, 2 Apr 2025 09:44:24 +0000 (12:44 +0300)
commitbc22dc0e0ddc2dcb6043a732415019cc6b6bf683
tree34fbf986ac05c0655f894ec056c9aba4f49eed5e
parentb53b88109f94bd81ed0ac580035a936000bc2865
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 
Co-authored-by: Alexander Korotkov
Reviewed-by: Pavel Borisov
Reviewed-by: Tomas Vondra
Tested-by: Michael Paquier
src/backend/access/transam/xlog.c
src/backend/utils/activity/wait_event_names.txt
src/include/storage/lwlocklist.h