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 1pPthb-0008B1-Jt for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Feb 2023 23:18:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pPtha-0002d7-1O for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Feb 2023 23:18:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPthZ-0002cw-Dh for pgsql-hackers@lists.postgresql.org; Wed, 08 Feb 2023 23:18:09 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pPthV-0003Fz-Sr for pgsql-hackers@postgresql.org; Wed, 08 Feb 2023 23:18:08 +0000 Received: by mail-il1-x12f.google.com with SMTP id v15so164410ilc.10 for ; Wed, 08 Feb 2023 15:18:05 -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=LinLaFKdh4dFvczMwlvxwOgjwvgTQDnwwMgJjyaUP5w=; b=soKVrIiEgRUThQAOZ1nnfdRgRbGrtNH5RW9dip8rLFDwsNmBrPeuweu3qOSyms9E62 6DG+uXMckJ8avj6Eyr4po5g5s26jXM7WUf6A2IPH375JJ203OfyGvf5v7ko2xXqctnl1 46WNHD5rUU5jy/qHx2VqjLC4mqN65Dnz3qoCZqOEV5pSdzpHGz2VdrOO5nEG8c6Apvg1 XU31VNg2fsdemXApkf+ydIdOfZDWB23cpQzQaPKnS605PzEFRU89jSPpXSktBkp+1FsR mKH3Qvz2gHn2Ch4NlWcys5yR8li0YVaXjT8AJDoVeDpIMJD86eN9GQLKqTLnc2Ysu8Nu B2yw== 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=LinLaFKdh4dFvczMwlvxwOgjwvgTQDnwwMgJjyaUP5w=; b=owDZ+WmRidHwLJMViAmNp6PMStASS4ViuAdRSDoRddpvOZy0slIibbnX6rH7R08Ar9 kVW6KFUohQ90p1xOBzTbODrR8i/GCS2PcBi3ZotAblB2NrCIUxSnZdnTim3nRa1x2bB4 R30F5TPmfk0YPloXAd3BiU/AXvBDs78NVUln/QZlc9XiQ6yc4yzZIJ5KYkBoUtZm8i7L 1ih8s2Unxd0ubaHEuCWKtFhIs2ZvmHmy9m23Kacb8ujSzSONpNv8++341x0nardxBvE+ jmt2wnuji8u7ez2kJrXkpKQjIKaIw3RyWEu3nfQO79Y5L0GQZNedy4HkCbNCWmLAsCLP baPg== X-Gm-Message-State: AO0yUKUTHWJhvjDf2xxu9QBTrfrS+s1evzwY9s2OQHSndRbjcZkju1ic e1ld/B7vUpHBBRZz9ts8E9Uomw== X-Google-Smtp-Source: AK7set9niXKtBcsWbrLrZYZ8899q63HX8qOmLJkz92Rm+YjTlMTknTEQN2BL8txEQthMIH/KRn1c1A== X-Received: by 2002:a05:6e02:18cd:b0:30c:1b0:fcf6 with SMTP id s13-20020a056e0218cd00b0030c01b0fcf6mr3516767ilu.7.1675898285203; Wed, 08 Feb 2023 15:18:05 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f13-20020a056e020c6d00b0031107762217sm3348154ilj.3.2023.02.08.15.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 15:18:04 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 8DC268009D6; Wed, 8 Feb 2023 17:18:03 -0600 (CST) Date: Wed, 8 Feb 2023 17:18:03 -0600 From: Justin Pryzby To: Alvaro Herrera Cc: Andres Freund , 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, Nathan Bossart Subject: Re: Improve logging when using Huge Pages Message-ID: <20230208231803.GP1653@telsasoft.com> References: <20230125013728.GK13860@telsasoft.com> <20230202155337.gwsjcszhxhdgqmhs@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LQAwcd5tHl0Qlnzi" Content-Disposition: inline In-Reply-To: <20230202155337.gwsjcszhxhdgqmhs@alvherre.pgsql> 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 --LQAwcd5tHl0Qlnzi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Feb 02, 2023 at 04:53:37PM +0100, Alvaro Herrera wrote: > On 2023-Jan-24, Justin Pryzby wrote: > > On Mon, Jan 23, 2023 at 05:33:35PM -0800, Andres Freund wrote: > > > I'm ok with this being a GUC, it doesn't feel elegant, but I suspect there's > > > no realistic elegant answer. > > > 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. > > Maybe I misread the code (actually I only read the patch), but -- does > it set active=true when huge_pages=on? I think the code only works when > huge_pages=try. That might be pretty confusing; I think it should say > "on" in both cases. Yes - I realized that too. There's no reason this GUC should be inaccurate when huge_pages=on. (I had hoped there would be a conflict needing resolution before anyone else noticed.) I don't think it makes sense to run postgres -C huge_pages_active, however, so I see no issue that that would always returns "false". If need be, maybe the documentation could say "indicates whether huge pages are active for the running server". Does anybody else want to vote for a function rather than a RUNTIME_COMPUTED GUC ? -- Justin --LQAwcd5tHl0Qlnzi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-add-GUC-huge_pages_active.patch" From 217b01b7eddabb5d863d50b1d4ca8e1019d9413c Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Mon, 23 Jan 2023 18:33:51 -0600 Subject: [PATCH v2] 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 | 5 ++++- src/backend/port/win32_shmem.c | 5 ++++- src/backend/utils/misc/guc_tables.c | 13 +++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index d190be1925d..fcef4e3ce8e 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..9b9b25d53ba 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -621,7 +621,10 @@ 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) + if (ptr != MAP_FAILED) + SetConfigOption("huge_pages_active", "on", + PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + else if (huge_pages == HUGE_PAGES_TRY) elog(DEBUG1, "mmap(%zu) with MAP_HUGETLB failed, huge pages disabled: %m", allocsize); } diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 62e08074770..73472a18f25 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -290,7 +290,10 @@ retry: size_low, /* Size Lower 32 bits */ szShareMem); - if (!hmap) + if (hmap) + SetConfigOption("huge_pages_active", "on", + PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + else { if (GetLastError() == ERROR_NO_SYSTEM_RESOURCES && huge_pages == HUGE_PAGES_TRY && diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index b21698934c8..1e8e67a4c54 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 --LQAwcd5tHl0Qlnzi--