Skip to content

Commit 13d5dd5

Browse files
committed
Improve documentation about use of Linux huge pages.
Show how to get the system's huge page size, rather than misleadingly referring to PAGE_SIZE (which is usually understood to be the regular page size). Show how to confirm whether huge pages have been allocated. Minor wordsmithing. Back-patch to 9.4 where this section appeared.
1 parent 8acc15e commit 13d5dd5

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,53 +1375,67 @@ export PG_OOM_ADJUST_VALUE=0
13751375
</sect2>
13761376

13771377
<sect2 id="linux-huge-pages">
1378-
<title>Linux huge pages</title>
1378+
<title>Linux Huge Pages</title>
13791379

13801380
<para>
13811381
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
13831384
feature in <productname>PostgreSQL</productname> you need a kernel
13841385
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:
13901393
<programlisting>
1391-
$ <userinput>head -1 /path/to/data/directory/postmaster.pid</userinput>
1394+
$ <userinput>head -1 $PGDATA/postmaster.pid</userinput>
13921395
4170
13931396
$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
13941397
VmPeak: 6490428 kB
1398+
$ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
1399+
Hugepagesize: 2048 kB
13951400
</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:
14001404
<programlisting>
14011405
$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
14021406
</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>
14031414
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>
14071422
</para>
14081423

14091424
<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
14111426
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</>.
14141429
</para>
14151430

14161431
<para>
14171432
The default behavior for huge pages in
14181433
<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.
14251439
</para>
14261440

14271441
<para>

0 commit comments

Comments
 (0)