From ccdf02bfdcca1807d9fe6bd1e39b0b185f81e5e6 Mon Sep 17 00:00:00 2001
From: alterego665 <824662526@qq.com>
Date: Thu, 28 Aug 2025 15:40:48 +0800
Subject: [PATCH v3 0/2] Improve read_local_xlog_page_guts by replacing polling with latch-based waiting

This patch depends on:
  [PATCH v8] Implement WAIT FOR command
  https://www.postgresql.org/message-id/flat/CAPpHfdsjtZLVzxjGT8rJHCYbM0D5dwkO%2BBBjcirozJ6nYbOW8Q%40mail.gmail.com

Summary:
--------
This patch replaces the polling loop in read_local_xlog_page_guts()
with latch-based infrastructure, building on the WAIT FOR command
introduced by Kartyshov Ivan and Alexander Korotkov in the above patch.
The polling loop was inefficient during long waits; this version
integrates latches for more efficient wakeups.

Credit:
-------
This work builds on the infrastructure by Kartyshov Ivan and Alexander
Korotkov. Credit goes to them for the foundational patch.

Testing:
--------
- Passes `make check-world`
- Shows reduced CPU usage when waiting for WAL in performance tests.

Application:
------------
To apply:
  1. First apply v8-0001-Implement-WAIT-FOR-command.patch
  2. Then apply this patch series

Thanks,
Xuneng

alterego665 (1):
  Improve read_local_xlog_page_guts by replacing polling with
    latch-based waiting

 src/backend/access/transam/xlog.c             | 18 ++++
 src/backend/access/transam/xlogutils.c        | 48 ++++++++--
 src/backend/access/transam/xlogwait.c         | 93 ++++++++++++++++---
 src/backend/replication/walsender.c           |  4 -
 .../utils/activity/wait_event_names.txt       |  1 +
 src/include/access/xlogwait.h                 |  1 +
 6 files changed, 142 insertions(+), 23 deletions(-)

-- 
2.49.0

