File tree Expand file tree Collapse file tree 5 files changed +34
-0
lines changed Expand file tree Collapse file tree 5 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 4040#include "postmaster/fork_process.h"
4141#include "postmaster/pgarch.h"
4242#include "postmaster/postmaster.h"
43+ #include "storage/dsm.h"
4344#include "storage/fd.h"
4445#include "storage/ipc.h"
4546#include "storage/latch.h"
@@ -163,6 +164,7 @@ pgarch_start(void)
163164 on_exit_reset ();
164165
165166 /* Drop our connection to postmaster's shared memory, as well */
167+ dsm_detach_all ();
166168 PGSharedMemoryDetach ();
167169
168170 PgArchiverMain (0 , NULL );
Original file line number Diff line number Diff line change 5050#include "postmaster/postmaster.h"
5151#include "storage/proc.h"
5252#include "storage/backendid.h"
53+ #include "storage/dsm.h"
5354#include "storage/fd.h"
5455#include "storage/ipc.h"
5556#include "storage/latch.h"
@@ -709,6 +710,7 @@ pgstat_start(void)
709710 on_exit_reset ();
710711
711712 /* Drop our connection to postmaster's shared memory, as well */
713+ dsm_detach_all ();
712714 PGSharedMemoryDetach ();
713715
714716 PgstatCollectorMain (0 , NULL );
Original file line number Diff line number Diff line change 3939#include "postmaster/fork_process.h"
4040#include "postmaster/postmaster.h"
4141#include "postmaster/syslogger.h"
42+ #include "storage/dsm.h"
4243#include "storage/ipc.h"
4344#include "storage/latch.h"
4445#include "storage/pg_shmem.h"
@@ -626,6 +627,7 @@ SysLogger_Start(void)
626627 on_exit_reset ();
627628
628629 /* Drop our connection to postmaster's shared memory, as well */
630+ dsm_detach_all ();
629631 PGSharedMemoryDetach ();
630632
631633 /* do the work */
Original file line number Diff line number Diff line change @@ -722,6 +722,8 @@ dsm_attach(dsm_handle h)
722722
723723/*
724724 * At backend shutdown time, detach any segments that are still attached.
725+ * (This is similar to dsm_detach_all, except that there's no reason to
726+ * unmap the control segment before exiting, so we don't bother.)
725727 */
726728void
727729dsm_backend_shutdown (void )
@@ -735,6 +737,31 @@ dsm_backend_shutdown(void)
735737 }
736738}
737739
740+ /*
741+ * Detach all shared memory segments, including the control segments. This
742+ * should be called, along with PGSharedMemoryDetach, in processes that
743+ * might inherit mappings but are not intended to be connected to dynamic
744+ * shared memory.
745+ */
746+ void
747+ dsm_detach_all (void )
748+ {
749+ void * control_address = dsm_control ;
750+
751+ while (!dlist_is_empty (& dsm_segment_list ))
752+ {
753+ dsm_segment * seg ;
754+
755+ seg = dlist_head_element (dsm_segment , node , & dsm_segment_list );
756+ dsm_detach (seg );
757+ }
758+
759+ if (control_address != NULL )
760+ dsm_impl_op (DSM_OP_DETACH , dsm_control_handle , 0 ,
761+ & dsm_control_impl_private , & control_address ,
762+ & dsm_control_mapped_size , ERROR );
763+ }
764+
738765/*
739766 * Resize an existing shared memory segment.
740767 *
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ typedef struct dsm_segment dsm_segment;
2020/* Startup and shutdown functions. */
2121extern void dsm_postmaster_startup (void );
2222extern void dsm_backend_shutdown (void );
23+ extern void dsm_detach_all (void );
2324
2425/* Functions that create, update, or remove mappings. */
2526extern dsm_segment * dsm_create (Size size );
You can’t perform that action at this time.
0 commit comments