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 1pK7zq-0008Ea-O9 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 01:21:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pK7zp-0000Px-LY for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 01:21:09 +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 1pK7zp-0000Pi-4c for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 01:21:09 +0000 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pK7zk-0008RA-Ef for pgsql-hackers@postgresql.org; Tue, 24 Jan 2023 01:21:08 +0000 Received: by mail-il1-x12a.google.com with SMTP id r19so6481397ilt.7 for ; Mon, 23 Jan 2023 17:21:04 -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=n6IlHZW09y2jcU8g+BHcb+C3G4b7lO2u5Bb3fpbtoj8=; b=pzldrcSPkPQAegzo1/lcp2+WIsP+U6z3sE8n2wgzNKqVw2iVY9LJ8VEPgBKEScHoio z+jKbh5xPpC7/Vwyf2VBKOmUKn9BxTHmuUQtsvYSONxK/NezwjoJbTo5u0ZBLCltcIJF E903q8FMZTzr5cFTs03DJFmR6t7HJCS0QjGZ5OPIYVa+dC4UU/V5VYgiFN2MoFlxT8qS +aZ+yqfGW4727m2qzPyufYwZq7fegBFTc0WPNFWScdrHJvonYLq5fxusBn3NIKBxGOzj QwrJYKM7GU3CCxm4U/ISxng19Phs1fCImYSlIY7vT5Pc1vxvUkvCJqqaXttp7UEN3WM4 5Bww== 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=n6IlHZW09y2jcU8g+BHcb+C3G4b7lO2u5Bb3fpbtoj8=; b=b0rxDj0qagLMO68sI2ojUPRg+btGe6RF267YkNem+lTCCzmEklfXhQdHqH1jNZhnpw 2D0KLXpesRwSGQ/8ZdKQQDC0xvaQ7sTHnJyCH7M43M02MdpoeuepV4mCeqi8BL5xdGP5 HCjCfwByARhhAj5lrDAtFOJ7El8gtS0IsF8czwkwtwJOI0w5ql/5WMGz4IDzPV6E0bUu lWyC0hlvvX+CiW0sN960E4x0tSaOIKTMH6z6w9AnN9mOZ8vVZPzs/FMAxtjkpkJTDyB1 Q9PmTqnggHpgwz/qjpphH5csF6BcpGmhl3Xa8FV4an5682rkUQCWaWdhndMliy8I9yzc QS3g== X-Gm-Message-State: AFqh2kolNIqH/h8hRYPYENhJ5KHeNcAhdbD1z+UYW9w5HTxkfO1rOdY5 wRYvnZAVpUdhVdpV2eC/M7JaHw== X-Google-Smtp-Source: AMrXdXvOxXq6XDBHCDqqp8bvbYY2KwKhUuIhT3TJbheycuT1v4h9vR/SDmB8kXDYFJPXgIMkm4FAcw== X-Received: by 2002:a05:6e02:220a:b0:30b:a918:386e with SMTP id j10-20020a056e02220a00b0030ba918386emr22408655ilf.6.1674523263656; Mon, 23 Jan 2023 17:21:03 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l13-20020a02664d000000b0039deb26853csm249338jaf.10.2023.01.23.17.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 17:21:02 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 028A5800983; Mon, 23 Jan 2023 19:21:00 -0600 (CST) Date: Mon, 23 Jan 2023 19:21:00 -0600 From: Justin Pryzby To: Michael Paquier Cc: Kyotaro Horiguchi , thomas.munro@gmail.com, tgl@sss.pgh.pa.us, andres@anarazel.de, 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: <20230124012100.GB13860@telsasoft.com> References: <20221107151458.6puzamerxti2y5in@awork3.anarazel.de> <3239882.1667836576@sss.pgh.pa.us> <20221109.114757.661491395677294771.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline In-Reply-To: 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 --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Nov 09, 2022 at 02:04:00PM +0900, Michael Paquier wrote: > On Wed, Nov 09, 2022 at 11:47:57AM +0900, Kyotaro Horiguchi wrote: > > Honestly I don't come up with other users of the new > > log-level. Another possible issue is it might be a bit hard for people > > to connect that level to huge_pages=try, whereas I think we shouldn't > > put a description about the concrete impact range of that log-level. > > > > I came up with an alternative idea that add a new huge_pages value > > try_report or try_verbose, which tell postgresql to *always* report > > the result of huge_pages = try. > > Here is an extra idea for the bucket of ideas: switch the user-visible > value of huge_pages to 'on' when we are at "try" but success in using > huge pages, and switch the visible value to "off". The idea of Justin > in [1] to use an internal runtime-computed GUC sounds sensible, as well > (say a boolean effective_huge_pages?). > > [1]: https://www.postgresql.org/message-id/20221106130426.GG16921@telsasoft.com > -- > Michael Michael seemed to support this idea and nobody verbalized hatred of it, so I implemented it. In v15, we have shared_memory_size_in_huge_pages, so this adds effective_huge_pages. Feel free to suggest a better name. -- Justin --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-add-GUC-effective_huge_pages.patch" From 2bb0c48dfefff78325b1b9d31a3e54e982d44e4e Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Mon, 23 Jan 2023 18:33:51 -0600 Subject: [PATCH] add GUC: effective_huge_pages This is useful to show the current state of huge pages when huge_pages=try. --- 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 | 12 ++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index f985afc009d..383139d5266 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' + + effective_huge_pages (boolean) + + effective_huge_pages 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..1e6adc97533 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("effective_huge_pages", "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..8c5ffd7af4c 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("effective_huge_pages", "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..88272765479 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 effective_huge_pages; static bool integer_datetimes; #ifdef USE_ASSERT_CHECKING @@ -1972,6 +1973,17 @@ struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"effective_huge_pages", 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 + }, + &effective_huge_pages, + false, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL -- 2.25.1 --UlVJffcvxoiEqYs2--