From 5cd8e6b8b5304b6faf1f3500e89b9b5685930caa Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Thu, 25 Sep 2025 16:35:03 +0000 Subject: [PATCH 1/2] fix --- src/backend/postmaster/postmaster.c | 7 +++++++ src/backend/storage/ipc/ipci.c | 5 +++++ src/backend/utils/misc/guc_gp.c | 11 +++++++++++ src/include/postmaster/backoff.h | 1 + src/include/postmaster/postmaster.h | 2 ++ src/include/utils/sync_guc_name.h | 1 + 6 files changed, 27 insertions(+) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3a5bf1bf797..e805a034306 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -239,6 +239,8 @@ int ReservedBackends; #define MAXLISTEN 64 static pgsocket ListenSocket[MAXLISTEN]; +unsigned char *ForkLock = NULL; + /* * Set by the -o option */ @@ -4498,6 +4500,9 @@ BackendStartup(Port *port) #ifdef EXEC_BACKEND pid = backend_forkexec(port); #else /* !EXEC_BACKEND */ + + if (gp_enable_fork_lock) + SpinLockAcquire(ForkLock); pid = fork_process(); if (pid == 0) /* child */ { @@ -4522,6 +4527,8 @@ BackendStartup(Port *port) /* Perform additional initialization and collect startup packet */ BackendInitialize(port); + if (gp_enable_fork_lock) + SpinLockRelease(ForkLock); /* And run the backend */ BackendRun(port); diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 158aca09ce0..93937fa2e79 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -372,6 +372,11 @@ CreateSharedMemoryAndSemaphores(int port) if (gp_enable_resqueue_priority) BackoffStateInit(); + if (gp_enable_fork_lock) { + /* Create ProcStructLock spinlock, too */ + ForkLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); + SpinLockInit(ForkLock); + } /* Initialize dynamic shared memory facilities. */ if (!IsUnderPostmaster) diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 5203116d76e..487ee3402fb 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -215,6 +215,7 @@ static char *gp_resource_manager_str; /* Backoff-related GUCs */ bool gp_enable_resqueue_priority; +bool gp_enable_fork_lock; int gp_resqueue_priority_local_interval; int gp_resqueue_priority_sweeper_interval; int gp_resqueue_priority_inactivity_timeout; @@ -1744,6 +1745,16 @@ struct config_bool ConfigureNamesBool_gp[] = NULL, NULL, NULL }, + { + {"gp_enable_fork_lock", PGC_POSTMASTER, RESOURCES_MGM, + gettext_noop("Enables priority scheduling."), + NULL + }, + &gp_enable_fork_lock, + true, + NULL, NULL, NULL + }, + { {"debug_resource_group", PGC_USERSET, DEVELOPER_OPTIONS, gettext_noop("Prints resource groups debug logs."), diff --git a/src/include/postmaster/backoff.h b/src/include/postmaster/backoff.h index 2f23c9825fd..2d37123c9fb 100644 --- a/src/include/postmaster/backoff.h +++ b/src/include/postmaster/backoff.h @@ -12,6 +12,7 @@ /* GUCs */ extern bool gp_enable_resqueue_priority; +extern bool gp_enable_fork_lock; extern int gp_resqueue_priority_local_interval; extern int gp_resqueue_priority_sweeper_interval; extern int gp_resqueue_priority_inactivity_timeout; diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index 54a2f1d6919..44a3bde6cf0 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -55,6 +55,8 @@ extern int postmaster_alive_fds[2]; extern const char *progname; extern PGDLLIMPORT const char *progname; +extern unsigned char *ForkLock; + extern void PostmasterMain(int argc, char *argv[]) __attribute__((noreturn)); extern void ClosePostmasterPorts(bool am_syslogger); diff --git a/src/include/utils/sync_guc_name.h b/src/include/utils/sync_guc_name.h index 82a9b3733d2..9cece6f1c53 100644 --- a/src/include/utils/sync_guc_name.h +++ b/src/include/utils/sync_guc_name.h @@ -23,6 +23,7 @@ "gp_enable_mk_sort", "gp_enable_motion_mk_sort", "gp_enable_segment_copy_checking", + "gp_enable_fork_lock", "gp_external_enable_filter_pushdown", "gp_gpperfmon_send_interval", "gp_hashagg_default_nbatches", From abdad4f6c34b136f923e420711a1177af3c593c1 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Thu, 25 Sep 2025 18:52:16 +0000 Subject: [PATCH 2/2] f --- src/backend/postmaster/postmaster.c | 7 +++---- src/backend/storage/ipc/ipci.c | 2 +- src/backend/utils/misc/guc_gp.c | 26 ++++++++++++++------------ src/include/postmaster/backoff.h | 2 +- src/include/utils/sync_guc_name.h | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index e805a034306..b8aa324e518 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -4501,8 +4501,9 @@ BackendStartup(Port *port) pid = backend_forkexec(port); #else /* !EXEC_BACKEND */ - if (gp_enable_fork_lock) - SpinLockAcquire(ForkLock); + if (gp_enable_fork_sleep) + pg_usleep(gp_enable_fork_sleep * 1000 /*ms*/); + pid = fork_process(); if (pid == 0) /* child */ { @@ -4527,8 +4528,6 @@ BackendStartup(Port *port) /* Perform additional initialization and collect startup packet */ BackendInitialize(port); - if (gp_enable_fork_lock) - SpinLockRelease(ForkLock); /* And run the backend */ BackendRun(port); diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 93937fa2e79..e303e8d77af 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -372,7 +372,7 @@ CreateSharedMemoryAndSemaphores(int port) if (gp_enable_resqueue_priority) BackoffStateInit(); - if (gp_enable_fork_lock) { + if (gp_enable_fork_sleep) { /* Create ProcStructLock spinlock, too */ ForkLock = (slock_t *) ShmemAlloc(sizeof(slock_t)); SpinLockInit(ForkLock); diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 487ee3402fb..99a0d578a87 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -215,7 +215,7 @@ static char *gp_resource_manager_str; /* Backoff-related GUCs */ bool gp_enable_resqueue_priority; -bool gp_enable_fork_lock; +int gp_enable_fork_sleep; int gp_resqueue_priority_local_interval; int gp_resqueue_priority_sweeper_interval; int gp_resqueue_priority_inactivity_timeout; @@ -1744,17 +1744,6 @@ struct config_bool ConfigureNamesBool_gp[] = true, NULL, NULL, NULL }, - - { - {"gp_enable_fork_lock", PGC_POSTMASTER, RESOURCES_MGM, - gettext_noop("Enables priority scheduling."), - NULL - }, - &gp_enable_fork_lock, - true, - NULL, NULL, NULL - }, - { {"debug_resource_group", PGC_USERSET, DEVELOPER_OPTIONS, gettext_noop("Prints resource groups debug logs."), @@ -3350,6 +3339,19 @@ struct config_bool ConfigureNamesBool_gp[] = struct config_int ConfigureNamesInt_gp[] = { + + { + {"gp_enable_fork_sleep", PGC_USERSET, RESOURCES_MGM, + gettext_noop("Enables priority scheduling."), + gettext_noop("Enables priority scheduling."), + GUC_UNIT_S | GUC_NOT_IN_SAMPLE + }, + &gp_enable_fork_sleep, + 1000, 0, 72000, + NULL, NULL, NULL + }, + + { {"readable_external_table_timeout", PGC_USERSET, EXTERNAL_TABLES, gettext_noop("Cancel the query if no data read within N seconds."), diff --git a/src/include/postmaster/backoff.h b/src/include/postmaster/backoff.h index 2d37123c9fb..2a13c52a80f 100644 --- a/src/include/postmaster/backoff.h +++ b/src/include/postmaster/backoff.h @@ -12,7 +12,7 @@ /* GUCs */ extern bool gp_enable_resqueue_priority; -extern bool gp_enable_fork_lock; +extern int gp_enable_fork_sleep; extern int gp_resqueue_priority_local_interval; extern int gp_resqueue_priority_sweeper_interval; extern int gp_resqueue_priority_inactivity_timeout; diff --git a/src/include/utils/sync_guc_name.h b/src/include/utils/sync_guc_name.h index 9cece6f1c53..984275be057 100644 --- a/src/include/utils/sync_guc_name.h +++ b/src/include/utils/sync_guc_name.h @@ -23,7 +23,7 @@ "gp_enable_mk_sort", "gp_enable_motion_mk_sort", "gp_enable_segment_copy_checking", - "gp_enable_fork_lock", + "gp_enable_fork_sleep", "gp_external_enable_filter_pushdown", "gp_gpperfmon_send_interval", "gp_hashagg_default_nbatches",