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 1sNWkU-0097Ya-Fv for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Jun 2024 12:00:10 +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 1sNWkQ-00994I-Vu for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Jun 2024 12:00:07 +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 1sNWkQ-009941-M8 for pgsql-hackers@lists.postgresql.org; Sat, 29 Jun 2024 12:00:06 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sNWkO-0048x3-Mc for pgsql-hackers@lists.postgresql.org; Sat, 29 Jun 2024 12:00:06 +0000 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2ee4ab4076bso22453631fa.0 for ; Sat, 29 Jun 2024 05:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719662403; x=1720267203; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Sa2+BsaVVBTMGxAMRQUBeqxzsZHWAS/NYHnL3DRKK5c=; b=ZSKPI8AqXWj0iK8luAPkKhIJvt3AGsISLdVHnt8QrFLdGW9U29fibllaARzVEVFiHi CgK79F/FgvXbiDX4Ey7r/EiHVF7RiyEcB3qfP5HOS+u5faAPKbJPtykeUUuXwT0n80n/ vpxUKzM5pHHQGfnVVWujO51EtACy8C57dPc/o1LHlm9Xz6EOtlMDqqZliW9/wuqM5fZR /2ryZynIGG3Xf4Cq3aqc8BUnkmwgFim6JPTG4RYFfRdI/NSul+wNVZ0W2SLytqomm/vf uphjn05lVuFf5yd7un4CgxBbAeMThjIbSbnooaL4Sxrr3bbCWXy9Ia5Db1poxBp2mKKL MaJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719662403; x=1720267203; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Sa2+BsaVVBTMGxAMRQUBeqxzsZHWAS/NYHnL3DRKK5c=; b=iTUwYJ6jEYGggTg9QJGROBW8uE29O0I/JSF2iBeErUd7Tz0rP73mqTv0nczMX5Plk6 kls0s8fhya5Hyucp/ZygW0f+W12u5YEEuWI5VQXmxcOKX4KAnhQ/WMOXNGQ/rNVp7FH9 y8kIwKSbNEj6iVsNcaBxEnKnykGmNTqzCntt4bCwIVHjU3VJv1BzSAZONUfpvGhxeqVT RmhqBz+mmMILbemBTUaiqhBiWYOkhv2e7MevPmN4dvb5ye8JdfapXb95/yafguMvmS+Y jabi//o2RCpcSoxU0kkTGB4WPxXxhBLLckoGRM5NAKhFi/knAUVQqBjoQdrB9mTIFSmd aQBA== X-Forwarded-Encrypted: i=1; AJvYcCUeB2lFQh8OvbOjwAGeY0Yxo5HDY9alXF3BGCw1DuCsW/YmYgyC0AtmEuaTV4SorYHGGzvxnLKYxlm9ukA60Aj6AxEBCl1omwhirgOWosI+6Jsz X-Gm-Message-State: AOJu0YxVgX7bC0z5P3kFZOXG1Cphq1cbHS8MiGWFr58mMJWuUKveCYUC jhanOHHYt9OAkkjiYH3M0hh+B2AqN9wCGiLiVW0HyR/KW2fY3ET3 X-Google-Smtp-Source: AGHT+IEQpbIMncxu3NFA9KCrKHotjlzudrhEUri7I588JLWl65/mRmubkPF4RLygRa6Rgf4V+b1Reg== X-Received: by 2002:a2e:894e:0:b0:2ec:361b:c079 with SMTP id 38308e7fff4ca-2ee53c8baccmr11818791fa.25.1719662402539; Sat, 29 Jun 2024 05:00:02 -0700 (PDT) Received: from [1.0.0.7] ([81.23.167.104]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fbbcsm5609331fa.44.2024.06.29.05.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Jun 2024 05:00:01 -0700 (PDT) Message-ID: <4244f22a-a208-321f-ec32-150ffde35c8e@gmail.com> Date: Sat, 29 Jun 2024 15:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: LogwrtResult contended spinlock Content-Language: en-US To: Alvaro Herrera Cc: Bharath Rupireddy , Tom Lane , Andres Freund , Jeff Davis , pgsql-hackers@lists.postgresql.org, Jaime Casanova References: <202406291023.6plsxeg2zho7@alvherre.pgsql> From: Alexander Lakhin In-Reply-To: <202406291023.6plsxeg2zho7@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alvaro, Thank you for looking at this! 29.06.2024 13:23, Alvaro Herrera wrote: >> TRAP: failed Assert("TYPEALIGN(8, (uintptr_t)(&currval)) == >> (uintptr_t)(&currval)"), File: "...\src\include\port/atomics.h", Line: 597, >> PID: 7556 >> child process was terminated by exception 0xC0000409 > Oh. This is the new assertion in pg_atomic_monotonic_advance_u64() and > therefore the only possible culprit could be logInsertResult in > XLogCtlData. Does it work if you do this? > > diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c > index 8dcdf5a764..e581488d57 100644 > --- a/src/backend/access/transam/xlog.c > +++ b/src/backend/access/transam/xlog.c > @@ -468,7 +468,7 @@ typedef struct XLogCtlData > XLogRecPtr lastSegSwitchLSN; > > /* These are accessed using atomics -- info_lck not needed */ > - pg_atomic_uint64 logInsertResult; /* last byte + 1 inserted to buffers */ > + pg_atomic_uint64 logInsertResult pg_attribute_aligned(8); /* last byte + 1 inserted to buffers */ > pg_atomic_uint64 logWriteResult; /* last byte + 1 written out */ > pg_atomic_uint64 logFlushResult; /* last byte + 1 flushed */ It doesn't, but the following works for me:  static inline uint64  pg_atomic_monotonic_advance_u64(volatile pg_atomic_uint64 *ptr, uint64 target_)  { -       uint64          currval; +       pg_attribute_aligned(8) uint64          currval; because the failed assertion is: #ifndef PG_HAVE_ATOMIC_U64_SIMULATION     AssertPointerAlignment(&currval, 8); #endif Best regards, Alexander