@@ -1375,53 +1375,67 @@ export PG_OOM_ADJUST_VALUE=0
1375
1375
</sect2>
1376
1376
1377
1377
<sect2 id="linux-huge-pages">
1378
- <title>Linux huge pages </title>
1378
+ <title>Linux Huge Pages </title>
1379
1379
1380
1380
<para>
1381
1381
Using huge pages reduces overhead when using large contiguous chunks of
1382
- memory, like <productname>PostgreSQL</productname> does. To enable this
1382
+ memory, as <productname>PostgreSQL</productname> does, particularly when
1383
+ using large values of <xref linkend="guc-shared-buffers">. To use this
1383
1384
feature in <productname>PostgreSQL</productname> you need a kernel
1384
1385
with <varname>CONFIG_HUGETLBFS=y</varname> and
1385
- <varname>CONFIG_HUGETLB_PAGE=y</varname>. You also have to tune the system
1386
- setting <varname>vm.nr_hugepages</varname>. To estimate the number of
1387
- necessary huge pages start <productname>PostgreSQL</productname> without
1388
- huge pages enabled and check the <varname>VmPeak</varname> value from the
1389
- proc file system:
1386
+ <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to adjust
1387
+ the kernel setting <varname>vm.nr_hugepages</varname>. To estimate the
1388
+ number of huge pages needed, start <productname>PostgreSQL</productname>
1389
+ without huge pages enabled and check the
1390
+ postmaster's <varname>VmPeak</varname> value, as well as the system's
1391
+ huge page size, using the <filename>/proc</> file system. This might
1392
+ look like:
1390
1393
<programlisting>
1391
- $ <userinput>head -1 /path/to/data/directory /postmaster.pid</userinput>
1394
+ $ <userinput>head -1 $PGDATA /postmaster.pid</userinput>
1392
1395
4170
1393
1396
$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
1394
1397
VmPeak: 6490428 kB
1398
+ $ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
1399
+ Hugepagesize: 2048 kB
1395
1400
</programlisting>
1396
- <literal>6490428</literal> / <literal>2048</literal>
1397
- (<varname>PAGE_SIZE</varname> is <literal>2MB</literal> in this case) are
1398
- roughly <literal>3169.154</literal> huge pages, so you will need at
1399
- least <literal>3170</literal> huge pages:
1401
+ <literal>6490428</literal> / <literal>2048</literal> gives approximately
1402
+ <literal>3169.154</literal>, so in this example we need at
1403
+ least <literal>3170</literal> huge pages, which we can set with:
1400
1404
<programlisting>
1401
1405
$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
1402
1406
</programlisting>
1407
+ A larger setting would be appropriate if other programs on the machine
1408
+ also need huge pages. Don't forget to add this setting
1409
+ to <filename>/etc/sysctl.conf</filename> so that it will be reapplied
1410
+ after reboots.
1411
+ </para>
1412
+
1413
+ <para>
1403
1414
Sometimes the kernel is not able to allocate the desired number of huge
1404
- pages, so it might be necessary to repeat that command or to reboot. Don't
1405
- forget to add an entry to <filename>/etc/sysctl.conf</filename> to persist
1406
- this setting through reboots.
1415
+ pages immediately, so it might be necessary to repeat the command or to
1416
+ reboot. (Immediately after a reboot, most of the machine's memory
1417
+ should be available to convert into huge pages.) To verify the huge
1418
+ page allocation situation, use:
1419
+ <programlisting>
1420
+ $ <userinput>grep Huge /proc/meminfo</userinput>
1421
+ </programlisting>
1407
1422
</para>
1408
1423
1409
1424
<para>
1410
- It is also necessary to give the database server operating system
1425
+ It may also be necessary to give the database server's operating system
1411
1426
user permission to use huge pages by setting
1412
- <varname>vm.hugetlb_shm_group</> via <application>sysctl</>, and
1413
- permission to lock memory with <command>ulimit -l</>.
1427
+ <varname>vm.hugetlb_shm_group</> via <application>sysctl</>, and/or
1428
+ give permission to lock memory with <command>ulimit -l</>.
1414
1429
</para>
1415
1430
1416
1431
<para>
1417
1432
The default behavior for huge pages in
1418
1433
<productname>PostgreSQL</productname> is to use them when possible and
1419
- to fallback to normal pages when failing. To enforce the use of huge
1420
- pages, you can set
1421
- <link linkend="guc-huge-pages"><varname>huge_pages</varname></link>
1422
- to <literal>on</literal>. Note that in this case
1423
- <productname>PostgreSQL</productname> will fail to start if not enough huge
1424
- pages are available.
1434
+ to fall back to normal pages when failing. To enforce the use of huge
1435
+ pages, you can set <xref linkend="guc-huge-pages">
1436
+ to <literal>on</literal> in <filename>postgresql.conf</>.
1437
+ Note that with this setting <productname>PostgreSQL</> will fail to
1438
+ start if not enough huge pages are available.
1425
1439
</para>
1426
1440
1427
1441
<para>
0 commit comments