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 1sOKSN-00DflS-2F for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jul 2024 17:04:47 +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 1sOKSK-003JVy-B0 for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jul 2024 17:04:44 +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 1sOKSJ-003JVc-S4 for pgsql-hackers@lists.postgresql.org; Mon, 01 Jul 2024 17:04:44 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sOKSH-0044QA-Dz for pgsql-hackers@lists.postgresql.org; Mon, 01 Jul 2024 17:04:42 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id CB78013802A2; Mon, 1 Jul 2024 13:04:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 01 Jul 2024 13:04:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1719853479; x= 1719939879; bh=JT7j92rH5VZt1/szQ4FP3M11X1ae+Exq/daR+hZ01uI=; b=L PMu3T0gHFZxQnHsuXDuXt5XdfJujk4jFXrMKEyyGWEadf2IIZDMeKaXx9Bgp7jn7 D0VA81xdC3HdeN3235sDtxEYeA2f4mfh9FVS7JSt37sGr+dYdOXW7gi/ZQ+90rq7 EU2QAo2DyJi5uGSvLF/wTVPdaKQXH37gIkX1hW8SFtuhV2hwp2Nrrl41ioJ8YJIF cNO4ObUIRqkDcLvBPb2DsoHJY7TRf8J0EcbUn/7IIbPyEP/7JPPz3kHomqO4TR3a VnUDlfTSwIbCGJ9GR2ASfnN35v2qpV3mk2x0xrQC7u7Ot52KfJxx/HEqqIykUVqL CzJmeh52U7nrWKvrpn5Nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgddutdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudelkeekgfdttdettdekgfduvdeiffelteegjeeihfet heekveeftedtuddvhfeunecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Jul 2024 13:04:38 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1719853476; bh=n4rjutuN6Pf/CE9/iJBr/fMOjN00KbSzkb1mcX5bGZ8=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Y2PVw/FP2mFCl4+nkqzaGe1cAlzi33WIGO1dQxlMROxz1ZUVHgF0SdzIVsv3dEPOz RU2lkTjaRekJeDXHJ2TgJhENmTFbztHnAG9jqrqhu8zFMwCPyJ8By63Ua0isuw5aDk hqVKQXO84BVNhTOqRnsmY+X0rr2kp/XcAIV3uMDGMMsPu6Bbf7ORWz7hBNkN0NstCR 3gGdUJHM1xsybWfOkLdfKNOKVPE2cUrajmmvgJF7u1cNyaGn8W9VDhXeSJz1Hzk2ey IqS0Y/b4rQQIIcnGOnQ72tTdqzav86YTHVrr3a2PPGfFHZZqSzza1ZiN9BSj1ZMf05 IoJONwxpdBVFw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 9C126529; Mon, 1 Jul 2024 19:04:36 +0200 (CEST) Date: Mon, 1 Jul 2024 19:04:36 +0200 From: Alvaro Herrera To: Tom Lane Cc: Alexander Lakhin , Bharath Rupireddy , Andres Freund , Jeff Davis , pgsql-hackers@lists.postgresql.org, Jaime Casanova Subject: Re: LogwrtResult contended spinlock Message-ID: <202407011704.ujh2z5vtmx5d@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="utchk7geklzvbrhf" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2741228.1719845958@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --utchk7geklzvbrhf Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2024-Jul-01, Tom Lane wrote: > Alvaro Herrera writes: > > Maybe we can do something like this, > > > +#if MAXIMUM_ALIGNOF >= 8 > > uint64 currval; > > This should probably be testing the alignment of int64 specifically, > rather than assuming that MAXIMUM_ALIGNOF applies to it. At least > historically, there have been platforms where MAXIMUM_ALIGNOF is > determined by float quantities and integer quantities are different. OK, so it's #if ALIGNOF_LONG_LONG_INT >= 8 Alexander, can you please confirm whether this works for you? -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "La virtud es el justo medio entre dos defectos" (Aristóteles) --utchk7geklzvbrhf Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v4-0001-Fix-alignment-in-pg_atomic_monotonic_advance_u64.patch" From 65e9e813859fec436805b1ada7be9339f8ecd63e Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 1 Jul 2024 16:44:22 +0200 Subject: [PATCH v4] Fix alignment in pg_atomic_monotonic_advance_u64 Unsurprisingly, it's possible for Windows x86 to have 8-byte atomics but 4-byte-aligned long long ints. This breaks an assertion in recently introduced pg_atomic_monotonic_advance_u64 with commit f3ff7bf83bce. Try to fix that blindly by adding pg_attribute_aligned(8). Unfortunately not all compilers support that, so it needs to be protected by #ifdef; fortunately not all compilers _need_ it. Hopefully the combinations we now support cover all interesting cases. Reported-by: Alexander Lakhin Reviewed-by: Tom Lane Discussion: https://postgr.es/m/36796438-a718-cf9b-2071-b2c1b947c1b5@gmail.com --- src/include/port/atomics.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h index 78987f3154..eeb47dee30 100644 --- a/src/include/port/atomics.h +++ b/src/include/port/atomics.h @@ -580,7 +580,21 @@ pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_) static inline uint64 pg_atomic_monotonic_advance_u64(volatile pg_atomic_uint64 *ptr, uint64 target_) { + /* + * When using actual (not simulated) atomics, the target variable for + * pg_atomic_compare_exchange_u64 must have suitable alignment. This + * occurs naturally on platforms where long long int is 8-byte aligned. On + * others, we must explicitly coerce the compiler into applying suitable + * alignment, or abort the compile if we cannot. When using simulated + * atomics, the alignment doesn't matter. + */ +#if ALIGNOF_LONG_LONG_INT >= 8 || defined(PG_HAVE_ATOMIC_U64_SIMULATION) uint64 currval; +#elif defined(pg_attribute_aligned) + pg_attribute_aligned(8) uint64 currval; +#else +#error "Must have pg_attribute_aligned or simulated atomics on this platform" +#endif #ifndef PG_HAVE_ATOMIC_U64_SIMULATION AssertPointerAlignment(ptr, 8); -- 2.39.2 --utchk7geklzvbrhf--