32
32
#include "access/xact.h"
33
33
#include "catalog/pg_class.h"
34
34
#include "catalog/pg_type.h"
35
- #include "miscadmin.h"
36
35
#include "pgstat.h"
37
36
#include "postmaster/bgworker.h"
38
37
#include "postmaster/interrupt.h"
39
38
#include "storage/buf_internals.h"
40
39
#include "storage/dsm.h"
40
+ #include "storage/dsm_registry.h"
41
41
#include "storage/fd.h"
42
42
#include "storage/ipc.h"
43
43
#include "storage/latch.h"
@@ -95,8 +95,6 @@ static void apw_start_database_worker(void);
95
95
static bool apw_init_shmem (void );
96
96
static void apw_detach_shmem (int code , Datum arg );
97
97
static int apw_compare_blockinfo (const void * p , const void * q );
98
- static void autoprewarm_shmem_request (void );
99
- static shmem_request_hook_type prev_shmem_request_hook = NULL ;
100
98
101
99
/* Pointer to shared-memory state. */
102
100
static AutoPrewarmSharedState * apw_state = NULL ;
@@ -140,26 +138,11 @@ _PG_init(void)
140
138
141
139
MarkGUCPrefixReserved ("pg_prewarm" );
142
140
143
- prev_shmem_request_hook = shmem_request_hook ;
144
- shmem_request_hook = autoprewarm_shmem_request ;
145
-
146
141
/* Register autoprewarm worker, if enabled. */
147
142
if (autoprewarm )
148
143
apw_start_leader_worker ();
149
144
}
150
145
151
- /*
152
- * Requests any additional shared memory required for autoprewarm.
153
- */
154
- static void
155
- autoprewarm_shmem_request (void )
156
- {
157
- if (prev_shmem_request_hook )
158
- prev_shmem_request_hook ();
159
-
160
- RequestAddinShmemSpace (MAXALIGN (sizeof (AutoPrewarmSharedState )));
161
- }
162
-
163
146
/*
164
147
* Main entry point for the leader autoprewarm process. Per-database workers
165
148
* have a separate entry point.
@@ -767,6 +750,16 @@ autoprewarm_dump_now(PG_FUNCTION_ARGS)
767
750
PG_RETURN_INT64 ((int64 ) num_blocks );
768
751
}
769
752
753
+ static void
754
+ apw_init_state (void * ptr )
755
+ {
756
+ AutoPrewarmSharedState * state = (AutoPrewarmSharedState * ) ptr ;
757
+
758
+ LWLockInitialize (& state -> lock , LWLockNewTrancheId ());
759
+ state -> bgworker_pid = InvalidPid ;
760
+ state -> pid_using_dumpfile = InvalidPid ;
761
+ }
762
+
770
763
/*
771
764
* Allocate and initialize autoprewarm related shared memory, if not already
772
765
* done, and set up backend-local pointer to that state. Returns true if an
@@ -777,19 +770,10 @@ apw_init_shmem(void)
777
770
{
778
771
bool found ;
779
772
780
- LWLockAcquire (AddinShmemInitLock , LW_EXCLUSIVE );
781
- apw_state = ShmemInitStruct ("autoprewarm" ,
782
- sizeof (AutoPrewarmSharedState ),
783
- & found );
784
- if (!found )
785
- {
786
- /* First time through ... */
787
- LWLockInitialize (& apw_state -> lock , LWLockNewTrancheId ());
788
- apw_state -> bgworker_pid = InvalidPid ;
789
- apw_state -> pid_using_dumpfile = InvalidPid ;
790
- }
791
- LWLockRelease (AddinShmemInitLock );
792
-
773
+ apw_state = GetNamedDSMSegment ("autoprewarm" ,
774
+ sizeof (AutoPrewarmSharedState ),
775
+ apw_init_state ,
776
+ & found );
793
777
LWLockRegisterTranche (apw_state -> lock .tranche , "autoprewarm" );
794
778
795
779
return found ;
0 commit comments