| From: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
|---|---|
| To: | Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Small WAL replay perf improvements (smgropen()+reduce membarriers for LSN waiters) |
| Date: | 2026-12-04 08:14:10 |
| Message-ID: | CABPTF7Ux6SVXOwiRaLgXS2Vpd7M8ciqQ0n-jmW8=TE+LckY5-g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> OK I see, it's risky to me too, but then this sounds like we can leave
> everything mostly as it was in the 0003 patch and we do not need to move
> it to ApplyWalRecord() - as on 2nd second look to me to me that if we are
> not doing this optimization by Heikki, having it explictly in the "main
> redo loop" makes a lot of sense - mainly: feature code visibliity in top
> code section, so I've left it as it was.
Ok, it makes sense to keep it there. I have a few thoughts on 0003:
0003 uses two wakeup APIs, which seems fine to me. As I mentioned in
my earlier email, the trade-off with this approach is that we may need
extra safekeeping documentation for their contracts, especially how
they handle InvalidXLogRecPtr. Currently, we have only one external
wakeup call at xlogwait -- WaitLSNWakeup() -- the startup use it to
wake up all standby waiters at two points: after applying the WAL
record and at promotion. InvalidXLogRecPtr is used as a special marker
at promotion to skip the fast check in WaitLSNWakeup() and to enforce
waking up all waiters in the internal wakeupWaiters(). 0003 decouples
these cases into two helpers -- one for each, and treats
InvalidXLogRecPtr as an invalid input in the new helper. My concern is
that future readers might consider refactoring them because the two
helpers look quite similar, requiring many comments to warn them
against doing so or to guide them correctly. So for simplicity, how
about keeping them in one helper as v3 does? The cost of this is that
we cannot save the seemingly unnecessary barrier at promotion, which
seems ok to me since that transition is relatively rare. Additionally,
I find the function name WaitLSNWakeupStandby() as a bit misleading --
it implies that this function handles all standby wakeups, which isn't
true since WaitLSNWakeup() is also used for flush/write waiters at
standby. Unfortunately, I cannot come up with a better name. My
current compromise is WaitLSNWakeupAllStandby(). Apart from this, I
made a few small simplifications and adjustments to the patch.
Regarding the safety of turning three pg_atomic_read_membarrier_u64()
into one pg_memory_barrier() in ARM, here's the assembly: before the
patch, each of the three calls reads its slot with ldsetal xzr, x8,
[x8], which provides the memory ordering. After the patch, a single
dmb ish supplies the memory barrier for all three checks, and each
check reads its slot with an ordinary ldr. So, it should be fine.
I haven't reviewed other patches yet.
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
| Attachment | Content-Type | Size |
|---|---|---|
| 0003-WAIT-FOR-LSN-share-standby-wakeup-checks.patch | application/octet-stream | 5.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hayato Kuroda (Fujitsu) | 2026-12-04 08:29:31 | RE: Add aborted_txns and aborted_bytes to pg_stat_replication_slots |
| Previous Message | Jakub Wartak | 2026-12-04 08:12:52 | Re: add --transfer-mode to pg_upgrade |