@@ -1391,41 +1391,55 @@ export PG_OOM_ADJUST_VALUE=0
1391
1391
using large values of <xref linkend="guc-shared-buffers"/>. To use this
1392
1392
feature in <productname>PostgreSQL</productname> you need a kernel
1393
1393
with <varname>CONFIG_HUGETLBFS=y</varname> and
1394
- <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to adjust
1395
- the kernel setting <varname>vm.nr_hugepages</varname>. To estimate the
1396
- number of huge pages needed, start <productname>PostgreSQL</productname>
1397
- without huge pages enabled and check the
1398
- postmaster's anonymous shared memory segment size, as well as the system's
1399
- huge page size, using the <filename>/proc</filename> file system. This might
1400
- look like:
1394
+ <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to configure
1395
+ the operating system to provide enough huge pages of the desired size.
1396
+ To estimate the number of huge pages needed, start
1397
+ <productname>PostgreSQL</productname> without huge pages enabled and check
1398
+ the postmaster's anonymous shared memory segment size, as well as the
1399
+ system's default and supported huge page sizes, using the
1400
+ <filename>/proc</filename> and <filename>/sys</filename> file systems.
1401
+ This might look like:
1401
1402
<programlisting>
1402
1403
$ <userinput>head -1 $PGDATA/postmaster.pid</userinput>
1403
1404
4170
1404
1405
$ <userinput>pmap 4170 | awk '/rw-s/ && /zero/ {print $2}'</userinput>
1405
1406
6490428K
1406
1407
$ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
1407
1408
Hugepagesize: 2048 kB
1409
+ $ <userinput>ls /sys/kernel/mm/hugepages</userinput>
1410
+ hugepages-1048576kB hugepages-2048kB
1408
1411
</programlisting>
1412
+
1413
+ In this example the default is 2MB, but you can also explicitly request
1414
+ either 2MB or 1GB with <xref linkend="guc-huge-page-size"/>.
1415
+
1416
+ Assuming <literal>2MB</literal> huge pages,
1409
1417
<literal>6490428</literal> / <literal>2048</literal> gives approximately
1410
1418
<literal>3169.154</literal>, so in this example we need at
1411
- least <literal>3170</literal> huge pages, which we can set with:
1419
+ least <literal>3170</literal> huge pages. A larger setting would be
1420
+ appropriate if other programs on the machine also need huge pages.
1421
+ We can set this with:
1422
+ <programlisting>
1423
+ # <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
1424
+ </programlisting>
1425
+ Don't forget to add this setting to <filename>/etc/sysctl.conf</filename>
1426
+ so that it is reapplied after reboots. For non-default huge page sizes,
1427
+ we can instead use:
1412
1428
<programlisting>
1413
- $ <userinput>sysctl -w vm. nr_hugepages=3170 </userinput>
1429
+ # <userinput>echo 3170 > /sys/kernel/mm/hugepages/hugepages-2048kB/ nr_hugepages</userinput>
1414
1430
</programlisting>
1415
- A larger setting would be appropriate if other programs on the machine
1416
- also need huge pages. Don't forget to add this setting
1417
- to <filename>/etc/sysctl.conf</filename> so that it will be reapplied
1418
- after reboots.
1431
+ It is also possible to provide these settings at boot time using
1432
+ kernel parameters such as <literal>hugepagesz=2M hugepages=3170</literal>.
1419
1433
</para>
1420
1434
1421
1435
<para>
1422
1436
Sometimes the kernel is not able to allocate the desired number of huge
1423
- pages immediately, so it might be necessary to repeat the command or to
1424
- reboot. (Immediately after a reboot, most of the machine's memory
1425
- should be available to convert into huge pages.) To verify the huge
1426
- page allocation situation, use:
1437
+ pages immediately due to fragmentation , so it might be necessary
1438
+ to repeat the command or to reboot. (Immediately after a reboot, most of
1439
+ the machine's memory should be available to convert into huge pages.)
1440
+ To verify the huge page allocation situation for a given size , use:
1427
1441
<programlisting>
1428
- $ <userinput>grep Huge /proc/meminfo </userinput>
1442
+ $ <userinput>cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages </userinput>
1429
1443
</programlisting>
1430
1444
</para>
1431
1445
@@ -1438,8 +1452,9 @@ $ <userinput>grep Huge /proc/meminfo</userinput>
1438
1452
1439
1453
<para>
1440
1454
The default behavior for huge pages in
1441
- <productname>PostgreSQL</productname> is to use them when possible and
1442
- to fall back to normal pages when failing. To enforce the use of huge
1455
+ <productname>PostgreSQL</productname> is to use them when possible, with
1456
+ the system's default huge page size, and
1457
+ to fall back to normal pages on failure. To enforce the use of huge
1443
1458
pages, you can set <xref linkend="guc-huge-pages"/>
1444
1459
to <literal>on</literal> in <filename>postgresql.conf</filename>.
1445
1460
Note that with this setting <productname>PostgreSQL</productname> will fail to
0 commit comments