Skip to content

Commit cf30924

Browse files
i80andkay-kim
authored andcommitted
DOCS-5330: Tweak THP guide
Signed-off-by: kay <kay.kim@10gen.com>
1 parent 277d970 commit cf30924

7 files changed

+183
-148
lines changed

source/includes/steps-disable-thp-in-grub.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
title: Create the ``init.d`` script
2+
stepnum: 1
3+
ref: create-initd
4+
action:
5+
- pre: |
6+
Create the following file at ``/etc/init.d/disable-transparent-hugepages``:
7+
8+
language: sh
9+
code: |
10+
#!/bin/sh
11+
### BEGIN INIT INFO
12+
# Provides: disable-transparent-hugepages
13+
# Required-Start: $local_fs
14+
# Required-Stop:
15+
# X-Start-Before: mongod mongodb-mms-automation-agent
16+
# Default-Start: 2 3 4 5
17+
# Default-Stop: 0 1 6
18+
# Short-Description: Disable Linux transparent huge pages
19+
# Description: Disable Linux transparent huge pages, to improve
20+
# database performance.
21+
### END INIT INFO
22+
23+
case $1 in
24+
start)
25+
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
26+
thp_path=/sys/kernel/mm/transparent_hugepage
27+
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
28+
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
29+
else
30+
return 0
31+
fi
32+
33+
echo 'never' > ${thp_path}/enabled
34+
echo 'never' > ${thp_path}/defrag
35+
36+
unset thp_path
37+
;;
38+
esac
39+
---
40+
title: Make it executable
41+
stepnum: 2
42+
ref: make-executable
43+
action:
44+
- pre: |
45+
Run the following command to ensure that the init script can be used:
46+
47+
language: sh
48+
code: sudo chmod 755 /etc/init.d/disable-transparent-hugepages
49+
---
50+
title: Configure your operating system to run it on boot
51+
stepnum: 3
52+
ref: configure-initd
53+
action:
54+
- pre: |
55+
Use the appropriate command to configure the new init script on your Linux
56+
distribution.
57+
58+
.. list-table::
59+
:header-rows: 1
60+
:widths: 20 80
61+
62+
* - Distribution
63+
64+
- Command
65+
66+
* - Ubuntu and Debian
67+
68+
- .. code:: sh
69+
70+
sudo update-rc.d disable-transparent-hugepages defaults
71+
72+
* - SUSE
73+
74+
- .. code:: sh
75+
76+
sudo insserv /etc/init.d/disable-transparent-hugepages
77+
78+
* - Red Hat, CentOS, Amazon Linux, and derivatives
79+
80+
- .. code:: sh
81+
82+
sudo chkconfig --add disable-transparent-hugepages
83+
...

source/includes/steps-disable-thp-in-ktune.yaml

Lines changed: 0 additions & 51 deletions
This file was deleted.

source/includes/steps-disable-thp-in-rc.local.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
title: Create a new profile
2+
stepnum: 1
3+
ref: copy-profile
4+
action:
5+
- pre: |
6+
Create a new profile from an existing default
7+
profile by copying the relevant directory. In the example we use
8+
the ``default`` profile as the base and call our new profile ``no-thp``.
9+
language: sh
10+
code: |
11+
sudo cp -r /etc/tune-profiles/default /etc/tune-profiles/no-thp
12+
---
13+
title: Edit ``ktune.sh``
14+
stepnum: 2
15+
ref: edit-ktune
16+
action:
17+
- pre: |
18+
Edit ``/etc/tune-profiles/no-thp/ktune.sh`` and add the following:
19+
language: cfg
20+
code: |
21+
set_transparent_hugepages never
22+
post: |
23+
to the ``start()`` block of the file, before the ``return 0``
24+
statement.
25+
---
26+
title: Enable the new profile
27+
stepnum: 3
28+
ref: enable-profile
29+
action:
30+
- pre: |
31+
Finally, enable the new profile by issuing:
32+
language: sh
33+
code: |
34+
sudo tune-adm profile no-thp
35+
...
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
title: Create a new profile
2+
stepnum: 1
3+
ref: copy-profile
4+
action:
5+
- pre: |
6+
Create a new ``tuned`` profile directory:
7+
language: sh
8+
code: |
9+
sudo mkdir /etc/tuned/no-thp
10+
---
11+
title: Edit ``tuned.conf``
12+
stepnum: 2
13+
ref: edit-ktune
14+
action:
15+
- pre: |
16+
Create and edit ``/etc/tuned/no-thp/tuned.conf`` so that it contains the
17+
following:
18+
language: ini
19+
code: |
20+
[main]
21+
include=virtual-guest
22+
23+
[vm]
24+
transparent_hugepages=never
25+
---
26+
stepnum: 3
27+
source:
28+
file: steps-disable-thp-in-tuned-rhel-6.yaml
29+
ref: enable-profile
30+
...

source/tutorial/transparent-huge-pages.txt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,66 @@ Disable Transparent Huge Pages (THP)
44

55
.. default-domain:: mongodb
66

7-
Transparent Huge Pages (THP) is a Linux memory management kernel
8-
module used to reduce the overhead of Translation Lookaside Buffer
9-
(TLB) lookups on machines with large amounts of memory, and therefore
10-
a large number of memory pages. In effect, it presents system memory
11-
as a smaller number of much larger pages rather than as a larger
12-
number of 4096-byte pages.
7+
Transparent Huge Pages (THP) is a Linux memory management system
8+
that reduces the overhead of Translation Lookaside Buffer (TLB) lookups on
9+
machines with large amounts of memory by using larger memory pages.
1310

14-
However, THP is known to perform poorly under database workloads,
15-
which tend to have sparse rather than contiguous memory access
16-
patterns. You must disable THP on Linux machines used to run MongoDB
17-
instances to ensure best performance.
11+
However, database workloads often perform poorly with THP,
12+
because they tend to have sparse rather than contiguous memory access
13+
patterns. You should disable THP on Linux machines to ensure best performance
14+
with MongoDB.
1815

19-
There are three ways to disable Transparent Huge Pages on Linux.
16+
Init Script
17+
-----------
2018

21-
In Boot-Time Configuration (Preferred)
22-
--------------------------------------
19+
.. include:: /includes/steps/disable-thp-in-initd.rst
2320

24-
.. include:: /includes/steps/disable-thp-in-grub.rst
21+
Using ``tuned`` and ``ktune``
22+
-----------------------------
2523

26-
Using ``tuned`` and ``ktune`` (Necessary if you use ``tuned``)
27-
--------------------------------------------------------------
24+
.. important::
2825

29-
``tuned`` and ``ktune`` are dynamic kernel tuning tools that act in
30-
accordance with policies set by the system administrator. One of the
31-
settings available to ``tuned`` and ``ktune`` is whether or not to use
32-
THP.
26+
If installed, you must configure ``tuned`` and ``ktune`` to prevent them from
27+
re-enabling THP.
3328

34-
To disable transparent hugepages, you need to edit or create a new
35-
profile that sets THP to ``never``.
29+
``tuned`` and ``ktune`` are dynamic kernel tuning tools available on Red Hat
30+
and CentOS that can disable transparent huge pages.
3631

37-
.. include:: /includes/steps/disable-thp-in-ktune.rst
32+
To disable transparent huge pages in ``tuned`` or ``ktune``, you need to edit or
33+
create a new profile that sets THP to ``never``.
3834

39-
In ``/etc/rc.local`` (Alternate)
40-
--------------------------------
35+
Red Hat/CentOS 6
36+
~~~~~~~~~~~~~~~~
4137

42-
.. include:: /includes/steps/disable-thp-in-rc.local.rst
38+
.. include:: /includes/steps/disable-thp-in-tuned-rhel-6.rst
39+
40+
Red Hat/CentOS 7
41+
~~~~~~~~~~~~~~~~
42+
43+
.. include:: /includes/steps/disable-thp-in-tuned-rhel-7.rst
44+
45+
.. _test-thp-changes:
4346

4447
Test Your Changes
4548
-----------------
4649

47-
Whichever of the three methods you use, you can check the status of THP support by issuing the command:
50+
You can check the status of THP support by issuing the following commands:
4851

4952
.. code:: sh
5053

5154
cat /sys/kernel/mm/transparent_hugepage/enabled
55+
cat /sys/kernel/mm/transparent_hugepage/defrag
5256

53-
or
57+
On Red Hat Enterprise Linux, CentOS, and potentially other Red
58+
Hat-based derivatives, you may instead need to use the following:
5459

5560
.. code:: sh
5661

5762
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
63+
cat /sys/kernel/mm/redhat_transparent_hugepage/defrag
5864

59-
on Red Hat Enterprise Linux, CentOS, and potentially other Red
60-
Hat-based derivatives.
6165

62-
Correct output resembles:
66+
For both files, the correct output resembles:
6367

6468
.. code:: sh
6569

0 commit comments

Comments
 (0)