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