Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabb0b4f

Browse files
Teach autoprewarm to use the dynamic shared memory registry.
Besides showcasing the DSM registry, this prevents pg_prewarm fromstealing from the main shared memory segment's extra buffer spacewhen autoprewarm_start_worker() and autoprewarm_dump_now() are usedwithout loading the module via shared_preload_libraries.Suggested-by: Michael PaquierReviewed-by: Bharath RupireddyDiscussion:https://postgr.es/m/20231205034647.GA2705267%40nathanxps13
1 parent8b2bcf3 commitabb0b4f

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

‎contrib/pg_prewarm/autoprewarm.c

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
#include"access/xact.h"
3333
#include"catalog/pg_class.h"
3434
#include"catalog/pg_type.h"
35-
#include"miscadmin.h"
3635
#include"pgstat.h"
3736
#include"postmaster/bgworker.h"
3837
#include"postmaster/interrupt.h"
3938
#include"storage/buf_internals.h"
4039
#include"storage/dsm.h"
40+
#include"storage/dsm_registry.h"
4141
#include"storage/fd.h"
4242
#include"storage/ipc.h"
4343
#include"storage/latch.h"
@@ -95,8 +95,6 @@ static void apw_start_database_worker(void);
9595
staticboolapw_init_shmem(void);
9696
staticvoidapw_detach_shmem(intcode,Datumarg);
9797
staticintapw_compare_blockinfo(constvoid*p,constvoid*q);
98-
staticvoidautoprewarm_shmem_request(void);
99-
staticshmem_request_hook_typeprev_shmem_request_hook=NULL;
10098

10199
/* Pointer to shared-memory state. */
102100
staticAutoPrewarmSharedState*apw_state=NULL;
@@ -140,26 +138,11 @@ _PG_init(void)
140138

141139
MarkGUCPrefixReserved("pg_prewarm");
142140

143-
prev_shmem_request_hook=shmem_request_hook;
144-
shmem_request_hook=autoprewarm_shmem_request;
145-
146141
/* Register autoprewarm worker, if enabled. */
147142
if (autoprewarm)
148143
apw_start_leader_worker();
149144
}
150145

151-
/*
152-
* Requests any additional shared memory required for autoprewarm.
153-
*/
154-
staticvoid
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-
163146
/*
164147
* Main entry point for the leader autoprewarm process. Per-database workers
165148
* have a separate entry point.
@@ -767,6 +750,16 @@ autoprewarm_dump_now(PG_FUNCTION_ARGS)
767750
PG_RETURN_INT64((int64)num_blocks);
768751
}
769752

753+
staticvoid
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+
770763
/*
771764
* Allocate and initialize autoprewarm related shared memory, if not already
772765
* done, and set up backend-local pointer to that state. Returns true if an
@@ -777,19 +770,10 @@ apw_init_shmem(void)
777770
{
778771
boolfound;
779772

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);
793777
LWLockRegisterTranche(apw_state->lock.tranche,"autoprewarm");
794778

795779
returnfound;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp