Re: [PATCH] Refactor remaining zero-fill relation extensions to use smgrzeroextend()
Re: [PATCH] Refactor remaining zero-fill relation extensions to use smgrzeroextend()
Hi, On Thu, Aug 13, 2026 at 1:50 PM Bharath Rupireddy wrote: > > In the CREATE DATABASE path, smgrextend writes just one block with > zeros (out of N relation blocks only the last one gets written zero), > so this is already optimized today (which is why with posix_fallocate > the patch shows no visible benefit here). However, with smgrzeroextend > and file_extend_method=write_zeros (IOW, on platforms where > posix_fallocate doesn't exist), this patch increases the disk writes > (2x) and slows the query (2x). > > code exec time (s) disk writes (GB) > HEAD 59.2 7.3 > patched, posix_fallocate 59.2 7.3 > patched, write_zeros 119.1 14.6 > > I didn't dive deep into the other paths bulk_write.c and md.c changed > in this patch, so I'm not sure if they could also hit this problem. I looked at the other two places. _mdfd_getseg() has the same optimization as the CREATE DATABASE path (out of N blocks, only the last one gets zeroed), so the patch has the same problem there. smgr_bulk_flush() already writes all the gap pages with zeros, so using smgrzeroextend() there looks good to me. Using smgrzeroextend() for every zero-fill relation extension, as mentioned upthread [1], is a good idea. How about we pass only the last block to smgrzeroextend() and mdzeroextend() in those two places, something like the attached? This also removes the regression. code exec time (s) disk writes (GB) HEAD 58.9 7.3 v1, posix_fallocate 58.9 7.3 v1, write_zeros 118.5 14.6 v2, posix_fallocate 58.9 7.3 v2, write_zeros 58.9 7.3 Barring objections, I will mark the CF entry as Ready for Committer. [1] > > The Broader Vision > > Beyond simple code cleanup, enforcing the responsibility separation of smgrextend() and smgrzeroextend() opens up a clean way to address a long-standing data validation challenge. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: [PATCH] Refactor remaining zero-fill relation extensions to use smgrzeroextend()
От:
shihao zhong <zhong950419@gmail.com>
Дата:
Hi,
I reviewed v2. It fixes both regressions I raised on v1. With one
block, mdzeroextend() takes the same FileZero() path as the old
mdextend() call, so nothing changes at runtime there.
One request. smgrzeroextend(..., nblocks - 1, 1, ...) looks like a bug
unless you know why, and changing it to (0, nblocks) brings the 2x
regression back. Please add a one line comment in bufmgr.c and md.c
saying only the last block is written on purpose.
Nit, the "don't set checksum" comment in bulk_write.c no longer
applies, since no page is passed.
Note that v2 does not move toward the zero page detection idea. The
blocks before the last one are still holes, which read as zeros and
never pass through smgrzeroextend(). Making them non-zero means writing
them, which is the 2x cost Bharath measured.
Thanks,
Shihao
I reviewed v2. It fixes both regressions I raised on v1. With one
block, mdzeroextend() takes the same FileZero() path as the old
mdextend() call, so nothing changes at runtime there.
One request. smgrzeroextend(..., nblocks - 1, 1, ...) looks like a bug
unless you know why, and changing it to (0, nblocks) brings the 2x
regression back. Please add a one line comment in bufmgr.c and md.c
saying only the last block is written on purpose.
Nit, the "don't set checksum" comment in bulk_write.c no longer
applies, since no page is passed.
Note that v2 does not move toward the zero page detection idea. The
blocks before the last one are still holes, which read as zeros and
never pass through smgrzeroextend(). Making them non-zero means writing
them, which is the 2x cost Bharath measured.
Thanks,
Shihao
Re: [PATCH] Refactor remaining zero-fill relation extensions to use smgrzeroextend()
Hi, On Thu, Sep 24, 2026 at 10:07 PM shihao zhong wrote: > > I reviewed v2. It fixes both regressions I raised on v1. With one > block, mdzeroextend() takes the same FileZero() path as the old > mdextend() call, so nothing changes at runtime there. Thanks for reviewing. > One request. smgrzeroextend(..., nblocks - 1, 1, ...) looks like a bug > unless you know why, and changing it to (0, nblocks) brings the 2x > regression back. Please add a one line comment in bufmgr.c and md.c > saying only the last block is written on purpose. It can take a while to understand that part when first looking at it. Still, I would prefer not to add the comment, since it would mostly end up restating what the code already does, unless anyone thinks otherwise. > Nit, the "don't set checksum" comment in bulk_write.c no longer > applies, since no page is passed. Reworded it to match an existing comment around smgrzeroextend(). > Note that v2 does not move toward the zero page detection idea. The > blocks before the last one are still holes, which read as zeros and > never pass through smgrzeroextend(). Making them non-zero means writing > them, which is the 2x cost Bharath measured. Right, I don't think this patch was meant to solve that, though I may be missing something. What it does is keep the responsibilities of smgrextend() and smgrzeroextend() separate, as mentioned upthread, and that alone is worth having IMHO. I think the zero page detection part would need changes to the API itself. Peipei, appreciate any thoughts on this. I attached the v3 patch. Please have a look. I don't think this needs to be back-patched, since it is not fixing a bug. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com