Re: Use pg_nextpower2_* in a few more places

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Zhihong Yu <zyu(at)yugabyte(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Use pg_nextpower2_* in a few more places
Date: 2021-06-12 13:40:13
Message-ID: CAApHDvr9-VjVArkLzXAc-1xp5AzohpvJ7H1--GVTJo4-XfT3qQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for having a look.

On Sun, 13 Jun 2021 at 00:50, Zhihong Yu <zyu(at)yugabyte(dot)com> wrote:
> - newalloc = Max(LWLockTrancheNamesAllocated, 8);
> - while (newalloc <= tranche_id)
> - newalloc *= 2;
> + newalloc = pg_nextpower2_32(Max(8, tranche_id + 1));
>
> Should LWLockTrancheNamesAllocated be included in the Max() expression (in case it gets to a high value) ?

I think the new code will produce the same result as the old code in all cases.

All the old code did was finding the next power of 2 that's >= 8 and
larger than tranche_id. LWLockTrancheNamesAllocated is just a hint at
where the old code should start searching from. The new code does not
need that hint. All it seems to do is save the old code from having to
start the loop at 8 each time we need more space.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2021-06-12 13:55:22 Signed vs Unsigned (take 2) (src/backend/storage/ipc/procarray.c)
Previous Message Andrew Dunstan 2021-06-12 13:05:57 Re: Race condition in recovery?