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 1sHUJq-008A19-Np for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jun 2024 20:11:42 +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 1sHUJo-006Vkg-Il for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jun 2024 20:11:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHUJo-006VkY-9P for pgsql-hackers@lists.postgresql.org; Wed, 12 Jun 2024 20:11:41 +0000 Received: from fhigh2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHUJm-0010dE-Gx for pgsql-hackers@lists.postgresql.org; Wed, 12 Jun 2024 20:11:39 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id CFB4E1140092; Wed, 12 Jun 2024 16:11:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 12 Jun 2024 16:11:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718223097; x=1718309497; bh=S9kFWEuY6g YNOFhPt0+DQ1HwgAnCQE24CrLrfdZXa6w=; b=a91kCiRLG9h8VzIfUTcvizfHMX KG3X3yIrk+LNAh8JXNwQXfgNr51S3Zi6bhPUl3mLBq4x69ppNbgGcMjXNW94xf2V Z1bPIxAUqiAC9jFJyQNhCJxGvNAokJrrWkC8U5IgO0sF/2kWk1a9Rpd9FHgIcMD/ XdWMX+CfswO7dght8AiQVj1W6mUsbxYvozAjXwR0Fg0c7JOC3TrB+/adZpfKG1Ie i6NHMDHbpaZnpGwarflDZuDJdP4OH/KsxNPnl9zXACKCK3/SegnAmP/izQy6ivou D9t7wDoJTBDlniVezFmhT0G5MXYu/ceRzCJB9/Pxq7vHDRWieiop4nX2YUOg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718223097; x=1718309497; bh=S9kFWEuY6gYNOFhPt0+DQ1HwgAnC QE24CrLrfdZXa6w=; b=MHLSTmreyEmvF/ewaRIlO04Zo6+Qe9sTwtRlyMgh4Cl1 4Z3c3aokn+I0WQl7DzTPi6iEgqo1LBQWsqEV7GG+87r/Cl72O2hawhYvyBb9kvKJ dSOR5bWcTAeNPo39n4xR9zlFs9Ng0Uc7Mbngoz2FvT8bTgpWrGdYa5IDc1iaCM1F 4quUhFgzNSPVpgRERXO6o4RW0b76qgIDs9LTNol4XcP3UK66UEN3E3YiNat5Uwzs BsEBPSlPz6lYoOQO7WgUeg1LrcG6X9AqSPyL+DXYlA2TlE9yDdyudWLLCM0RQJaJ VlmXB/waZP2UWLqEa4KBg2oOWhohkdA+88WN5j5Biw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedugedgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgu rhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtf frrghtthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteev udeitedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 16:11:37 -0400 (EDT) Date: Wed, 12 Jun 2024 13:11:35 -0700 From: Andres Freund To: "Amonson, Paul D" Cc: "pgsql-hackers@lists.postgresql.org" , Nathan Bossart , "Shankaran, Akash" Subject: Re: Proposal for Updating CRC32C with AVX-512 Algorithm. Message-ID: <20240612201135.kk77tiqcux77lgev@awork3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-05-01 15:56:08 +0000, Amonson, Paul D wrote: > Comparing the current SSE4.2 implementation of the CRC32C algorithm in > Postgres, to an optimized AVX-512 algorithm [0] we observed significant > gains. The result was a ~6.6X average multiplier of increased performance > measured on 3 different Intel products. Details below. The AVX-512 algorithm > in C is a port of the ISA-L library [1] assembler code. > > Workload call size distribution details (write heavy): > * Average was approximately around 1,010 bytes per call > * ~80% of the calls were under 256 bytes > * ~20% of the calls were greater than or equal to 256 bytes up to the max buffer size of 8192 This is extremely workload dependent, it's not hard to find workloads with lots of very small record and very few big ones... What you observed might have "just" been the warmup behaviour where more full page writes have to be written. There a very frequent call computing COMP_CRC32C over just 20 bytes, while holding a crucial lock. If we were to do introduce something like this AVX-512 algorithm, it'd probably be worth to dispatch differently in case of compile-time known small lengths. How does the latency of the AVX-512 algorithm compare to just using the CRC32C instruction? FWIW, I tried the v2 patch on my Xeon Gold 5215 workstation, and dies early on with SIGILL: Program terminated with signal SIGILL, Illegal instruction. #0 0x0000000000d5946c in _mm512_clmulepi64_epi128 (__A=..., __B=..., __C=0) at /home/andres/build/gcc/master/install/lib/gcc/x86_64-pc-linux-gnu/15/include/vpclmulqdqintrin.h:42 42 return (__m512i) __builtin_ia32_vpclmulqdq_v8di ((__v8di)__A, (gdb) bt #0 0x0000000000d5946c in _mm512_clmulepi64_epi128 (__A=..., __B=..., __C=0) at /home/andres/build/gcc/master/install/lib/gcc/x86_64-pc-linux-gnu/15/include/vpclmulqdqintrin.h:42 #1 pg_comp_crc32c_avx512 (crc=, data=, length=) at ../../../../../home/andres/src/postgresql/src/port/pg_crc32c_avx512.c:163 #2 0x0000000000819343 in ReadControlFile () at ../../../../../home/andres/src/postgresql/src/backend/access/transam/xlog.c:4375 #3 0x000000000081c4ac in LocalProcessControlFile (reset=) at ../../../../../home/andres/src/postgresql/src/backend/access/transam/xlog.c:4817 #4 0x0000000000a8131d in PostmasterMain (argc=argc@entry=85, argv=argv@entry=0x341b08f0) at ../../../../../home/andres/src/postgresql/src/backend/postmaster/postmaster.c:902 #5 0x00000000009b53fe in main (argc=85, argv=0x341b08f0) at ../../../../../home/andres/src/postgresql/src/backend/main/main.c:197 Cascade lake doesn't have vpclmulqdq, so we shouldn't be getting here... This is on an optimied build with meson, with -march=native included in c_flags. Relevant configure output: Checking if "XSAVE intrinsics without -mxsave" : links: NO (cached) Checking if "XSAVE intrinsics with -mxsave" : links: YES (cached) Checking if "AVX-512 popcount without -mavx512vpopcntdq -mavx512bw" : links: NO (cached) Checking if "AVX-512 popcount with -mavx512vpopcntdq -mavx512bw" : links: YES (cached) Checking if "_mm512_clmulepi64_epi128 ... with -msse4.2 -mavx512vl -mvpclmulqdq" : links: YES Checking if "x86_64: popcntq instruction" compiles: YES (cached) Greetings, Andres Freund