mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Make it easy to detach completely from shared memory.
The new function dsm_detach_all() can be used either by postmaster children that don't wish to take any risk of accidentally corrupting shared memory; or by forked children of regular backends with the same need. This patch also updates the postmaster children that already do PGSharedMemoryDetach() to do dsm_detach_all() as well. Per discussion with Tom Lane.
This commit is contained in:
parent
551fb5ac74
commit
79a4d24f31
@ -40,6 +40,7 @@
|
||||
#include "postmaster/fork_process.h"
|
||||
#include "postmaster/pgarch.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/latch.h"
|
||||
@ -163,6 +164,7 @@ pgarch_start(void)
|
||||
on_exit_reset();
|
||||
|
||||
/* Drop our connection to postmaster's shared memory, as well */
|
||||
dsm_detach_all();
|
||||
PGSharedMemoryDetach();
|
||||
|
||||
PgArchiverMain(0, NULL);
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/proc.h"
|
||||
#include "storage/backendid.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/latch.h"
|
||||
@ -709,6 +710,7 @@ pgstat_start(void)
|
||||
on_exit_reset();
|
||||
|
||||
/* Drop our connection to postmaster's shared memory, as well */
|
||||
dsm_detach_all();
|
||||
PGSharedMemoryDetach();
|
||||
|
||||
PgstatCollectorMain(0, NULL);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "postmaster/fork_process.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "postmaster/syslogger.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/latch.h"
|
||||
#include "storage/pg_shmem.h"
|
||||
@ -626,6 +627,7 @@ SysLogger_Start(void)
|
||||
on_exit_reset();
|
||||
|
||||
/* Drop our connection to postmaster's shared memory, as well */
|
||||
dsm_detach_all();
|
||||
PGSharedMemoryDetach();
|
||||
|
||||
/* do the work */
|
||||
|
@ -722,6 +722,8 @@ dsm_attach(dsm_handle h)
|
||||
|
||||
/*
|
||||
* At backend shutdown time, detach any segments that are still attached.
|
||||
* (This is similar to dsm_detach_all, except that there's no reason to
|
||||
* unmap the control segment before exiting, so we don't bother.)
|
||||
*/
|
||||
void
|
||||
dsm_backend_shutdown(void)
|
||||
@ -735,6 +737,31 @@ dsm_backend_shutdown(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Detach all shared memory segments, including the control segments. This
|
||||
* should be called, along with PGSharedMemoryDetach, in processes that
|
||||
* might inherit mappings but are not intended to be connected to dynamic
|
||||
* shared memory.
|
||||
*/
|
||||
void
|
||||
dsm_detach_all(void)
|
||||
{
|
||||
void *control_address = dsm_control;
|
||||
|
||||
while (!dlist_is_empty(&dsm_segment_list))
|
||||
{
|
||||
dsm_segment *seg;
|
||||
|
||||
seg = dlist_head_element(dsm_segment, node, &dsm_segment_list);
|
||||
dsm_detach(seg);
|
||||
}
|
||||
|
||||
if (control_address != NULL)
|
||||
dsm_impl_op(DSM_OP_DETACH, dsm_control_handle, 0,
|
||||
&dsm_control_impl_private, &control_address,
|
||||
&dsm_control_mapped_size, ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Resize an existing shared memory segment.
|
||||
*
|
||||
|
@ -20,6 +20,7 @@ typedef struct dsm_segment dsm_segment;
|
||||
/* Startup and shutdown functions. */
|
||||
extern void dsm_postmaster_startup(void);
|
||||
extern void dsm_backend_shutdown(void);
|
||||
extern void dsm_detach_all(void);
|
||||
|
||||
/* Functions that create, update, or remove mappings. */
|
||||
extern dsm_segment *dsm_create(Size size);
|
||||
|
Loading…
Reference in New Issue
Block a user