Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vArRo-006frw-1b for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 15:05:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vArRl-001n6n-Pj for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 15:05:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vArRl-001n6B-AG for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 15:05:16 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vArRh-003Fek-2X for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 15:05:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1760972712; bh=6Ff8j+Hkv8ytXwO/uTtXjMQ0/UdmBf2xu87J/liVDCc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=Zdo50pzZR3kxmw1l1zpZSfYw/j+JdTd6IMq1abdxpy1SVKM4kAlsUXoWV6Fq+86TB 6QW3CDys0GDxpMBfLmjsEMzrLV6L0gkDzuLKQBOr+jOj5v/zAlapLkftEBKtZ/S/iu /Fc7UKOwm5cADdE6zFyT3VEH/MdzDjaLGQ1vLJhofQFBoJ7N/Hpb3C1FhB/TeOzOuj +MDfi4zlpi58iaGhHduvAtGCAf9bws/RRol2MJo3CUSEr7rWqNpYW+hZmeZTC/Zzcq 5HZ+EYVX17VW0OEhGYwT6jlyUuNStwb/N23D2pirqjpTlwwC23w3z9rxn72/x2Axn2 hGOXg+79waA4w== Received: from mail.postgrespro.ru (webmail-master-mstn.l.postgrespro.ru [192.168.2.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: o.tselebrovskiy@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 11644602AA; Mon, 20 Oct 2025 18:05:12 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 20 Oct 2025 18:05:12 +0300 From: Oleg Tselebrovskiy To: Andrew Kim Cc: John Naylor , pgsql-hackers@lists.postgresql.org Subject: Re: Proposal for enabling auto-vectorization for checksum calculations In-Reply-To: References: <20250911054220.3784-1-root@ip-172-31-36-228.ec2.internal> Message-ID: <44d2472a978912ca352eb839a24b2176@postgrespro.ru> X-Sender: o.tselebrovskiy@postgrespro.ru Organization: Postgres Pro Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/10/20 11:03:00 #27790215 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for the new patch version! Another round of review: 1) I think that changes to contrib/pageinspect/rawpage.c should be in the main patch, not in the benchmark patch. Also, without those chages the main patch can't compile using make world-bin 2) I still don't get why you check for working intrinsics in configure, config/c-compiler.m4 and meson.build, if your patch later uses them. I've gotten correct assembly code with this avx2_test function: #include #if defined(__has_attribute) && __has_attribute (target) __attribute__((target("avx2"))) static int avx2_test(void) { return 0; } #endif Please, check if this works for you and consider using something similar 3) __builtin_cpu_supports doesn't work on Windows at all. We still have to use approach with __get_cpuid 4) Looks like you can safely remove "port/checksum_impl.h" from src/bin/pg_checksums/pg_checksums.c. It probably links with libpgport and/or libpgcommon, so it gets pg_checksum_page from there. Same with src/bin/pg_upgrade/file.c. Maybe those includes are "for clarity" and you don't need to remove them, but pg_checksums and pg_upgrade seem to work without them 5) You don't need #include /* for memcpy */ in checksum_impl.h. At the very least, memcpy was used before your patch without string.h 6) Why did you remove Assert(sizeof(PGChecksummablePage) == BLCKSZ)? Is it always false? 7) Is reformatted variable declaration in pg_checksum_block_default_impl really needed? Is there a good reason for it? Or is it auto-formatting programm output? 8) Your patch removes one whitespace in this line - for (i = 0; i < (uint32)(BLCKSZ / (sizeof(uint32) * N_SUMS)); i++) If you wish to fix formatting like that - please, do it in a separate patch. If this was done automatically by some formatting tool - please, revert this change 9) Unneeded empty string #define FNV_PRIME 16777619 + /* Use a union so that this code is valid under strict aliasing */ typedef union 10) You need one line with just /* at the beginning of the comment, look at other multiline comments in this file + /* For now, AVX2 implementation is identical to default + * The compiler will auto-vectorize this with proper flags + * Future versions could use explicit AVX2 intrinsics here */ 11) Function pg_checksum_block_simple isn't used at all. 12) Why do you need those? +#ifndef PG_CHECKSUM_EXTERNAL_INTERFACE +#define PG_CHECKSUM_EXTERNAL_INTERFACE 13) Object files are added according to alphabetical order, not logical order (src/port/Makefile) pg_popcount_aarch64.o \ pg_popcount_avx512.o \ + checksum.o \ pg_strong_random.o \ pgcheckdir.o \ 14) I still think that src/port/checksum.c needs to just include src/include/port/checksum_impl.h and have no other logic to keep checksum_impl.h's role as "header with full implementation" Now checksum_impl.h doesn't have any mention of pg_checksum_page 15) Assembly for pg_checksum_block_choose now has full code of pg_checksum_block_default. This is probably a result of using inline functions Don't know if this is bad, but it is at least strange Also, some CFBot checks have failed. Two of them with this error/warning checksum.c:88:1: error: no previous prototype for ‘pg_checksum_page’ [-Werror=missing-prototypes] 88 | pg_checksum_page(char *page, BlockNumber blkno) | ^~~~~~~~~~~~~~~~ Please, address those Oleg Tselebrovskiy, PostgresPro