convert various variables to atomics

Поиск
Список
Период
Сортировка
Искать

convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
Вложения:
The attached patch set converts various variables to atomics, thereby
allowing us to remove a handful of spinlocks and volatile qualifiers.
We've been slowly moving in this direction for a while already.  I think
all of these are pretty straightforward and easy to reason about.

-- 
nathan

Re: convert various variables to atomics

От:
Andres Freund <andres@anarazel.de>
Дата:
Hi,

On 2026-07-22 09:06:44 -0400, Nathan Bossart wrote:
> On Wed, Jul 22, 2026 at 02:31:49PM +0200, Peter Eisentraut wrote:
> > Here is an instance that seems obviously wrong:
> > 
> >  	/* Buffer id of the buffer that Startup process waits for pin on, or -1 */
> > -	int			startupBufferPinWaitBufId;
> > +	pg_atomic_uint32 startupBufferPinWaitBufId;
> 
> I may just be undercaffeinated, but what is wrong with this case?  AFAICT
> the casting should work as expected, and I see other examples that do
> something similar, like avLauncherProc.

The comment says -1, which doesn't really make sense for an unsigned variable.

Greetings,

Andres Freund


Re: convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Jul 22, 2026 at 09:19:39AM -0400, Andres Freund wrote:
> On 2026-07-22 09:06:44 -0400, Nathan Bossart wrote:
>> >  	/* Buffer id of the buffer that Startup process waits for pin on, or -1 */
>> > -	int			startupBufferPinWaitBufId;
>> > +	pg_atomic_uint32 startupBufferPinWaitBufId;
>> 
>> I may just be undercaffeinated, but what is wrong with this case?  AFAICT
>> the casting should work as expected, and I see other examples that do
>> something similar, like avLauncherProc.
> 
> The comment says -1, which doesn't really make sense for an unsigned variable.

Ah.  It looks like we could use 0 as the sentinel and simplify the call
sites.  They subtract one before calling SetStartupBufferPinWaitBufId() and
add one after calling GetStartupBufferPinWaitBufId().

-- 
nathan


Re: convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
Вложения:
On Wed, Jul 22, 2026 at 09:31:49AM -0400, Nathan Bossart wrote:
> Ah.  It looks like we could use 0 as the sentinel and simplify the call
> sites.  They subtract one before calling SetStartupBufferPinWaitBufId() and
> add one after calling GetStartupBufferPinWaitBufId().

I added a new prerequisite patch (v2-0004) that does this.

-- 
nathan

Re: convert various variables to atomics

От:
solai v <solai.cdac@gmail.com>
Дата:
Hi Nathan,

I tested the complete v1 patch series on PostgreSQL 20devel.
The patches applied cleanly, and PostgreSQL built and installed
successfully. The server started without any issues after applying the
patches.
I performed functional testing for the areas affected by the patch
series, including shared invalidation, parallel bitmap heap scan,
parallel WAL state handling, startup process shared state, parallel
sort, SharedFileSet temporary file handling, parallel sequential scan,
and fast-path relation locking. For each patch, I compared the
behavior before and after applying the changes and observed no
functional differences. All tests behaved as expected, and I did not
encounter any crashes, assertion failures, or unexpected behavior.

I also ran the regression test suite using make check. All  regression
tests passed successfully, and the generated regression.
Overall, I did not observe any functional regressions during testing.
The patch series looks good from my testing.

Thank you for working on this improvement.

Regards,
Solai


Re: convert various variables to atomics

От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
On 23.07.26 21:56, Nathan Bossart wrote:
> On Wed, Jul 22, 2026 at 09:31:49AM -0400, Nathan Bossart wrote:
>> Ah.  It looks like we could use 0 as the sentinel and simplify the call
>> sites.  They subtract one before calling SetStartupBufferPinWaitBufId() and
>> add one after calling GetStartupBufferPinWaitBufId().
> 
> I added a new prerequisite patch (v2-0004) that does this.

Maybe this is okay, but there are a bunch more places (not touched by 
your patches) that mix unsigned atomics operations with actually signed 
values.  Stuff like PIDs and proc numbers.  I think for better overall 
hygiene and to simplify broader adoption, perhaps we should introduce 
support for signed atomic variables.



Re: convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
Вложения:
On Sun, Aug 30, 2026 at 10:54:36PM +0500, Andrey Borodin wrote:
> This entry is currently Ready for Committer, but the last exchange seems
> to leave the signed-atomic API question open.  Andres objected to the
> general form, and Heikki suggested exposing only read, write and CAS.
> 
> Is the current patchset still the intended design, or should it be
> updated after that discussion?  I have moved the entry back to Needs
> Review until that is clear.

My interpretation is that the signed atomics stuff would be a follow-up
effort.  I'm still planning to commit the v2 patch set soon.

If you have questions about the status of one of my commitfest entries,
please ask before you change it.

-- 
nathan


Re: convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
Вложения:
I've now committed everything except for these last two patches, which I'm
planning to commit tomorrow.

-- 
nathan

Re: convert various variables to atomics

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Tue, Sep 22, 2026 at 02:50:19PM -0500, Nathan Bossart wrote:
> I've now committed everything except for these last two patches, which I'm
> planning to commit tomorrow.

I've now committed everything tracked in this thread.

-- 
nathan


FAQ