Improve conditional compilation for direct I/O alignment checks
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t49690psql -h localhost -U postgresBuilt from patchset v2 (message #2), July 27, 2026 at 10:47 PM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t49690_2 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t49690_2 && git checkout t49690_2Patchset v2 (message #2) is on t49690_2
This patch refactors the alignment checks for direct I/O to preprocess phase,
thereby reducing some CPU cycles.
--
Regards
Junwang Zhao
Attachments:
0001-Improve-conditional-compilation-for-direct-I-O-align.patchapplication/octet-stream; name=0001-Improve-conditional-compilation-for-direct-I-O-align.patchDownload+7-7
On Sun, May 26, 2024 at 3:16 PM Junwang Zhao <zhjwpku@gmail.com> wrote:
This patch refactors the alignment checks for direct I/O to preprocess phase,
thereby reducing some CPU cycles.--
Regards
Junwang Zhao
Patch v2 with some additional minor polishment of the comments in `mdwriteback`.
--
Regards
Junwang Zhao
On 26.05.24 09:16, Junwang Zhao wrote:
This patch refactors the alignment checks for direct I/O to preprocess phase,
thereby reducing some CPU cycles.
This patch replaces for example
if (PG_O_DIRECT != 0 && PG_IO_ALIGN_SIZE <= BLCKSZ)
Assert((uintptr_t) buffer == TYPEALIGN(PG_IO_ALIGN_SIZE, buffer));
with
#if PG_O_DIRECT != 0 && PG_IO_ALIGN_SIZE <= BLCKSZ
Assert((uintptr_t) buffer == TYPEALIGN(PG_IO_ALIGN_SIZE, buffer));
#endif
You appear to be assuming that this saves some CPU cycles. But this is
not the case. The compiler will remove the unused code in the first
case because all the constants in the if expression are known at
compile-time.