mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 10:11:13 +02:00
Fix min_dynamic_shared_memory on Windows.
When min_dynamic_shared_memory is set above 0, we try to find space in a
pre-allocated region of the main shared memory area instead of calling
dsm_impl_XXX() routines to allocate more. The dsm_pin_segment() and
dsm_unpin_segment() routines had a bug: they called dsm_impl_XXX()
routines even for main region segments. Nobody noticed before now
because those routines do nothing on Unix, but on Windows they'd fail
while attempting to duplicate an invalid Windows HANDLE. Add the
missing gating.
Back-patch to 14, where commit 84b1c63a
added this feature. Fixes
pgsql-bugs bug #18165.
Reported-by: Maxime Boyer <maxime.boyer@cra-arc.gc.ca>
Tested-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/18165-bf4f525cea6e51de%40postgresql.org
This commit is contained in:
parent
2d870b4aef
commit
dab889d60b
@ -927,7 +927,7 @@ dsm_unpin_mapping(dsm_segment *seg)
|
|||||||
void
|
void
|
||||||
dsm_pin_segment(dsm_segment *seg)
|
dsm_pin_segment(dsm_segment *seg)
|
||||||
{
|
{
|
||||||
void *handle;
|
void *handle = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bump reference count for this segment in shared memory. This will
|
* Bump reference count for this segment in shared memory. This will
|
||||||
@ -938,6 +938,7 @@ dsm_pin_segment(dsm_segment *seg)
|
|||||||
LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE);
|
LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE);
|
||||||
if (dsm_control->item[seg->control_slot].pinned)
|
if (dsm_control->item[seg->control_slot].pinned)
|
||||||
elog(ERROR, "cannot pin a segment that is already pinned");
|
elog(ERROR, "cannot pin a segment that is already pinned");
|
||||||
|
if (!is_main_region_dsm_handle(seg->handle))
|
||||||
dsm_impl_pin_segment(seg->handle, seg->impl_private, &handle);
|
dsm_impl_pin_segment(seg->handle, seg->impl_private, &handle);
|
||||||
dsm_control->item[seg->control_slot].pinned = true;
|
dsm_control->item[seg->control_slot].pinned = true;
|
||||||
dsm_control->item[seg->control_slot].refcnt++;
|
dsm_control->item[seg->control_slot].refcnt++;
|
||||||
@ -995,6 +996,7 @@ dsm_unpin_segment(dsm_handle handle)
|
|||||||
* releasing the lock, because impl_private_pm_handle may get modified by
|
* releasing the lock, because impl_private_pm_handle may get modified by
|
||||||
* dsm_impl_unpin_segment.
|
* dsm_impl_unpin_segment.
|
||||||
*/
|
*/
|
||||||
|
if (!is_main_region_dsm_handle(handle))
|
||||||
dsm_impl_unpin_segment(handle,
|
dsm_impl_unpin_segment(handle,
|
||||||
&dsm_control->item[control_slot].impl_private_pm_handle);
|
&dsm_control->item[control_slot].impl_private_pm_handle);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user