Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita14354c

Browse files
committed
Add GUC parameter "huge_pages_status"
This is useful to show the allocation state of huge pages when settingup a server with "huge_pages = try", where allocating huge pages wouldbe attempted but the server would continue its startup sequence even ifthe allocation fails. The effective status of huge pages is not easilyvisible without OS-level tools (or for instance, a lookup at/proc/N/smaps), and the environments where Postgres runs may notauthorize that. Like the other GUCs related to huge pages, this worksfor Linux and Windows.This GUC can report as values:- "on", if huge pages were allocated.- "off", if huge pages were not allocated.- "unknown", a special state that could only be seen when using forexample postgres -C because it is only possible to know if the sharedmemory allocation worked after we can check for the GUC values, even ifchecking a runtime-computed GUC. This value should never be seen whenquerying for the GUC on a running server. An assertion is added tocheck that.The discussion has also turned around having a new function to grab thisstatus, but this would have required more tricks for -DEXEC_BACKEND,something that GUCs already handle.Noriyoshi Shinoda has initiated the thread that has led to the result ofthis commit.Author: Justin PryzbyReviewed-by: Nathan Bossart, Kyotaro Horiguchi, Michael PaquierDiscussion:https://postgr.es/m/TU4PR8401MB1152EBB0D271F827E2E37A01EECC9@TU4PR8401MB1152.NAMPRD84.PROD.OUTLOOK.COM
1 parentcf05113 commita14354c

File tree

8 files changed

+80
-3
lines changed

8 files changed

+80
-3
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,9 @@ include_dir 'conf.d'
17271727
server will try to request huge pages, but fall back to the default if
17281728
that fails. With <literal>on</literal>, failure to request huge pages
17291729
will prevent the server from starting up. With <literal>off</literal>,
1730-
huge pages will not be requested.
1730+
huge pages will not be requested. The actual state of huge pages is
1731+
indicated by the server variable
1732+
<xref linkend="guc-huge-pages-status"/>.
17311733
</para>
17321734

17331735
<para>
@@ -10738,6 +10740,25 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
1073810740
</listitem>
1073910741
</varlistentry>
1074010742

10743+
<varlistentry id="guc-huge-pages-status" xreflabel="huge_pages_status">
10744+
<term><varname>huge_pages_status</varname> (<type>enum</type>)
10745+
<indexterm>
10746+
<primary><varname>huge_pages_status</varname> configuration parameter</primary>
10747+
</indexterm>
10748+
</term>
10749+
<listitem>
10750+
<para>
10751+
Reports the state of huge pages in the current instance:
10752+
<literal>on</literal>, <literal>off</literal>, or
10753+
<literal>unknown</literal> (if displayed with
10754+
<literal>postgres -C</literal>).
10755+
This parameter is useful to determine whether allocation of huge pages
10756+
was successful under <literal>huge_pages=try</literal>.
10757+
See <xref linkend="guc-huge-pages"/> for more information.
10758+
</para>
10759+
</listitem>
10760+
</varlistentry>
10761+
1074110762
<varlistentry id="guc-integer-datetimes" xreflabel="integer_datetimes">
1074210763
<term><varname>integer_datetimes</varname> (<type>boolean</type>)
1074310764
<indexterm>

‎src/backend/port/sysv_shmem.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,14 @@ CreateAnonymousSegment(Size *size)
627627
}
628628
#endif
629629

630+
/*
631+
* Report whether huge pages are in use. This needs to be tracked before
632+
* the second mmap() call if attempting to use huge pages failed
633+
* previously.
634+
*/
635+
SetConfigOption("huge_pages_status", (ptr==MAP_FAILED) ?"off" :"on",
636+
PGC_INTERNAL,PGC_S_DYNAMIC_DEFAULT);
637+
630638
if (ptr==MAP_FAILED&&huge_pages!=HUGE_PAGES_ON)
631639
{
632640
/*
@@ -737,8 +745,14 @@ PGSharedMemoryCreate(Size size,
737745
sysvsize=sizeof(PGShmemHeader);
738746
}
739747
else
748+
{
740749
sysvsize=size;
741750

751+
/* huge pages are only available with mmap */
752+
SetConfigOption("huge_pages_status","off",
753+
PGC_INTERNAL,PGC_S_DYNAMIC_DEFAULT);
754+
}
755+
742756
/*
743757
* Loop till we find a free IPC key. Trust CreateDataDirLockFile() to
744758
* ensure no more than one postmaster per data directory can enter this

‎src/backend/port/win32_shmem.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ PGSharedMemoryCreate(Size size,
401401
on_shmem_exit(pgwin32_SharedMemoryDelete,PointerGetDatum(hmap2));
402402

403403
*shim=hdr;
404+
405+
/* Report whether huge pages are in use */
406+
SetConfigOption("huge_pages_status", (flProtect&SEC_LARGE_PAGES) ?
407+
"on" :"off",PGC_INTERNAL,PGC_S_DYNAMIC_DEFAULT);
408+
404409
returnhdr;
405410
}
406411

‎src/backend/storage/ipc/ipci.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ CreateSharedMemoryAndSemaphores(void)
190190
*/
191191
seghdr=PGSharedMemoryCreate(size,&shim);
192192

193+
/*
194+
* Make sure that huge pages are never reported as "unknown" while the
195+
* server is running.
196+
*/
197+
Assert(strcmp("unknown",
198+
GetConfigOption("huge_pages_status", false, false))!=0);
199+
193200
InitShmemAccess(seghdr);
194201

195202
/*

‎src/backend/utils/misc/guc_tables.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ static const struct config_enum_entry huge_pages_options[] = {
365365
{NULL,0, false}
366366
};
367367

368+
staticconststructconfig_enum_entryhuge_pages_status_options[]= {
369+
{"off",HUGE_PAGES_OFF, false},
370+
{"on",HUGE_PAGES_ON, false},
371+
{"unknown",HUGE_PAGES_UNKNOWN, false},
372+
{NULL,0, false}
373+
};
374+
368375
staticconststructconfig_enum_entryrecovery_prefetch_options[]= {
369376
{"off",RECOVERY_PREFETCH_OFF, false},
370377
{"on",RECOVERY_PREFETCH_ON, false},
@@ -550,6 +557,7 @@ intssl_renegotiation_limit;
550557
*/
551558
inthuge_pages=HUGE_PAGES_TRY;
552559
inthuge_page_size;
560+
inthuge_pages_status=HUGE_PAGES_UNKNOWN;
553561

554562
/*
555563
* These variables are all dummies that don't do anything, except in some
@@ -4876,6 +4884,17 @@ struct config_enum ConfigureNamesEnum[] =
48764884
NULL,NULL,NULL
48774885
},
48784886

4887+
{
4888+
{"huge_pages_status",PGC_INTERNAL,PRESET_OPTIONS,
4889+
gettext_noop("Indicates the status of huge pages."),
4890+
NULL,
4891+
GUC_NOT_IN_SAMPLE |GUC_DISALLOW_IN_FILE
4892+
},
4893+
&huge_pages_status,
4894+
HUGE_PAGES_UNKNOWN,huge_pages_status_options,
4895+
NULL,NULL,NULL
4896+
},
4897+
48794898
{
48804899
{"recovery_prefetch",PGC_SIGHUP,WAL_RECOVERY,
48814900
gettext_noop("Prefetch referenced blocks during recovery."),

‎src/include/storage/pg_shmem.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ extern PGDLLIMPORT int shared_memory_type;
4646
externPGDLLIMPORTinthuge_pages;
4747
externPGDLLIMPORTinthuge_page_size;
4848

49-
/* Possible values for huge_pages */
49+
/* Possible values for huge_pagesand huge_pages_status*/
5050
typedefenum
5151
{
5252
HUGE_PAGES_OFF,
5353
HUGE_PAGES_ON,
54-
HUGE_PAGES_TRY
54+
HUGE_PAGES_TRY,/* only for huge_pages */
55+
HUGE_PAGES_UNKNOWN/* only for huge_pages_status */
5556
}HugePagesType;
5657

5758
/* Possible values for shared_memory_type */

‎src/test/authentication/t/003_peer.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ sub test_role
100100
$node->safe_psql('postgres',
101101
q(select (string_to_array(SYSTEM_USER, ':'))[2]));
102102

103+
# While on it, check the status of huge pages, that can be either on
104+
# or off, but never unknown.
105+
my$huge_pages_status =
106+
$node->safe_psql('postgres',q(SHOW huge_pages_status;));
107+
isnt($huge_pages_status,'unknown',"check huge_pages_status");
108+
103109
# Tests without the user name map.
104110
# Failure as connection is attempted with a database role not mapping
105111
# to an authorized system user.

‎src/test/authentication/t/005_sspi.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
$node->append_conf('postgresql.conf',"log_connections = on\n");
2222
$node->start;
2323

24+
my$huge_pages_status =
25+
$node->safe_psql('postgres',q(SHOW huge_pages_status;));
26+
isnt($huge_pages_status,'unknown',"check huge_pages_status");
27+
2428
# SSPI is set up by default. Make sure it interacts correctly with
2529
# require_auth.
2630
$node->connect_ok("require_auth=sspi",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp