Re: LogwrtResult contended spinlock - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: LogwrtResult contended spinlock
Date
Msg-id 20210129154018.GA7723@alvherre.pgsql
Whole thread Raw
In response to Re: LogwrtResult contended spinlock  (Andres Freund <andres@anarazel.de>)
Responses Re: LogwrtResult contended spinlock
Re: LogwrtResult contended spinlock
List pgsql-hackers
On 2020-Aug-31, Andres Freund wrote:

> Wouldn't the better fix here be to allow reading of individual members without a lock? E.g. by wrapping each in a
64bitatomic.
 

So I've been playing with this and I'm annoyed about having two
datatypes to represent Write/Flush positions:

typedef struct XLogwrtRqst
{
    XLogRecPtr    Write;            /* last byte + 1 to write out */
    XLogRecPtr    Flush;            /* last byte + 1 to flush */
} XLogwrtRqst;

typedef struct XLogwrtResult
{
    XLogRecPtr    Write;            /* last byte + 1 written out */
    XLogRecPtr    Flush;            /* last byte + 1 flushed */
} XLogwrtResult;

Don't they look, um, quite similar?  I am strongly tempted to remove
that distinction, since it seems quite pointless, and introduce a
different one:

typedef struct XLogwrtAtomic
{
    pg_atomic_uint64    Write;        /* last byte + 1 of write position */
    pg_atomic_uint64    Flush;        /* last byte + 1 of flush position */
} XLogwrtAtomic;

this one, with atomics, would be used for the XLogCtl struct members
LogwrtRqst and LogwrtResult, and are always accessed using atomic ops.
On the other hand we would have

typedef struct XLogwrt
{
    XLogRecPtr    Write;        /* last byte + 1 of write position */
    XLogRecPtr    Flush;        /* last byte + 1 of flush position */
} XLogwrt;

to be used for the local-memory-only LogwrtResult, using normal
assignment.

Now, I do wonder if there's a point in keeping LogwrtResult as a local
variable at all; maybe since the ones in shared memory are going to use
unlocked access, we don't need it anymore?  I'd prefer to defer that
decision to after this patch is done, since ISTM that it'd merit more
careful benchmarking.

Thoughts?

-- 
Álvaro Herrera       Valdivia, Chile



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Allow matching whole DN from a client certificate
Next
From: Alexander Korotkov
Date:
Subject: Re: [HACKERS] [PATCH] Generic type subscripting