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 1pfWa3-00048B-Sk for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Mar 2023 01:51:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pfWa2-0007qO-Or for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Mar 2023 01:50:58 +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 1pfWa2-0007q9-6W for pgsql-hackers@lists.postgresql.org; Fri, 24 Mar 2023 01:50:58 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pfWZz-0005ra-1Q for pgsql-hackers@postgresql.org; Fri, 24 Mar 2023 01:50:57 +0000 Received: by mail-il1-x12b.google.com with SMTP id r4so259513ilt.8 for ; Thu, 23 Mar 2023 18:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; t=1679622654; h=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=4cCh5/iVkxnlGdEWAQuj1TwAvvTaqdhplFYg5fKaIFQ=; b=KcE0Mnxs+N5DmjNNcrUvXwprpB55jh6sYa60WH3FfkZswea/iDdKRgS15wxL4RD/8X TgO5pdVCGJj25HW3TJ7D3/WE/e9fI8QBUwgb+GfNahh1AQwIGgW2zVSRbk1I0tIBFWND uZXpo7oGTDIvxrUio69o+0DibQHDmvieFLPZR52I5Ixg9W1wm3VUIv+F9c0MtJodQEey 29+ZG0lNTic6m1sqIADMTBfXBrwYE+QeLD3BpmBXRCVdPvi99JOoQ6I9cJNgkMHR+p4j S0CqflEMLi7mf8mjB5an7r7Vzrfo0qzPuHYxC3/TPO0p+InZvFaEXzTUnX1o3rF022EB uzTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679622654; h=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=4cCh5/iVkxnlGdEWAQuj1TwAvvTaqdhplFYg5fKaIFQ=; b=rDU2fLaOeg62SX6Mpq0L5Q0PO8p4tap/SgEahmggV4tqVZ+SPlLD9VAiDHKMzo9wJr +zCsLa4YEKvF5GzgPcBm/8dC1/XhTb3gOUTsLNy87cwkDyjUObMNQHxtLArXpFgClut9 hq8wst1wyeiunWGdnciQelRJf+V6XhFtRYNDBNXue0c1gRz6+qrYTsdPjwrqROnEPP5q 1pRrDO3N8gKHiDT+li3qwKxh/W5IR8QJaj/oNCejs1rP1btPzt0fiA5nEYIH3ncNKWMd +Cr8/pnPrI/y+0HA/faTRhM4df9HxGSRWZlnPrfUZg/kgdiLnTDbm+gtIGsZ5cBJdAoH FlpQ== X-Gm-Message-State: AAQBX9f9wSSXaR3h30tomSOZ+6Xw0EhWSktHLeKBKjcfpI6o9bQxwP6K jn0SMetCN0M+KQVjKxdFQplQhg== X-Google-Smtp-Source: AKy350ZtrPOT/pFaZ0cnY/ZmG42diFkbfGGFkjivhcj8EV2YFVLZiavQV1cB74U1t3uplh/XwtMkYg== X-Received: by 2002:a05:6e02:686:b0:325:b505:f8f2 with SMTP id o6-20020a056e02068600b00325b505f8f2mr990250ils.30.1679622653825; Thu, 23 Mar 2023 18:50:53 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e41-20020a02862c000000b0039df8e7af39sm6579073jai.41.2023.03.23.18.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 18:50:52 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 17027800DAB; Thu, 23 Mar 2023 20:50:51 -0500 (CDT) Date: Thu, 23 Mar 2023 20:50:50 -0500 From: Justin Pryzby To: Michael Paquier Cc: Kyotaro Horiguchi , sfrost@snowman.net, alvherre@alvh.no-ip.org, andres@anarazel.de, nathandbossart@gmail.com, jchampion@timescale.com, john.naylor@enterprisedb.com, masao.fujii@oss.nttdata.com, noriyoshi.shinoda@hpe.com, pgsql-hackers@postgresql.org, rjuju123@gmail.com, sawada.mshk@gmail.com, tgl@sss.pgh.pa.us, thomas.munro@gmail.com Subject: Re: Improve logging when using Huge Pages Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="HsPhGMMkM6t+clob" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --HsPhGMMkM6t+clob Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Mar 23, 2023 at 05:25:46PM +0900, Kyotaro Horiguchi wrote: > Wouldn't storing the value in the shared memory itself work? Though, > that space does become almost dead for the server's lifetime... I'm sure it's possible, but it's also not worth writing a special implementation just to handle huge_pages_active, which is better written in 30 lines than in 300 lines. If we needed to avoid using a GUC, maybe it'd work to add huge_pages_active to PGShmemHeader. But "avoid using gucs at all costs" isn't the goal, and using a GUC parallels all the similar, and related things without needing to allocate extra bits of shared_memory. On Thu, Mar 23, 2023 at 07:23:28AM +0900, Michael Paquier wrote: > On Wed, Mar 22, 2023 at 05:18:28PM -0500, Justin Pryzby wrote: > > Wow, good point. I think to make it work we'd need put > > huge_pages_active into BackendParameters and handle it in > > save_backend_variables(). If so, that'd be strong argument for using a > > GUC, which already has all the necessary infrastructure for exposing the > > server's state. > > I am afraid so, duplicating an existing infrastructure for a need like > the one of this thread is not really appealing. This goes back to using a GUC, and: - removes GUC_RUNTIME_COMPUTED, since that causes a useless error when using -C if the server is running, rather than successfully printing "unknown". - I also renamed it from huge_pages_active = {true,false,unknown} to huge_pages_STATUS = {on,off,unknown}. This parallels huge_pages, which is documented to accept values on/off/try. Also, true/false isn't how bools are displayed. - I realized that the rename suggested implementing it as an enum GUC, and re-using the existing HUGE_PAGES_{ON,OFF} values (and adding an "UNKNOWN"). Maybe this also avoids Stephen's earlier objection to using a string ? I mis-used cirrusci to check that the GUC does work correctly under windows. If there's continuing aversions to using a GUC, please say so, and try to suggest an alternate implementation you think would be justified. It'd need to work under windows with EXEC_BACKEND. -- Justin --HsPhGMMkM6t+clob Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v6-0001-add-GUC-huge_pages_active.patch" From 951d481b74ac978482b9d5794b437f741518f3a9 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Mon, 23 Jan 2023 18:33:51 -0600 Subject: [PATCH v6] 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. https://www.postgresql.org/message-id/flat/TU4PR8401MB1152EBB0D271F827E2E37A01EECC9@TU4PR8401MB1152.NAMPRD84.PROD.OUTLOOK.COM --- doc/src/sgml/config.sgml | 17 ++++++++++++++++- src/backend/port/sysv_shmem.c | 3 +++ src/backend/port/win32_shmem.c | 4 ++++ src/backend/utils/misc/guc_tables.c | 20 ++++++++++++++++++++ src/include/storage/pg_shmem.h | 5 +++-- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 510ff88fc5e..88998238645 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 . @@ -10660,6 +10661,20 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' + + huge_pages_status (enum) + + huge_pages_status configuration parameter + + + + + Reports the state of huge pages in the current instance. + 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..b6104c6ce60 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -627,6 +627,9 @@ CreateAnonymousSegment(Size *size) } #endif + SetConfigOption("huge_pages_status", ptr == MAP_FAILED ? "off" : "on", + PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + if (ptr == MAP_FAILED && huge_pages != HUGE_PAGES_ON) { /* diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 62e08074770..199f2e23a13 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -327,6 +327,10 @@ retry: Sleep(1000); continue; } + + SetConfigOption("huge_pages_status", (flProtect & SEC_LARGE_PAGES) ? + "on" : "off", PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); + break; } diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 8696d965dee..785bee948e9 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -348,6 +348,13 @@ static const struct config_enum_entry huge_pages_options[] = { {NULL, 0, false} }; +static const struct config_enum_entry huge_pages_status_options[] = { + {"off", HUGE_PAGES_OFF, false}, + {"on", HUGE_PAGES_ON, false}, + {"unknown", HUGE_PAGES_UNKNOWN, false}, + {NULL, 0, false} +}; + static const struct config_enum_entry recovery_prefetch_options[] = { {"off", RECOVERY_PREFETCH_OFF, false}, {"on", RECOVERY_PREFETCH_ON, false}, @@ -536,6 +543,8 @@ int ssl_renegotiation_limit; int huge_pages = HUGE_PAGES_TRY; int huge_page_size; +int huge_pages_status = HUGE_PAGES_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 @@ -4833,6 +4842,17 @@ struct config_enum ConfigureNamesEnum[] = NULL, NULL, NULL }, + { + {"huge_pages_status", PGC_INTERNAL, PRESET_OPTIONS, + gettext_noop("Indicates the status of huge pages."), + NULL, + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + }, + &huge_pages_status, + HUGE_PAGES_UNKNOWN, huge_pages_status_options, + NULL, NULL, NULL + }, + { {"recovery_prefetch", PGC_SIGHUP, WAL_RECOVERY, gettext_noop("Prefetch referenced blocks during recovery."), diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h index 4dd05f156d5..bfda42b0b26 100644 --- a/src/include/storage/pg_shmem.h +++ b/src/include/storage/pg_shmem.h @@ -46,12 +46,13 @@ extern PGDLLIMPORT int shared_memory_type; extern PGDLLIMPORT int huge_pages; extern PGDLLIMPORT int huge_page_size; -/* Possible values for huge_pages */ +/* Possible values for huge_pages/huge_pages_status */ typedef enum { HUGE_PAGES_OFF, HUGE_PAGES_ON, - HUGE_PAGES_TRY + HUGE_PAGES_TRY, /* only for huge_pages */ + HUGE_PAGES_UNKNOWN /* only for huge_pages_status */ } HugePagesType; /* Possible values for shared_memory_type */ -- 2.34.1 --HsPhGMMkM6t+clob--