@@ -1422,53 +1422,67 @@ export PG_OOM_ADJUST_VALUE=0
1422
1422
</sect2>
1423
1423
1424
1424
<sect2 id="linux-huge-pages">
1425
- <title>Linux huge pages </title>
1425
+ <title>Linux Huge Pages </title>
1426
1426
1427
1427
<para>
1428
1428
Using huge pages reduces overhead when using large contiguous chunks of
1429
- memory, like <productname>PostgreSQL</productname> does. To enable this
1429
+ memory, as <productname>PostgreSQL</productname> does, particularly when
1430
+ using large values of <xref linkend="guc-shared-buffers">. To use this
1430
1431
feature in <productname>PostgreSQL</productname> you need a kernel
1431
1432
with <varname>CONFIG_HUGETLBFS=y</varname> and
1432
- <varname>CONFIG_HUGETLB_PAGE=y</varname>. You also have to tune the system
1433
- setting <varname>vm.nr_hugepages</varname>. To estimate the number of
1434
- necessary huge pages start <productname>PostgreSQL</productname> without
1435
- huge pages enabled and check the <varname>VmPeak</varname> value from the
1436
- proc file system:
1433
+ <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to adjust
1434
+ the kernel setting <varname>vm.nr_hugepages</varname>. To estimate the
1435
+ number of huge pages needed, start <productname>PostgreSQL</productname>
1436
+ without huge pages enabled and check the
1437
+ postmaster's <varname>VmPeak</varname> value, as well as the system's
1438
+ huge page size, using the <filename>/proc</> file system. This might
1439
+ look like:
1437
1440
<programlisting>
1438
- $ <userinput>head -1 /path/to/data/directory /postmaster.pid</userinput>
1441
+ $ <userinput>head -1 $PGDATA /postmaster.pid</userinput>
1439
1442
4170
1440
1443
$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
1441
1444
VmPeak: 6490428 kB
1445
+ $ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
1446
+ Hugepagesize: 2048 kB
1442
1447
</programlisting>
1443
- <literal>6490428</literal> / <literal>2048</literal>
1444
- (<varname>PAGE_SIZE</varname> is <literal>2MB</literal> in this case) are
1445
- roughly <literal>3169.154</literal> huge pages, so you will need at
1446
- least <literal>3170</literal> huge pages:
1448
+ <literal>6490428</literal> / <literal>2048</literal> gives approximately
1449
+ <literal>3169.154</literal>, so in this example we need at
1450
+ least <literal>3170</literal> huge pages, which we can set with:
1447
1451
<programlisting>
1448
1452
$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
1449
1453
</programlisting>
1454
+ A larger setting would be appropriate if other programs on the machine
1455
+ also need huge pages. Don't forget to add this setting
1456
+ to <filename>/etc/sysctl.conf</filename> so that it will be reapplied
1457
+ after reboots.
1458
+ </para>
1459
+
1460
+ <para>
1450
1461
Sometimes the kernel is not able to allocate the desired number of huge
1451
- pages, so it might be necessary to repeat that command or to reboot. Don't
1452
- forget to add an entry to <filename>/etc/sysctl.conf</filename> to persist
1453
- this setting through reboots.
1462
+ pages immediately, so it might be necessary to repeat the command or to
1463
+ reboot. (Immediately after a reboot, most of the machine's memory
1464
+ should be available to convert into huge pages.) To verify the huge
1465
+ page allocation situation, use:
1466
+ <programlisting>
1467
+ $ <userinput>grep Huge /proc/meminfo</userinput>
1468
+ </programlisting>
1454
1469
</para>
1455
1470
1456
1471
<para>
1457
- It is also necessary to give the database server operating system
1472
+ It may also be necessary to give the database server's operating system
1458
1473
user permission to use huge pages by setting
1459
- <varname>vm.hugetlb_shm_group</> via <application>sysctl</>, and
1460
- permission to lock memory with <command>ulimit -l</>.
1474
+ <varname>vm.hugetlb_shm_group</> via <application>sysctl</>, and/or
1475
+ give permission to lock memory with <command>ulimit -l</>.
1461
1476
</para>
1462
1477
1463
1478
<para>
1464
1479
The default behavior for huge pages in
1465
1480
<productname>PostgreSQL</productname> is to use them when possible and
1466
- to fallback to normal pages when failing. To enforce the use of huge
1467
- pages, you can set
1468
- <link linkend="guc-huge-pages"><varname>huge_pages</varname></link>
1469
- to <literal>on</literal>. Note that in this case
1470
- <productname>PostgreSQL</productname> will fail to start if not enough huge
1471
- pages are available.
1481
+ to fall back to normal pages when failing. To enforce the use of huge
1482
+ pages, you can set <xref linkend="guc-huge-pages">
1483
+ to <literal>on</literal> in <filename>postgresql.conf</>.
1484
+ Note that with this setting <productname>PostgreSQL</> will fail to
1485
+ start if not enough huge pages are available.
1472
1486
</para>
1473
1487
1474
1488
<para>
0 commit comments