aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2020-07-17 14:33:00 +1200
committerThomas Munro <tmunro@postgresql.org>2020-07-17 14:33:00 +1200
commitd2bddc2500fb74d56e5bc53a1cfa269e2e846510 (patch)
treecaf1a941a50374e61f327fce8e717c7b62b0a031 /doc/src
parentd66b23b032d75614e1be47ca182020960d89206d (diff)
downloadpostgresql-d2bddc2500fb74d56e5bc53a1cfa269e2e846510.tar.gz
postgresql-d2bddc2500fb74d56e5bc53a1cfa269e2e846510.zip
Add huge_page_size setting for use on Linux.
This allows the huge page size to be set explicitly. The default is 0, meaning it will use the system default, as before. Author: Odin Ugedal <odin@ugedal.com> Discussion: https://postgr.es/m/20200608154639.20254-1-odin%40ugedal.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/config.sgml27
-rw-r--r--doc/src/sgml/runtime.sgml55
2 files changed, 62 insertions, 20 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index b353c616830..e0ea397ed40 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -1582,6 +1582,33 @@ include_dir 'conf.d'
</listitem>
</varlistentry>
+ <varlistentry id="guc-huge-page-size" xreflabel="huge_page_size">
+ <term><varname>huge_page_size</varname> (<type>integer</type>)
+ <indexterm>
+ <primary><varname>huge_page_size</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Controls the size of huge pages, when they are enabled with
+ <xref linkend="guc-huge-pages"/>.
+ The default is zero (<literal>0</literal>).
+ When set to <literal>0</literal>, the default huge page size on the
+ system will be used.
+ </para>
+ <para>
+ Some commonly available page sizes on modern 64 bit server architectures include:
+ <literal>2MB</literal> and <literal>1GB</literal> (Intel and AMD), <literal>16MB</literal> and
+ <literal>16GB</literal> (IBM POWER), and <literal>64kB</literal>, <literal>2MB</literal>,
+ <literal>32MB</literal> and <literal>1GB</literal> (ARM). For more information
+ about usage and support, see <xref linkend="linux-huge-pages"/>.
+ </para>
+ <para>
+ Non-default settings are currently supported only on Linux.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-temp-buffers" xreflabel="temp_buffers">
<term><varname>temp_buffers</varname> (<type>integer</type>)
<indexterm>
diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index 937bb2e8ac9..e09cb55efcd 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -1391,13 +1391,14 @@ export PG_OOM_ADJUST_VALUE=0
using large values of <xref linkend="guc-shared-buffers"/>. To use this
feature in <productname>PostgreSQL</productname> you need a kernel
with <varname>CONFIG_HUGETLBFS=y</varname> and
- <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to adjust
- the kernel setting <varname>vm.nr_hugepages</varname>. To estimate the
- number of huge pages needed, start <productname>PostgreSQL</productname>
- without huge pages enabled and check the
- postmaster's anonymous shared memory segment size, as well as the system's
- huge page size, using the <filename>/proc</filename> file system. This might
- look like:
+ <varname>CONFIG_HUGETLB_PAGE=y</varname>. You will also have to configure
+ the operating system to provide enough huge pages of the desired size.
+ To estimate the number of huge pages needed, start
+ <productname>PostgreSQL</productname> without huge pages enabled and check
+ the postmaster's anonymous shared memory segment size, as well as the
+ system's default and supported huge page sizes, using the
+ <filename>/proc</filename> and <filename>/sys</filename> file systems.
+ This might look like:
<programlisting>
$ <userinput>head -1 $PGDATA/postmaster.pid</userinput>
4170
@@ -1405,27 +1406,40 @@ $ <userinput>pmap 4170 | awk '/rw-s/ &amp;&amp; /zero/ {print $2}'</userinput>
6490428K
$ <userinput>grep ^Hugepagesize /proc/meminfo</userinput>
Hugepagesize: 2048 kB
+$ <userinput>ls /sys/kernel/mm/hugepages</userinput>
+hugepages-1048576kB hugepages-2048kB
</programlisting>
+
+ In this example the default is 2MB, but you can also explicitly request
+ either 2MB or 1GB with <xref linkend="guc-huge-page-size"/>.
+
+ Assuming <literal>2MB</literal> huge pages,
<literal>6490428</literal> / <literal>2048</literal> gives approximately
<literal>3169.154</literal>, so in this example we need at
- least <literal>3170</literal> huge pages, which we can set with:
+ least <literal>3170</literal> huge pages. A larger setting would be
+ appropriate if other programs on the machine also need huge pages.
+ We can set this with:
+<programlisting>
+# <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
+</programlisting>
+ Don't forget to add this setting to <filename>/etc/sysctl.conf</filename>
+ so that it is reapplied after reboots. For non-default huge page sizes,
+ we can instead use:
<programlisting>
-$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
+# <userinput>echo 3170 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages</userinput>
</programlisting>
- A larger setting would be appropriate if other programs on the machine
- also need huge pages. Don't forget to add this setting
- to <filename>/etc/sysctl.conf</filename> so that it will be reapplied
- after reboots.
+ It is also possible to provide these settings at boot time using
+ kernel parameters such as <literal>hugepagesz=2M hugepages=3170</literal>.
</para>
<para>
Sometimes the kernel is not able to allocate the desired number of huge
- pages immediately, so it might be necessary to repeat the command or to
- reboot. (Immediately after a reboot, most of the machine's memory
- should be available to convert into huge pages.) To verify the huge
- page allocation situation, use:
+ pages immediately due to fragmentation, so it might be necessary
+ to repeat the command or to reboot. (Immediately after a reboot, most of
+ the machine's memory should be available to convert into huge pages.)
+ To verify the huge page allocation situation for a given size, use:
<programlisting>
-$ <userinput>grep Huge /proc/meminfo</userinput>
+$ <userinput>cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages</userinput>
</programlisting>
</para>
@@ -1438,8 +1452,9 @@ $ <userinput>grep Huge /proc/meminfo</userinput>
<para>
The default behavior for huge pages in
- <productname>PostgreSQL</productname> is to use them when possible and
- to fall back to normal pages when failing. To enforce the use of huge
+ <productname>PostgreSQL</productname> is to use them when possible, with
+ the system's default huge page size, and
+ to fall back to normal pages on failure. To enforce the use of huge
pages, you can set <xref linkend="guc-huge-pages"/>
to <literal>on</literal> in <filename>postgresql.conf</filename>.
Note that with this setting <productname>PostgreSQL</productname> will fail to