Hi, It seems that XLogCtl->LogwrtRqst.Flush has long been unused; can we reduce the shared request to a single write position?
Backends publish a shared write target so the WAL writer can know WAL to write. For flushing, a backend calling XlogFlush() already knows the LSN it needs made durable by checking shared flush progress and it performas the flush itself if necessary. The WAL writer selects its work using the shared write request and asyncXactLSN, then choose the flush target based on its flush policy. The shared Flush field doesn't participate in those decisions. Startup initializes it, and XLogWrite() advances it to match finished flush progress. XLogBackgroundFlush() copies it but overwrites the local value before using it. XLogFlush() stopped publishing its target there in 4d14fe0048c, and ad4295728e0 removed the remaining path that passed the shared flush value to XLogWrite(). Since then, the field has still been updated but no longer affects what gets flushed. --- Effect on struct layout. Removing it affects the struct layout of XLogCtlData. Now every field after the request is shifted 8 bytes earlier. logInsertResult ends up on a different cache line. - With 64-byte lines, it moves from the line holding logWriteResult and logFlushResult to the line holiding RedoRecPtr and asyncXactLSN - With 128-byte lines, it joins the line that holds Insert.RedoRectPtr and fullPageWrites. I could not measure a difference on an 8-core x86-64 Linux machine or an Apple ARM machine (128-byte lines). Bigger machines haven't been tested yet. The workload is meant to call test XLogWrite() as often as possible with fsync=off: SELECT count(pg_logical_emit_message(false, 'b', 'xxxxxxxxxxxxxxxx', true)) FROM generate_series(1, 1000); -- Regards, Xuneng Zhou HighGo Software Co., Ltd.
#!/bin/bash
# Usage: flush-bench.sh [RUNS]
# Runs against the server that psql and pgbench connect to by default.
set -eu
RUNS=${1:-12}
CLIENTS=${CLIENTS:-8}
SECS=${SECS:-4}
cat >flush.sql <<'SQL'
SELECT count(pg_logical_emit_message(false, 'b', 'xxxxxxxxxxxxxxxx', true))
FROM generate_series(1, 1000);
SQL
echo "run,tps,wal_records,wal_bytes,wal_writes"
for run in $(seq "$RUNS"); do
psql -qAt -c "CHECKPOINT" \
-c "SELECT pg_stat_reset_shared('wal'), pg_stat_reset_shared('io')" >/dev/null
tps=$(pgbench -n -f flush.sql -c "$CLIENTS" -j "$CLIENTS" -T "$SECS" |
sed -n 's/^tps = \([0-9.]*\).*/\1/p')
wal=$(psql -qAt -F, -c "
SELECT wal_records, wal_bytes,
(SELECT sum(writes) FROM pg_stat_io WHERE object = 'wal')
FROM pg_stat_wal")
echo "$run,$tps,$wal"
done
v1-0001-Remove-the-unused-shared-WAL-flush-request.patch
Description: Binary data
