remove unused shared WAL flush request

Started by Xuneng Zhou4 days ago3 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Xuneng Zhou
xunengzhou@gmail.com

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.

Attachments:

t259764_1
flush-bench.shtext/x-sh; charset=US-ASCII; name=flush-bench.shDownload
v1-0001-Remove-the-unused-shared-WAL-flush-request.patchapplication/octet-stream; name=v1-0001-Remove-the-unused-shared-WAL-flush-request.patchDownload+19-23
#2Alvaro Herrera
alvherre@kurilemu.de
In reply to: Xuneng Zhou (#1)
Re: remove unused shared WAL flush request

On 2026-Nov-25, Xuneng Zhou wrote:

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.

Interesting. I can't confirm these findings, but if we're modifying
this code, please let's use less of a consonant soup for a name; how
about LogWriteRequest or WALWriteRequest or walWriteRequest? Also, do
we still need struct XLogwrtRqst?

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"I can't go to a restaurant and order food because I keep looking at the
fonts on the menu. Five minutes later I realize that it's also talking
about food" (Donald Knuth)

#3Xuneng Zhou
xunengzhou@gmail.com
In reply to: Alvaro Herrera (#2)
Re: remove unused shared WAL flush request

Hi Álvaro,

Thanks for your comments.

Interesting. I can't confirm these findings, but if we're modifying
this code, please let's use less of a consonant soup for a name; how
about LogWriteRequest or WALWriteRequest or walWriteRequest?

Yeah, LogwrtRqstWrite is not a good name.. logWriteRequest looks better.

Also, do we still need struct XLogwrtRqst?

I think we could get rid of it if Flush is out.

--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.