1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Allow using huge TLB pages on Linux (MAP_HUGETLB)

This patch adds an option, huge_tlb_pages, which allows requesting the
shared memory segment to be allocated using huge pages, by using the
MAP_HUGETLB flag in mmap(). This can improve performance.

The default is 'try', which means that we will attempt using huge pages,
and fall back to non-huge pages if it doesn't work. Currently, only Linux
has MAP_HUGETLB. On other platforms, the default 'try' behaves the same as
'off'.

In the passing, don't try to round the mmap() size to a multiple of
pagesize. mmap() doesn't require that, and there's no particular reason for
PostgreSQL to do that either. When using MAP_HUGETLB, however, round the
request size up to nearest 2MB boundary. This is to work around a bug in
some Linux kernel versions, but also to avoid wasting memory, because the
kernel will round the size up anyway.

Many people were involved in writing this patch, including Christian Kruse,
Richard Poole, Abhijit Menon-Sen, reviewed by Peter Geoghegan, Andres Freund
and me.
This commit is contained in:
Heikki Linnakangas
2014-01-29 13:44:45 +02:00
parent b7643b19f0
commit 1a3458b6d8
6 changed files with 183 additions and 39 deletions

View File

@ -1107,6 +1107,43 @@ include 'filename'
</listitem>
</varlistentry>
<varlistentry id="guc-huge-tlb-pages" xreflabel="huge_tlb_pages">
<term><varname>huge_tlb_pages</varname> (<type>enum</type>)</term>
<indexterm>
<primary><varname>huge_tlb_pages</> configuration parameter</primary>
</indexterm>
<listitem>
<para>
Enables/disables the use of huge TLB pages. Valid values are
<literal>try</literal> (the default), <literal>on</literal>,
and <literal>off</literal>.
</para>
<para>
At present, this feature is supported only on Linux. The setting
is ignored on other systems.
</para>
<para>
The use of huge TLB pages results in smaller page tables and
less CPU time spent on memory management, increasing performance. For
more details, see
<ulink url="https://wiki.debian.org/Hugepages">the Debian wiki</ulink>.
Remember that you will need at least shared_buffers / huge page size +
1 huge TLB pages. So for example for a system with 6GB shared buffers
and a hugepage size of 2kb of you will need at least 3156 huge pages.
</para>
<para>
With <varname>huge_tlb_pages</varname> set to <literal>try</literal>,
the server will try to use huge pages, but fall back to using
normal allocation if that fails. With <literal>on</literal, failure
to use huge pages will prevent the server from starting up. With
<literal>off</literal>, huge pages will not be used.
</para>
</listitem>
</varlistentry>
<varlistentry id="guc-temp-buffers" xreflabel="temp_buffers">
<term><varname>temp_buffers</varname> (<type>integer</type>)</term>
<indexterm>