Improve conditional compilation for direct I/O alignment checks

Started by Junwang Zhaoalmost 2 years ago3 messageshackers
Jump to latest
#1Junwang Zhao
zhjwpku@gmail.com

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
#2Junwang Zhao
zhjwpku@gmail.com
In reply to: Junwang Zhao (#1)
Re: Improve conditional compilation for direct I/O alignment checks

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

Attachments:

v2-0001-Improve-conditional-compilation-for-direct-I-O-al.patchapplication/octet-stream; name=v2-0001-Improve-conditional-compilation-for-direct-I-O-al.patchDownload+9-10
#3Peter Eisentraut
peter_e@gmx.net
In reply to: Junwang Zhao (#1)
Re: Improve conditional compilation for direct I/O alignment checks

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.