From 96ad5dcd77bb8d2e4c9c3ca06ae4dcf43017defe Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Tue, 14 Feb 2023 15:29:41 -0600 Subject: [PATCH v4 2/2] f! convert to an enum --- doc/src/sgml/config.sgml | 2 +- src/backend/utils/misc/guc_tables.c | 32 ++++++++++++++++++----------- src/include/storage/pg_shmem.h | 8 ++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 3ff301edf8a..1f6f71a2826 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -10681,23 +10681,23 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' macro USE_ASSERT_CHECKING is defined when PostgreSQL is built (accomplished e.g., by the configure option ). By default PostgreSQL is built without assertions. - huge_pages_active (string) + huge_pages_active (enum) huge_pages_active configuration parameter Reports whether huge pages are in use by the current instance. See for more information. diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 1a298f16c81..f9c98997492 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -339,22 +339,29 @@ static const struct config_enum_entry huge_pages_options[] = { {"on", HUGE_PAGES_ON, false}, {"try", HUGE_PAGES_TRY, false}, {"true", HUGE_PAGES_ON, true}, {"false", HUGE_PAGES_OFF, true}, {"yes", HUGE_PAGES_ON, true}, {"no", HUGE_PAGES_OFF, true}, {"1", HUGE_PAGES_ON, true}, {"0", HUGE_PAGES_OFF, true}, {NULL, 0, false} }; +static const struct config_enum_entry huge_pages_active_options[] = { + {"unknown", HUGE_PAGES_ACTIVE_UNKNOWN, false}, + {"false", HUGE_PAGES_ACTIVE_FALSE, false}, + {"true", HUGE_PAGES_ACTIVE_TRUE, false}, + {NULL, 0, false} +}; + static const struct config_enum_entry recovery_prefetch_options[] = { {"off", RECOVERY_PREFETCH_OFF, false}, {"on", RECOVERY_PREFETCH_ON, false}, {"try", RECOVERY_PREFETCH_TRY, false}, {"true", RECOVERY_PREFETCH_ON, true}, {"false", RECOVERY_PREFETCH_OFF, true}, {"yes", RECOVERY_PREFETCH_ON, true}, {"no", RECOVERY_PREFETCH_OFF, true}, {"1", RECOVERY_PREFETCH_ON, true}, {"0", RECOVERY_PREFETCH_OFF, true}, {NULL, 0, false} @@ -527,22 +534,24 @@ int tcp_user_timeout; * renegotiation and therefore always try to zero it. */ int ssl_renegotiation_limit; /* * This really belongs in pg_shmem.c, but is defined here so that it doesn't * need to be duplicated in all the different implementations of pg_shmem.c. */ int huge_pages = HUGE_PAGES_TRY; int huge_page_size; +int huge_pages_active = HUGE_PAGES_ACTIVE_UNKNOWN; + /* * These variables are all dummies that don't do anything, except in some * cases provide the value for SHOW to display. The real state is elsewhere * and is kept in sync by assign_hooks. */ static char *syslog_ident_str; static double phony_random_seed; static char *client_encoding_string; static char *datestyle_string; static char *locale_collate; static char *locale_ctype; @@ -554,23 +563,22 @@ static int server_version_num; #define DEFAULT_SYSLOG_FACILITY LOG_LOCAL0 #else #define DEFAULT_SYSLOG_FACILITY 0 #endif static int syslog_facility = DEFAULT_SYSLOG_FACILITY; static char *timezone_string; static char *log_timezone_string; static char *timezone_abbreviations_string; static char *data_directory; static char *session_authorization_string; -static char *huge_pages_active = "unknown"; /* dynamically set */ static int max_function_args; static int max_index_keys; static int max_identifier_length; static int block_size; static int segment_size; static int shared_memory_size_mb; static int shared_memory_size_in_huge_pages; static int wal_block_size; static bool data_checksums; static bool integer_datetimes; @@ -4517,33 +4525,22 @@ struct config_string ConfigureNamesString[] = { {"backtrace_functions", PGC_SUSET, DEVELOPER_OPTIONS, gettext_noop("Log backtrace for errors in these functions."), NULL, GUC_NOT_IN_SAMPLE }, &backtrace_functions, "", check_backtrace_functions, assign_backtrace_functions, NULL }, - { - {"huge_pages_active", PGC_INTERNAL, PRESET_OPTIONS, - gettext_noop("Indicates whether huge pages are in use."), - NULL, - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED - }, - &huge_pages_active, - "unknown", - NULL, NULL, NULL - }, - /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL } }; struct config_enum ConfigureNamesEnum[] = { { {"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS, @@ -4845,22 +4842,33 @@ struct config_enum ConfigureNamesEnum[] = { {"huge_pages", PGC_POSTMASTER, RESOURCES_MEM, gettext_noop("Use of huge pages on Linux or Windows."), NULL }, &huge_pages, HUGE_PAGES_TRY, huge_pages_options, NULL, NULL, NULL }, + { + {"huge_pages_active", PGC_INTERNAL, PRESET_OPTIONS, + gettext_noop("Indicates whether huge pages are in use."), + NULL, + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED + }, + &huge_pages_active, + HUGE_PAGES_ACTIVE_UNKNOWN, huge_pages_active_options, + NULL, NULL, NULL + }, + { {"recovery_prefetch", PGC_SIGHUP, WAL_RECOVERY, gettext_noop("Prefetch referenced blocks during recovery."), gettext_noop("Look ahead in the WAL to find references to uncached data.") }, &recovery_prefetch, RECOVERY_PREFETCH_TRY, recovery_prefetch_options, check_recovery_prefetch, assign_recovery_prefetch, NULL }, { diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h index 4dd05f156d5..1699bf64238 100644 --- a/src/include/storage/pg_shmem.h +++ b/src/include/storage/pg_shmem.h @@ -46,22 +46,30 @@ extern PGDLLIMPORT int shared_memory_type; extern PGDLLIMPORT int huge_pages; extern PGDLLIMPORT int huge_page_size; /* Possible values for huge_pages */ typedef enum { HUGE_PAGES_OFF, HUGE_PAGES_ON, HUGE_PAGES_TRY } HugePagesType; +/* Possible values for huge_pages_active */ +typedef enum +{ + HUGE_PAGES_ACTIVE_UNKNOWN, + HUGE_PAGES_ACTIVE_FALSE, + HUGE_PAGES_ACTIVE_TRUE, +} HugePagesActiveType; + /* Possible values for shared_memory_type */ typedef enum { SHMEM_TYPE_WINDOWS, SHMEM_TYPE_SYSV, SHMEM_TYPE_MMAP } PGShmemType; #ifndef WIN32 extern PGDLLIMPORT unsigned long UsedShmemSegID; #else -- 2.34.1