Re: LogwrtResult contended spinlock

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>
Subject: Re: LogwrtResult contended spinlock
Date: 2024-06-29 12:00:00
Message-ID: 4244f22a-a208-321f-ec32-150ffde35c8e@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2024-06-29 12:22:09 Re: Optimize numeric.c mul_var() using the Karatsuba algorithm
Previous Message Alvaro Herrera 2024-06-29 10:23:02 Re: LogwrtResult contended spinlock