- Administration >
- Administration Tutorials >
- Configuration, Maintenance, and Analysis >
- Disable Transparent Huge Pages (THP)
Disable Transparent Huge Pages (THP)¶
On this page
Transparent Huge Pages (THP) is a Linux memory management system that reduces the overhead of Translation Lookaside Buffer (TLB) lookups on machines with large amounts of memory by using larger memory pages.
However, database workloads often perform poorly with THP, because they tend to have sparse rather than contiguous memory access patterns. You should disable THP on Linux machines to ensure best performance with MongoDB.
Init Script¶
Important
If you are using tuned
or ktune
(for example, if you are running
Red Hat or CentOS 6+), you must additionally configure them so that THP is
not re-enabled. See Using tuned and ktune.
Create the init.d
script.¶
Create the following file at /etc/init.d/disable-transparent-hugepages
:
Make it executable.¶
Run the following command to ensure that the init script can be used:
Configure your operating system to run it on boot.¶
Use the appropriate command to configure the new init script on your Linux distribution.
Distribution | Command |
---|---|
Ubuntu and Debian | sudo update-rc.d disable-transparent-hugepages defaults
|
SUSE | sudo insserv /etc/init.d/disable-transparent-hugepages
|
Red Hat, CentOS, Amazon Linux, and derivatives | sudo chkconfig --add disable-transparent-hugepages
|
Override tuned and ktune, if applicable¶
If you are using tuned
or ktune
(for example, if you are running
Red Hat or CentOS 6+) you must now configure them to preserve the above
settings.
Using tuned
and ktune
¶
Important
If using tuned
or ktune
, you must perform this step in addition
to installing the init script.
tuned
and ktune
are dynamic kernel tuning tools available on Red Hat
and CentOS that can disable transparent huge pages.
To disable transparent huge pages in tuned
or ktune
, you need to edit or
create a new profile that sets THP to never
.
Red Hat/CentOS 6¶
Create a new profile.¶
Create a new profile from an existing default
profile by copying the relevant directory. In the example we use
the default
profile as the base and call our new profile no-thp
.
Edit ktune.sh
.¶
Edit /etc/tune-profiles/no-thp/ktune.sh
and add the following:
to the start()
block of the file, before the return 0
statement.
Enable the new profile.¶
Finally, enable the new profile by issuing:
Test Your Changes¶
You can check the status of THP support by issuing the following commands:
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
On Red Hat Enterprise Linux, CentOS, and potentially other Red Hat-based derivatives, you may instead need to use the following:
cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
cat /sys/kernel/mm/redhat_transparent_hugepage/defrag
For both files, the correct output resembles:
always madvise [never]