On 08/09/2026 13:08, Peter Eisentraut wrote:
There are a number of places where palloc()/malloc()/etc. was used solely to obtain an aligned buffer. We can do these much simpler by using alignas with a local variable instead. See attached patch.
In XLogRecordAssemble, you could use a local variable in XLogInsert() for the scratch buffer, and pass a pointer to that to XLogRecordAssemble(). That would avoid the a global variable, which is nice for multi-threading.
Not new with this patch, but the calculations for HEADER_SCRATCH_SIZE are a little scary. I'd also suggest adding an assertion somewhere that you don't overrun the HEADER_SCRATCH_SIZE buffer, and maybe some extra comments. I don't see any bugs there, but it's very subtle that if you e.g. add a new "special" block ID similar to XLR_BLOCK_ID_TOPLEVEL_XID, you need to remember to adjust HEADER_SCRATCH_SIZE accordingly.
For the BLCKSZ-sized buffers, how about using PGAlignedBlock? - Heikki
