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 1v9i5o-006JNq-2S for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Oct 2025 10:53:52 +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 1v9i5m-001j9A-28 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Oct 2025 10:53:49 +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 1v9i5l-001j8z-JE for pgsql-hackers@lists.postgresql.org; Fri, 17 Oct 2025 10:53:48 +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 1v9i5h-002hRi-2m for pgsql-hackers@lists.postgresql.org; Fri, 17 Oct 2025 10:53:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1760698423; bh=hiAvBe682Vw2gn3NuoPIxMEQNkluzP7egvITMQt3hFg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=V6Wy/QsSmTRmlMIr6ufuRU3Qrmfx6scVXjWJaWBZAPfnB1OX7kyvR5MAByNyxqzbw mkKpTLRlcw1WN5vL2H0CTYM2bzrq7A/V8gAwzDF+iFnOxpu8//GoC6s1Nx9ZYFqK19 /hYh1IwlBl4XnsABznJlpAz9jRTUp38RcTHLZDFabrujxe9E4ixeD/QZXwIsNHq8P3 11NRIEj95/jwVt2/oThZAssHqQI6ROocWt4LY9LwRGHloxZVrciQt3t1V9+FZyviIi cYS3y9w80AYlhhr3ud9zx3FhDMD5854oKNQU3U6dXrWWW157igvx3QfeThhFLBgSZL YD7GzG0MvKOsQ== Received: from mail.postgrespro.ru (webmail-slave-mstn.l.postgrespro.ru [192.168.2.28]) (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 88CAE6092E; Fri, 17 Oct 2025 13:53:43 +0300 (MSK) MIME-Version: 1.0 Date: Fri, 17 Oct 2025 17:53:43 +0700 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: X-Sender: o.tselebrovskiy@postgrespro.ru Organization: Postgres Pro Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit 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/17 09:40:00 #27886745 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 Greetings! I've also tried to use AVX2 to speedup checksums and I've found your approach quite interesting But I see some issues with v6 patch 1) checksum.c was moved to src/port, but special meson rules are left in src/backend/storage/page/meson.build. As a result, assembly code for moved src/port/checksum.c doesn't use -funroll-loops and -ftree-vectorize (latter isn't probably needed now, due to the nature of the patch). The same is true for src/port/Makefile, there are no instructions to use CFLAGS_UNROLL_LOOPS and CFLAGS_VECTORIZE 2) checksum.c was moved to src/port, but checksum.h and checksum_impl.h are left in src/include/storage. I think they both should be moved to src/include/port, as John Naylor suggested in his review of v5 3) checksum_impl.h now doesn't provide any code, so including it in external programs won't allow checksum calculation. I think that all code should be in checksum_impl.h, and external programs could just define USE_AVX2_WITH_RUNTIME_CHECK (probably using similar checks as we are) to use AVX2 implementation. If not - then they will default to default realisation 4) I don't understand why do we need to check for AVX2 intrinsics if we don't use those in code (at least I don't see them directly)? As in review of v5, couldn't test functions in configure, config/c-compiler.m4 and ./meson.build just be {return 0;} or {return 1;}? 5) Why do we need both src/backend/storage/page/checksum.c and src/port/checksum.c? 6) > +/* Function declarations for ISA-specific implementations */ > +uint32 pg_checksum_block_default(const PGChecksummablePage *page); > +#ifdef USE_AVX2_WITH_RUNTIME_CHECK > +uint32 pg_checksum_block_avx2(const PGChecksummablePage *page); > +#endif What is "ISA-specific implementations" in this comment? Maybe I'm just not familiar with the term? Or is it an artifact from macro implementation? 7) Why remove all comments from code of pg_checksum_block_default? I could understand if you just removed comments from pg_checksum_block_avx2, since it just duplicates code (though I personally would leave all the comments even when duplicating code), but I don't understand removing comments from pg_checksum_block_default 8) It might be a personal taste, but pg_checksum_block_dispatch looks more like "choose" function from src/port/pg_crc32c_sse42_choose.c and alike. "dispatch" from src/include/port/pg_crc32c looks a little different - we don't choose function pointer once there, we choose between inlined computation and calling a function with runtime check. So I'd suggest changing name of pg_checksum_block_dispatch to pg_checksum_block_choose Other than those, I think the core of this patch is good Oleg Tselebrovskiy, PostgresPro