<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="large-page-support">
      </a>
      10.12.3.3 Enabling Large Page Support
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045222150512">
  </a>
  <p>
   Some hardware and operating system architectures support
          memory pages greater than the default (usually 4KB). The
          actual implementation of this support depends on the
          underlying hardware and operating system. Applications that
          perform a lot of memory accesses may obtain performance
          improvements by using large pages due to reduced Translation
          Lookaside Buffer (TLB) misses.
  </p>
  <p>
   In MySQL, large pages can be used by
   <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
    <code class="literal">
     InnoDB
    </code>
   </a>
   , to allocate memory for
          its buffer pool and additional memory pool.
  </p>
  <p>
   Standard use of large pages in MySQL attempts to use the
          largest size supported, up to 4MB. Under Solaris, a
   <span class="quote">
    “
    <span class="quote">
     super large pages
    </span>
    ”
   </span>
   feature enables uses of pages
          up to 256MB. This feature is available for recent SPARC
          platforms. It can be enabled or disabled by using the
   <a class="link" href="server-options.html#option_mysqld_super-large-pages">
    <code class="option">
     --super-large-pages
    </code>
   </a>
   or
   <a class="link" href="server-options.html#option_mysqld_super-large-pages">
    <code class="option">
     --skip-super-large-pages
    </code>
   </a>
   option.
  </p>
  <p>
   MySQL also supports the Linux implementation of large page
          support (which is called HugeTLB in Linux).
  </p>
  <p>
   Before large pages can be used on Linux, the kernel must be
          enabled to support them and it is necessary to configure the
          HugeTLB memory pool. For reference, the HugeTBL API is
          documented in the
   <code class="filename">
    Documentation/vm/hugetlbpage.txt
   </code>
   file of
          your Linux sources.
  </p>
  <p>
   The kernels for some recent systems such as Red Hat Enterprise
          Linux may have the large pages feature enabled by default. To
          check whether this is true for your kernel, use the following
          command and look for output lines containing
   <span class="quote">
    “
    <span class="quote">
     huge
    </span>
    ”
   </span>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa90271592"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">grep</span> <span class="token property">-i</span> huge /proc/meminfo
AnonHugePages<span class="token punctuation">:</span>   2658304 kB
ShmemHugePages<span class="token punctuation">:</span>        0 kB
HugePages_Total<span class="token punctuation">:</span>       0
HugePages_Free<span class="token punctuation">:</span>        0
HugePages_Rsvd<span class="token punctuation">:</span>        0
HugePages_Surp<span class="token punctuation">:</span>        0
Hugepagesize<span class="token punctuation">:</span>       2048 kB
Hugetlb<span class="token punctuation">:</span>               0 kB</code></pre>
  </div>
  <p>
   The nonempty command output indicates that large page support
          is present, but the zero values indicate that no pages are
          configured for use.
  </p>
  <p>
   If your kernel needs to be reconfigured to support large
          pages, consult the
   <code class="filename">
    hugetlbpage.txt
   </code>
   file
          for instructions.
  </p>
  <p>
   Assuming that your Linux kernel has large page support
          enabled, configure it for use by MySQL using the following
          steps:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Determine the number of large pages needed. This is the
              size of the InnoDB buffer pool divided by the large page
              size, which we can calculate as
      <a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_size">
       <code class="literal">
        innodb_buffer_pool_size
       </code>
      </a>
      /
      <code class="literal">
       Hugepagesize
      </code>
      . Assuming the default
              value for the
      <a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_size">
       <code class="literal">
        innodb_buffer_pool_size
       </code>
      </a>
      (128MB) and using the
      <code class="literal">
       Hugepagesize
      </code>
      value obtained from
      <code class="filename">
       /proc/meminfo
      </code>
      (2MB), this is 128MB / 2MB, or 64 Huge Pages. We call this
              value
      <em class="replaceable">
       <code>
        P
       </code>
      </em>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      As system root, open the file
      <code class="filename">
       /etc/sysctl.conf
      </code>
      in a text editor,
              and add the line shown here, where
      <em class="replaceable">
       <code>
        P
       </code>
      </em>
      is the number of large pages
              obtained in the previous step:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa61463335"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token constant">vm.nr_hugepages</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">P</em></span></code></pre>
     </div>
     <p>
      Using the actual value obtained previously, the additional
              line should look like this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa3147095"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token constant">vm.nr_hugepages</span><span class="token attr-value"><span class="token punctuation">=</span>66</span></code></pre>
     </div>
     <p>
      Save the updated file.
     </p>
    </li>
    <li class="listitem">
     <p>
      As system root, run the following command:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa31987450"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-simple">$<span class="token operator">&gt;</span> sudo sysctl <span class="token operator">-</span>p</code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       On some systems the large pages file may be named
                slightly differently; for example, some distributions
                call it
       <code class="filename">
        nr_hugepages
       </code>
       . In the event
       <span class="command">
        <strong>
         sysctl
        </strong>
       </span>
       returns an error
                relating to the file name, check the name of the
                corresponding file in
       <code class="filename">
        /proc/sys/vm
       </code>
       and use that instead.
      </p>
     </div>
     <p>
      To verify the large page configuration, check
      <code class="filename">
       /proc/meminfo
      </code>
      again as described
              previously. Now you should see some additional nonzero
              values in the output, similar to this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa19754463"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">grep</span> <span class="token property">-i</span> huge /proc/meminfo
AnonHugePages<span class="token punctuation">:</span>   2686976 kB
ShmemHugePages<span class="token punctuation">:</span>        0 kB
HugePages_Total<span class="token punctuation">:</span>     233
HugePages_Free<span class="token punctuation">:</span>      233
HugePages_Rsvd<span class="token punctuation">:</span>        0
HugePages_Surp<span class="token punctuation">:</span>        0
Hugepagesize<span class="token punctuation">:</span>       2048 kB
Hugetlb<span class="token punctuation">:</span>          477184 kB</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Optionally, you may wish to compact the Linux VM. You can
              do this using a sequence of commands, possibly in a script
              file, similar to what is shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-bash"><div class="docs-select-all right" id="sa57947087"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-bash"><span class="token function">sync</span>
<span class="token function">sync</span>
<span class="token function">sync</span>
<span class="token keyword">echo</span> 3 <span class="token operator">&gt;</span> /proc/sys/vm/drop_caches
<span class="token keyword">echo</span> 1 <span class="token operator">&gt;</span> /proc/sys/vm/compact_memory</code></pre>
     </div>
     <p>
      See your operating platform documentation for more
              information about how to do this.
     </p>
    </li>
    <li class="listitem">
     <p>
      Check any configuration files such as
      <code class="filename">
       my.cnf
      </code>
      used by the server, and make
              sure that
      <a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_chunk_size">
       <code class="literal">
        innodb_buffer_pool_chunk_size
       </code>
      </a>
      is set larger than the huge page size. The default for
              this variable is 128M.
     </p>
    </li>
    <li class="listitem">
     <p>
      Large page support in the MySQL server is disabled by
              default. To enable it, start the server with
      <a class="link" href="server-options.html#option_mysqld_large-pages">
       <code class="option">
        --large-pages
       </code>
      </a>
      . You can also
              do so by adding the following line to the
      <code class="literal">
       [mysqld]
      </code>
      section of the server
      <code class="filename">
       my.cnf
      </code>
      file:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa62367466"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token constant">large-pages</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre>
     </div>
     <p>
      With this option enabled,
      <code class="literal">
       InnoDB
      </code>
      uses
              large pages automatically for its buffer pool and
              additional memory pool. If
      <code class="literal">
       InnoDB
      </code>
      cannot do this, it falls back to use of traditional memory
              and writes a warning to the error log:
      <span class="errortext">
       Warning:
              Using conventional memory pool
      </span>
      .
     </p>
    </li>
   </ol>
  </div>
  <p>
   You can verify that MySQL is now using large pages by checking
   <code class="filename">
    /proc/meminfo
   </code>
   again after restarting
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   , like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa57815047"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">grep</span> <span class="token property">-i</span> huge /proc/meminfo
AnonHugePages<span class="token punctuation">:</span>   2516992 kB
ShmemHugePages<span class="token punctuation">:</span>        0 kB
HugePages_Total<span class="token punctuation">:</span>     233
HugePages_Free<span class="token punctuation">:</span>      222
HugePages_Rsvd<span class="token punctuation">:</span>       55
HugePages_Surp<span class="token punctuation">:</span>        0
Hugepagesize<span class="token punctuation">:</span>       2048 kB
Hugetlb<span class="token punctuation">:</span>          477184 kB</code></pre>
  </div>
 </div>
 <br/>
</div>
