Skip to content

Commit dc04be2

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 a92c0f6 commit dc04be2

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
@@ -1422,53 +1422,67 @@ export PG_OOM_ADJUST_VALUE=0
14221422
</sect2>
14231423

14241424
<sect2 id="linux-huge-pages">
1425-
<title>Linux huge pages</title>
1425+
<title>Linux Huge Pages</title>
14261426

14271427
<para>
14281428
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
14301431
feature in <productname>PostgreSQL</productname> you need a kernel
14311432
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:
14371440
<programlisting>
1438-
$ <userinput>head -1 /path/to/data/directory/postmaster.pid</userinput>
1441+
$ <userinput>head -1 $PGDATA/postmaster.pid</userinput>
14391442
4170
14401443
$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
14411444
VmPeak: 6490428 kB
1445+
$ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
1446+
Hugepagesize: 2048 kB
14421447
</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:
14471451
<programlisting>
14481452
$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
14491453
</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>
14501461
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>
14541469
</para>
14551470

14561471
<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
14581473
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</>.
14611476
</para>
14621477

14631478
<para>
14641479
The default behavior for huge pages in
14651480
<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.
14721486
</para>
14731487

14741488
<para>

0 commit comments

Comments
 (0)