Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMhlH-0002ZK-Uv for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2023 03:56:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pMhlG-00038i-SH for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2023 03:56:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMhlG-00038Y-Dq for pgsql-hackers@lists.postgresql.org; Tue, 31 Jan 2023 03:56:46 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pMhlD-0001pv-Dm for pgsql-hackers@postgresql.org; Tue, 31 Jan 2023 03:56:45 +0000 Received: by mail-il1-x132.google.com with SMTP id m15so1408150ilh.9 for ; Mon, 30 Jan 2023 19:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=bClHRtLEgarMyy5iATP7NJfm690dJcS8Bqrrm2Cj4Do=; b=NPHgYcBroaROD4hDLaEvCxvPoarkA4ZlcNz4LtGPDfyyZzQgU+goYfJS6d8POd2vTW M7TxFG7s1kGXtPq8N7clTu8KObAZxBemRm+VaJM3tr/4ceWUzakSCengrfpMUYON/ZI0 pn9tOAJ2jKBK3fFrJs0egy3f3OBdehHkHO5ZrmhYHGUJn+gyW+I6LLsVT0L0ZPXgUwAB ot1VV+CUAnRdtFMXSKcvzkar4yOwunQsBu5EndRWDTisBmnfwjP1bBon+Y0JKlxYbRTi wZVVfE69G6l9AGPm7+IDHm3q5happe7D24uRZzO+9LlpMGImBIBuu4Zb3Sqt/z2Q1VTl 5aXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bClHRtLEgarMyy5iATP7NJfm690dJcS8Bqrrm2Cj4Do=; b=DoTRF91kAUoIMJirjvxsTMD9uSXlMtUMOPKAfQeFDsi8eNU8fpjECt4R4bYD23NROC IeppQbEmF8yWvPa6OTF4EXIJSvP7xpTxSAogG2zN+Q3/0ipyzK9DSzzR1qFVx7Vu6v+j VJ/Jrzx+kelgI9dw+noJqmjQ9bZ3LCM3Bi7uXfApssMukkQbqOMIUb9mIPjJB0PsJQmM 6XAwOMseDCSPFNjUN4AiPUaQlv3eukan1/7MXKtscAop2Wuh/cabnfusKh9V/CV132OR SDZK5wq5FtGUyl+Wvv6XvvythVuQ/caDrVAj/fakBakhNACcJQ0cIZLuUOAnTIoXUh7T AJXg== X-Gm-Message-State: AO0yUKX4FmL2UhcxWPAMwUzWI/C7LuNUfMZCv1TKXauJ5E22RCx7oDjJ EMRxtby1ANd8pSL7tcWQTVYl0w== X-Google-Smtp-Source: AK7set8N8fJQ8yR1fzzi7rOffwYiJkxnD7K2j8BLR3Be+shB95U4IYj4AGL6mXFsegDPeUmyUM75aA== X-Received: by 2002:a05:6e02:1d0e:b0:310:fc22:725e with SMTP id i14-20020a056e021d0e00b00310fc22725emr3810872ila.27.1675137401372; Mon, 30 Jan 2023 19:56:41 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m17-20020a02cdd1000000b003a96f9940ddsm4628760jap.102.2023.01.30.19.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 19:56:40 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 5BF72800C4C; Mon, 30 Jan 2023 21:56:39 -0600 (CST) Date: Mon, 30 Jan 2023 21:56:39 -0600 From: Justin Pryzby To: Andres Freund Cc: Michael Paquier , Kyotaro Horiguchi , thomas.munro@gmail.com, tgl@sss.pgh.pa.us, john.naylor@enterprisedb.com, noriyoshi.shinoda@hpe.com, jchampion@timescale.com, sawada.mshk@gmail.com, masao.fujii@oss.nttdata.com, pgsql-hackers@postgresql.org, rjuju123@gmail.com Subject: Re: Improve logging when using Huge Pages Message-ID: <20230131035639.GJ22427@telsasoft.com> References: <20221107151458.6puzamerxti2y5in@awork3.anarazel.de> <3239882.1667836576@sss.pgh.pa.us> <20221109.114757.661491395677294771.horikyota.ntt@gmail.com> <20230124012100.GB13860@telsasoft.com> <20230124013335.7u75j75ze5o7uh2l@awork3.anarazel.de> <20230125013728.GK13860@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="kfjH4zxOES6UT95V" Content-Disposition: inline In-Reply-To: <20230125013728.GK13860@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --kfjH4zxOES6UT95V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jan 24, 2023 at 07:37:29PM -0600, Justin Pryzby wrote: > BTW, I didn't realize it when I made the suggestion, nor when I wrote > the patch, but a GUC was implemented in the v2 patch. > https://www.postgresql.org/message-id/TU4PR8401MB1152CB4FEB99658BC6B35543EECF9%40TU4PR8401MB1152.NAMPRD84.PROD.OUTLOOK.COM > Whether it's a GUC or a function, I propose to name it hugepages_active. > If there's no objections, I'll add to the CF. As such, I re-opened the previous CF. https://commitfest.postgresql.org/38/3310/ --kfjH4zxOES6UT95V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-add-GUC-huge_pages_active.patch" From f23e27ed112aff2f177082a105d79aaa09b2ce3b Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Mon, 23 Jan 2023 18:33:51 -0600 Subject: [PATCH] add GUC: huge_pages_active This is useful to show the current state of huge pages when huge_pages=try. The effective status is not otherwise visible without OS level tools like gdb or /proc/N/smaps. --- doc/src/sgml/config.sgml | 17 ++++++++++++++++- src/backend/port/sysv_shmem.c | 12 +++++++++--- src/backend/port/win32_shmem.c | 4 ++++ src/backend/utils/misc/guc_tables.c | 13 +++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index f985afc009d..e5ef58d441d 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -1708,7 +1708,8 @@ include_dir 'conf.d' server will try to request huge pages, but fall back to the default if that fails. With on, failure to request huge pages will prevent the server from starting up. With off, - huge pages will not be requested. + huge pages will not be requested. The actual state of huge pages is + indicated by the server variable . @@ -10687,6 +10688,20 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' + + huge_pages_active (boolean) + + huge_pages_active configuration parameter + + + + + Reports whether huge pages are in use by the current process. + See for more information. + + + + integer_datetimes (boolean) diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index eaba244bc9c..62029e7fe0e 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -621,9 +621,15 @@ CreateAnonymousSegment(Size *size) ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE, PG_MMAP_FLAGS | mmap_flags, -1, 0); mmap_errno = errno; - if (huge_pages == HUGE_PAGES_TRY && ptr == MAP_FAILED) - elog(DEBUG1, "mmap(%zu) with MAP_HUGETLB failed, huge pages disabled: %m", - allocsize); + if (huge_pages == HUGE_PAGES_TRY) + { + if (ptr == MAP_FAILED) + elog(DEBUG1, "mmap(%zu) with MAP_HUGETLB failed, huge pages disabled: %m", + allocsize); + else + SetConfigOption("huge_pages_active", "on", + PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + } } #endif diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 62e08074770..352e68b7af2 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -314,6 +314,10 @@ retry: errdetail("Failed system call was CreateFileMapping(size=%zu, name=%s).", size, szShareMem))); } + else if (huge_pages == HUGE_PAGES_TRY) + SetConfigOption("huge_pages_active", "on", + PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + /* * If the segment already existed, CreateFileMapping() will return a diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 4454d57322a..649aa473020 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -571,6 +571,7 @@ 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 huge_pages_active = false; /* dynamically set */ static bool integer_datetimes; #ifdef USE_ASSERT_CHECKING @@ -1013,6 +1014,18 @@ struct config_bool ConfigureNamesBool[] = true, 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, + false, + NULL, NULL, NULL + }, + { /* Not for general use --- used by SET SESSION AUTHORIZATION */ {"is_superuser", PGC_INTERNAL, UNGROUPED, -- 2.25.1 --kfjH4zxOES6UT95V--