Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f8ce16d

Browse files
committed
Rename huge_tlb_pages to huge_pages, and improve docs.
Christian Kruse
1 parent 9067310 commit f8ce16d

File tree

7 files changed

+92
-45
lines changed

7 files changed

+92
-45
lines changed

doc/src/sgml/config.sgml

+10-14
Original file line numberDiff line numberDiff line change
@@ -1166,35 +1166,31 @@ include 'filename'
11661166
</listitem>
11671167
</varlistentry>
11681168

1169-
<varlistentry id="guc-huge-tlb-pages" xreflabel="huge_tlb_pages">
1170-
<term><varname>huge_tlb_pages</varname> (<type>enum</type>)</term>
1169+
<varlistentry id="guc-huge-pages" xreflabel="huge_pages">
1170+
<term><varname>huge_pages</varname> (<type>enum</type>)</term>
11711171
<indexterm>
1172-
<primary><varname>huge_tlb_pages</> configuration parameter</primary>
1172+
<primary><varname>huge_pages</> configuration parameter</primary>
11731173
</indexterm>
11741174
<listitem>
11751175
<para>
1176-
Enables/disables the use of huge TLB pages. Valid values are
1176+
Enables/disables the use of huge memory pages. Valid values are
11771177
<literal>try</literal> (the default), <literal>on</literal>,
11781178
and <literal>off</literal>.
11791179
</para>
11801180

11811181
<para>
1182-
At present, this feature is supported only on Linux. The setting
1183-
is ignored on other systems.
1182+
At present, this feature is supported only on Linux. The setting is
1183+
ignored on other systems when set to <literal>try</literal>.
11841184
</para>
11851185

11861186
<para>
1187-
The use of huge TLB pages results in smaller page tables and
1188-
less CPU time spent on memory management, increasing performance. For
1189-
more details, see
1190-
<ulink url="https://wiki.debian.org/Hugepages">the Debian wiki</ulink>.
1191-
Remember that you will need at least shared_buffers / huge page size +
1192-
1 huge TLB pages. So for example for a system with 6GB shared buffers
1193-
and a hugepage size of 2kb of you will need at least 3156 huge pages.
1187+
The use of huge pages results in smaller page tables and less CPU time
1188+
spent on memory management, increasing performance. For more details,
1189+
see <xref linkend="linux-huge-pages">.
11941190
</para>
11951191

11961192
<para>
1197-
With <varname>huge_tlb_pages</varname> set to <literal>try</literal>,
1193+
With <varname>huge_pages</varname> set to <literal>try</literal>,
11981194
the server will try to use huge pages, but fall back to using
11991195
normal allocation if that fails. With <literal>on</literal>, failure
12001196
to use huge pages will prevent the server from starting up. With

doc/src/sgml/runtime.sgml

+51
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,57 @@ echo -1000 > /proc/self/oom_score_adj
13071307
</para>
13081308
</note>
13091309
</sect2>
1310+
1311+
<sect2 id="linux-huge-pages">
1312+
<title>Linux huge pages</title>
1313+
1314+
<para>
1315+
Using huge pages reduces overhead when using large contiguous chunks of
1316+
memory, like <productname>PostgreSQL</productname> does. To enable this
1317+
feature in <productname>PostgreSQL</productname> you need a kernel
1318+
with <varname>CONFIG_HUGETLBFS=y</varname> and
1319+
<varname>CONFIG_HUGETLB_PAGE=y</varname>. You also have to tune the system
1320+
setting <varname>vm.nr_hugepages</varname>. To estimate the number of
1321+
necessary huge pages start <productname>PostgreSQL</productname> without
1322+
huge pages enabled and check the <varname>VmPeak</varname> value from the
1323+
proc filesystem:
1324+
<programlisting>
1325+
$ <userinput>head -1 /path/to/data/directory/postmaster.pid</userinput>
1326+
4170
1327+
$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
1328+
VmPeak: 6490428 kB
1329+
</programlisting>
1330+
<literal>6490428</literal> / <literal>2048</literal>
1331+
(<varname>PAGE_SIZE</varname> is <literal>2MB</literal> in this case) are
1332+
roughly <literal>3169.154</literal> huge pages, so you will need at
1333+
least <literal>3170</literal> huge pages:
1334+
<programlisting>
1335+
$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
1336+
</programlisting>
1337+
Sometimes the kernel is not able to allocate the desired number of huge
1338+
pages, so it might be necessary to repeat that command or to reboot. Don't
1339+
forget to add an entry to <filename>/etc/sysctl.conf</filename> to persist
1340+
this setting through reboots.
1341+
</para>
1342+
1343+
<para>
1344+
The default behavior for huge pages in
1345+
<productname>PostgreSQL</productname> is to use them when possible and
1346+
to fallback to normal pages when failing. To enforce the use of huge
1347+
pages, you can set
1348+
<link linkend="guc-huge-pages"><varname>huge_pages</varname></link>
1349+
to <literal>on</literal>. Note that in this case
1350+
<productname>PostgreSQL</productname> will fail to start if not enough huge
1351+
pages are available.
1352+
</para>
1353+
1354+
<para>
1355+
For a detailed description of the <productname>Linux</productname> huge
1356+
pages feature have a look
1357+
at <ulink url="https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt">https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt</ulink>.
1358+
</para>
1359+
1360+
</sect2>
13101361
</sect1>
13111362

13121363

src/backend/port/sysv_shmem.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ CreateAnonymousSegment(Size *size)
333333
int mmap_errno = 0;
334334

335335
#ifndef MAP_HUGETLB
336-
if (huge_tlb_pages == HUGE_TLB_ON)
336+
if (huge_pages == HUGE_PAGES_ON)
337337
ereport(ERROR,
338338
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
339339
errmsg("huge TLB pages not supported on this platform")));
340340
#else
341-
if (huge_tlb_pages == HUGE_TLB_ON || huge_tlb_pages == HUGE_TLB_TRY)
341+
if (huge_pages == HUGE_PAGES_ON || huge_pages == HUGE_PAGES_TRY)
342342
{
343343
/*
344344
* Round up the request size to a suitable large value.
@@ -364,13 +364,13 @@ CreateAnonymousSegment(Size *size)
364364
ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE,
365365
PG_MMAP_FLAGS | MAP_HUGETLB, -1, 0);
366366
mmap_errno = errno;
367-
if (huge_tlb_pages == HUGE_TLB_TRY && ptr == MAP_FAILED)
367+
if (huge_pages == HUGE_PAGES_TRY && ptr == MAP_FAILED)
368368
elog(DEBUG1, "mmap with MAP_HUGETLB failed, huge pages disabled: %m");
369369
}
370370
#endif
371371

372-
if (huge_tlb_pages == HUGE_TLB_OFF ||
373-
(huge_tlb_pages == HUGE_TLB_TRY && ptr == MAP_FAILED))
372+
if (huge_pages == HUGE_PAGES_OFF ||
373+
(huge_pages == HUGE_PAGES_TRY && ptr == MAP_FAILED))
374374
{
375375
/*
376376
* use the original size, not the rounded up value, when falling
@@ -431,10 +431,10 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
431431
Size sysvsize;
432432

433433
#if defined(EXEC_BACKEND) || !defined(MAP_HUGETLB)
434-
if (huge_tlb_pages == HUGE_TLB_ON)
434+
if (huge_pages == HUGE_PAGES_ON)
435435
ereport(ERROR,
436436
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
437-
errmsg("huge TLB pages not supported on this platform")));
437+
errmsg("huge pages not supported on this platform")));
438438
#endif
439439

440440
/* Room for a header? */

src/backend/port/win32_shmem.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
128128
DWORD size_high;
129129
DWORD size_low;
130130

131-
if (huge_tlb_pages == HUGE_TLB_ON)
131+
if (huge_pages == HUGE_PAGES_ON)
132132
ereport(ERROR,
133133
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
134-
errmsg("huge TLB pages not supported on this platform")));
134+
errmsg("huge pages not supported on this platform")));
135135

136136
/* Room for a header? */
137137
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));

src/backend/utils/misc/guc.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ static const struct config_enum_entry synchronous_commit_options[] = {
393393
* Although only "on", "off", "try" are documented, we accept all the likely
394394
* variants of "on" and "off".
395395
*/
396-
static const struct config_enum_entry huge_tlb_options[] = {
397-
{"off", HUGE_TLB_OFF, false},
398-
{"on", HUGE_TLB_ON, false},
399-
{"try", HUGE_TLB_TRY, false},
400-
{"true", HUGE_TLB_ON, true},
401-
{"false", HUGE_TLB_OFF, true},
402-
{"yes", HUGE_TLB_ON, true},
403-
{"no", HUGE_TLB_OFF, true},
404-
{"1", HUGE_TLB_ON, true},
405-
{"0", HUGE_TLB_OFF, true},
396+
static const struct config_enum_entry huge_pages_options[] = {
397+
{"off", HUGE_PAGES_OFF, false},
398+
{"on", HUGE_PAGES_ON, false},
399+
{"try", HUGE_PAGES_TRY, false},
400+
{"true", HUGE_PAGES_ON, true},
401+
{"false", HUGE_PAGES_OFF, true},
402+
{"yes", HUGE_PAGES_ON, true},
403+
{"no", HUGE_PAGES_OFF, true},
404+
{"1", HUGE_PAGES_ON, true},
405+
{"0", HUGE_PAGES_OFF, true},
406406
{NULL, 0, false}
407407
};
408408

@@ -470,7 +470,7 @@ int tcp_keepalives_count;
470470
* This really belongs in pg_shmem.c, but is defined here so that it doesn't
471471
* need to be duplicated in all the different implementations of pg_shmem.c.
472472
*/
473-
int huge_tlb_pages;
473+
int huge_pages;
474474

475475
/*
476476
* These variables are all dummies that don't do anything, except in some
@@ -3497,12 +3497,12 @@ static struct config_enum ConfigureNamesEnum[] =
34973497
},
34983498

34993499
{
3500-
{"huge_tlb_pages", PGC_POSTMASTER, RESOURCES_MEM,
3501-
gettext_noop("Use of huge TLB pages on Linux"),
3500+
{"huge_pages", PGC_POSTMASTER, RESOURCES_MEM,
3501+
gettext_noop("Use of huge pages on Linux"),
35023502
NULL
35033503
},
3504-
&huge_tlb_pages,
3505-
HUGE_TLB_TRY, huge_tlb_options,
3504+
&huge_pages,
3505+
HUGE_PAGES_TRY, huge_pages_options,
35063506
NULL, NULL, NULL
35073507
},
35083508

src/backend/utils/misc/postgresql.conf.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
#shared_buffers = 32MB # min 128kB
117117
# (change requires restart)
118-
#huge_tlb_pages = try # on, off, or try
118+
#huge_pages = try # on, off, or try
119119
# (change requires restart)
120120
#temp_buffers = 8MB # min 800kB
121121
#max_prepared_transactions = 0 # zero disables the feature

src/include/storage/pg_shmem.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
3939
} PGShmemHeader;
4040

4141
/* GUC variable */
42-
extern int huge_tlb_pages;
42+
extern int huge_pages;
4343

44-
/* Possible values for huge_tlb_pages */
44+
/* Possible values for huge_pages */
4545
typedef enum
4646
{
47-
HUGE_TLB_OFF,
48-
HUGE_TLB_ON,
49-
HUGE_TLB_TRY
50-
} HugeTlbType;
47+
HUGE_PAGES_OFF,
48+
HUGE_PAGES_ON,
49+
HUGE_PAGES_TRY
50+
} HugePagesType;
5151

5252
#ifndef WIN32
5353
extern unsigned long UsedShmemSegID;

0 commit comments

Comments
 (0)