On Tue, Dec 02, 2025 at 10:31:33AM -0600, Nathan Bossart wrote: > On Tue, Dec 02, 2025 at 02:28:29PM +0530, Rahila Syed wrote: >> Thank you for highlighting the discussions. I'm unsure about the best >> approach here, but I think it would be safe to stay consistent with the >> rest of the code in dsa.c, especially since it's unclear that the use of >> LW_EXCLUSIVE for reading values in dsa is a mistake. > > Okay. I switched to LW_EXCLUSIVE and will consider starting a new thread > to use LW_SHARED when possible in dsa.c.
Here is a patch that switches to LW_SHARED in dsa_get_total_size() and dsa_get_total_size_from_handle(). Another candidate was dsa_dump(), but that function appears to do some things that require more than a shared lock. In any case, it's just a debugging function, and I found no uses in-tree or elsewhere. -- nathan
>From f25ccc54e25f6db9b7b07b0b1ca771f7c758620f Mon Sep 17 00:00:00 2001 From: Nathan Bossart <[email protected]> Date: Tue, 2 Dec 2025 11:16:17 -0600 Subject: [PATCH v1 1/1] use LW_SHARED in dsa.c when appropriate --- src/backend/utils/mmgr/dsa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c index c8a72686177..4b6bcffea28 100644 --- a/src/backend/utils/mmgr/dsa.c +++ b/src/backend/utils/mmgr/dsa.c @@ -1043,7 +1043,7 @@ dsa_get_total_size(dsa_area *area) { size_t size; - LWLockAcquire(DSA_AREA_LOCK(area), LW_EXCLUSIVE); + LWLockAcquire(DSA_AREA_LOCK(area), LW_SHARED); size = area->control->total_segment_size; LWLockRelease(DSA_AREA_LOCK(area)); @@ -1075,7 +1075,7 @@ dsa_get_total_size_from_handle(dsa_handle handle) control = (dsa_area_control *) dsm_segment_address(segment); - LWLockAcquire(&control->lock, LW_EXCLUSIVE); + LWLockAcquire(&control->lock, LW_SHARED); size = control->total_segment_size; LWLockRelease(&control->lock); -- 2.39.5 (Apple Git-154)
