mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Allow dynamic shared memory segments to be kept until shutdown.
Amit Kapila, reviewed by Kyotaro Horiguchi, with some further changes by me.
This commit is contained in:
@@ -885,6 +885,33 @@ dsm_keep_mapping(dsm_segment *seg)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep a dynamic shared memory segment until postmaster shutdown.
|
||||
*
|
||||
* This function should not be called more than once per segment;
|
||||
* on Windows, doing so will create unnecessary handles which will
|
||||
* consume system resources to no benefit.
|
||||
*
|
||||
* Note that this function does not arrange for the current process to
|
||||
* keep the segment mapped indefinitely; if that behavior is desired,
|
||||
* dsm_keep_mapping() should be used from each process that needs to
|
||||
* retain the mapping.
|
||||
*/
|
||||
void
|
||||
dsm_keep_segment(dsm_segment *seg)
|
||||
{
|
||||
/*
|
||||
* Bump reference count for this segment in shared memory. This will
|
||||
* ensure that even if there is no session which is attached to this
|
||||
* segment, it will remain until postmaster shutdown.
|
||||
*/
|
||||
LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE);
|
||||
dsm_control->item[seg->control_slot].refcnt++;
|
||||
LWLockRelease(DynamicSharedMemoryControlLock);
|
||||
|
||||
dsm_impl_keep_segment(seg->handle, seg->impl_private);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find an existing mapping for a shared memory segment, if there is one.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user