Re: ProcArrayGroupClearXid() compare-exchange style

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ProcArrayGroupClearXid() compare-exchange style
Date: 2019-10-15 09:30:01
Message-ID: CAA4eK1JmfG_BHMRPXgjFPXODMyBcjmCcbAV33HnyP5Ld4PN81g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 15, 2019 at 9:23 AM Noah Misch <noah(at)leadboat(dot)com> wrote:
>
> ProcArrayGroupClearXid() has this:
>
> while (true)
> {
> nextidx = pg_atomic_read_u32(&procglobal->procArrayGroupFirst);
>
> ...
>
> if (pg_atomic_compare_exchange_u32(&procglobal->procArrayGroupFirst,
> &nextidx,
> (uint32) proc->pgprocno))
> break;
> }
>
> This, from UnpinBuffer(), is our more-typical style:
>
> old_buf_state = pg_atomic_read_u32(&buf->state);
> for (;;)
> {
> ...
>
> if (pg_atomic_compare_exchange_u32(&buf->state, &old_buf_state,
> buf_state))
> break;
> }
>
> That is, we typically put the pg_atomic_read_u32() outside the loop. After
> the first iteration, it is redundant with the side effect of
> pg_atomic_compare_exchange_u32(). I haven't checked whether this materially
> improves performance, but, for style, I would like to change it in HEAD.
>

+1. I am not sure if it would improve performance as this whole
optimization was to reduce the number of attempts to acquire LWLock,
but definitely, it makes the code consistent.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2019-10-15 09:33:30 Re: [HACKERS] Block level parallel vacuum
Previous Message Dilip Kumar 2019-10-15 08:34:36 Re: [HACKERS] Block level parallel vacuum