agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v5 1/3] Remove fallback declaration for tas(). 199+ messages / 1 participants [nested] [flat]
* [PATCH v5 1/3] Remove fallback declaration for tas(). @ 2026-05-04 21:04 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-05-04 21:04 UTC (permalink / raw) The last definition of tas() in s_lock.c was removed in commit 718aa43a4e, and the last tas.s file was removed in commit 25f36066dd, so this is dead code. --- src/backend/Makefile | 2 +- src/backend/port/.gitignore | 1 - src/backend/port/meson.build | 2 +- src/include/storage/s_lock.h | 7 ------- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 162d3f1f2a9..4bb76d3d397 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -301,7 +301,7 @@ endif distclean: clean # generated by configure - rm -f port/tas.s port/pg_sema.c port/pg_shmem.c + rm -f port/pg_sema.c port/pg_shmem.c ########################################################################## diff --git a/src/backend/port/.gitignore b/src/backend/port/.gitignore index 4ef36b82c77..6c5067a4a9f 100644 --- a/src/backend/port/.gitignore +++ b/src/backend/port/.gitignore @@ -1,3 +1,2 @@ /pg_sema.c /pg_shmem.c -/tas.s diff --git a/src/backend/port/meson.build b/src/backend/port/meson.build index e8b7da8d281..29e88ef3541 100644 --- a/src/backend/port/meson.build +++ b/src/backend/port/meson.build @@ -30,4 +30,4 @@ if host_system == 'windows' endif # autoconf generates the file there, ensure we get a conflict -generated_sources_ac += {'src/backend/port': ['pg_sema.c', 'pg_shmem.c', 'tas.s']} +generated_sources_ac += {'src/backend/port': ['pg_sema.c', 'pg_shmem.c']} diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index c9e52511990..dcfec8ce2af 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -697,13 +697,6 @@ extern void s_unlock(volatile slock_t *lock); #define SPIN_DELAY() ((void) 0) #endif /* SPIN_DELAY */ -#if !defined(TAS) -extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or - * s_lock.c */ - -#define TAS(lock) tas(lock) -#endif /* TAS */ - #if !defined(TAS_SPIN) #define TAS_SPIN(lock) TAS(lock) #endif /* TAS_SPIN */ -- 2.50.1 (Apple Git-155) --EzTP03ol5OjsRjZr Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v5-0002-Remove-HAS_TEST_AND_SET.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
* [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic @ 2026-07-09 19:53 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 199+ messages in thread From: Nathan Bossart @ 2026-07-09 19:53 UTC (permalink / raw) --- src/backend/storage/file/sharedfileset.c | 27 +++++++++--------------- src/include/storage/sharedfileset.h | 5 ++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index d76bd72dc63..4f12f92beae 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -38,8 +38,7 @@ void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) { /* Initialize the shared fileset specific members. */ - SpinLockInit(&fileset->mutex); - fileset->refcnt = 1; + pg_atomic_init_u32(&fileset->refcnt, 1); /* Initialize the fileset. */ FileSetInit(&fileset->fs); @@ -55,19 +54,15 @@ SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg) void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg) { - bool success; + uint32 refcnt; - SpinLockAcquire(&fileset->mutex); - if (fileset->refcnt == 0) - success = false; - else - { - ++fileset->refcnt; - success = true; - } - SpinLockRelease(&fileset->mutex); + refcnt = pg_atomic_read_u32(&fileset->refcnt); + while (refcnt != 0 && + !pg_atomic_compare_exchange_u32(&fileset->refcnt, &refcnt, + refcnt + 1)) + ; - if (!success) + if (refcnt == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("could not attach to a SharedFileSet that is already destroyed"))); @@ -98,11 +93,9 @@ SharedFileSetOnDetach(dsm_segment *segment, Datum datum) bool unlink_all = false; SharedFileSet *fileset = (SharedFileSet *) DatumGetPointer(datum); - SpinLockAcquire(&fileset->mutex); - Assert(fileset->refcnt > 0); - if (--fileset->refcnt == 0) + Assert(pg_atomic_read_u32(&fileset->refcnt) > 0); + if (pg_atomic_sub_fetch_u32(&fileset->refcnt, 1) == 0) unlink_all = true; - SpinLockRelease(&fileset->mutex); /* * If we are the last to detach, we delete the directory in all diff --git a/src/include/storage/sharedfileset.h b/src/include/storage/sharedfileset.h index 904396e7173..d89626ae64b 100644 --- a/src/include/storage/sharedfileset.h +++ b/src/include/storage/sharedfileset.h @@ -15,10 +15,10 @@ #ifndef SHAREDFILESET_H #define SHAREDFILESET_H +#include "port/atomics.h" #include "storage/dsm.h" #include "storage/fd.h" #include "storage/fileset.h" -#include "storage/spin.h" /* * A set of temporary files that can be shared by multiple backends. @@ -26,8 +26,7 @@ typedef struct SharedFileSet { FileSet fs; - slock_t mutex; /* mutex protecting the reference count */ - int refcnt; /* number of attached backends */ + pg_atomic_uint32 refcnt; /* number of attached backends */ } SharedFileSet; extern void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg); -- 2.50.1 (Apple Git-155) --Ot5x3ffkWEuxilWO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0007-convert-ParallelBlockTableScanDescData-phs_-start.patch ^ permalink raw reply [nested|flat] 199+ messages in thread
end of thread, other threads:[~2026-07-09 19:53 UTC | newest] Thread overview: 199+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-05-04 21:04 [PATCH v5 1/3] Remove fallback declaration for tas(). Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]> 2026-07-09 19:53 [PATCH v1 6/8] convert SharedFileSet->refcnt to an atomic Nathan Bossart <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox