Hi,

after I finally got documentation compilation working I updated the
patch to be syntactically correct. You will find it attached.

Best regards,

-- 
 Christian Kruse               http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 1b5f831..68b38f7 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -1128,10 +1128,7 @@ include 'filename'
         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.
+        <link linkend="linux-huge-tlb-pages">Linux huge TLB pages</link>.
        </para>
 
        <para>
diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index bbb808f..0b98314 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -1307,6 +1307,82 @@ echo -1000 > /proc/self/oom_score_adj
    </para>
    </note>
   </sect2>
+
+  <sect2 id="linux-huge-tlb-pages">
+   <title>Linux huge TLB pages</title>
+
+   <para>
+    Nowadays memory address spaces for processes are virtual. This means, when
+    a process reserves memory, it gets a virtual memory address which has to
+    be translated to a physical memory address by the OS or the CPU. This can
+    be done via calculations, but since memory is accessed very often there is
+    a cache for that, called Translation Lookaside Buffer,
+    short <emphasis>TLB</emphasis>.
+   </para>
+
+   <para>
+    When a process reserves memory, this is done in chunks (often
+    of <literal>4kb</literal>) named pages. This means if a process requires
+    1GB of RAM, it has <literal>262144</literal> (<literal>1GB</literal>
+    / <literal>4KB</literal>) pages and therefore <literal>262144</literal>
+    entries for the translation table. Since the TLB has a limited number of
+    entries it is obvious that they can't be they can't all be cached, which
+    will lead to loss of performance.
+   </para>
+
+   <para>
+    One way to tune this is to increase the page size. Most platforms allow
+    larger pages, e.g. x86 allows pages of <literal>2MB</literal>. This would
+    reduce the number of pages to <literal>512</literal>
+    (<literal>1GB</literal> / <literal>2MB</literal>). This reduces the number
+    of necessary lookups drastrically.
+   </para>
+
+   <para>
+    To enable this feature in <productname>PostgreSQL</productname> you need a
+    kernel with <varname>CONFIG_HUGETLBFS=y</varname> and
+    <varname>CONFIG_HUGETLB_PAGE=y</varname>. You also have to tune the system
+    setting <varname>vm.nr_hugepages</varname>. To calculate the number of
+    necessary huge pages start <productname>PostgreSQL</productname> without
+    huge pages enabled and check the <varname>VmPeak</varname> value from the
+    proc filesystem:
+<programlisting>
+$ <userinput>head -1 /path/to/data/directory/postmaster.pid</userinput>
+4170
+$ <userinput>grep ^VmPeak /proc/4170/status</userinput>
+VmPeak:  6490428 kB
+</programlisting>
+     <literal>6490428</literal> / <literal>2048</literal>
+     (<varname>PAGE_SIZE</varname> <literal>2MB</literal>) are
+     roughly <literal>3169.154</literal> huge pages, so you will need at
+     least <literal>3170</literal> huge pages:
+<programlisting>
+$ <userinput>sysctl -w vm.nr_hugepages=3170</userinput>
+</programlisting>
+    Sometimes the kernel is not able to allocate the desired number of huge
+    pages, so it might be necessary to repeat that command or to reboot. Don't
+    forget to add an entry to <filename>/etc/sysctl.conf</filename> to persist
+    this setting through reboots.
+   </para>
+
+   <para>
+    The default behavior for huge pages
+    in <productname>PostgreSQL</productname> is to use them when possible and
+    to fallback to normal pages when failing. To enforce the use of huge
+    pages, you can
+    set <link linkend="guc-huge-tlb-pages"><varname>huge_tlb_pages</varname></link>
+    to <literal>on</literal>. Note that in this
+    case <productname>PostgreSQL</productname> will fail to start if not
+    enough huge pages are available.
+   </para>
+
+   <para>
+    For a detailed description of the <productname>Linux</productname> huge
+    pages feature have a look
+    at <ulink url="">https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt</ulink>.
+   </para>
+
+  </sect2>
  </sect1>
 
 

Attachment: pgpuCF6bKmrpI.pgp
Description: PGP signature

Reply via email to