Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Disable Transparent Huge Pages (THP)

On this page

  • Create a Service File
  • Using tuned and ktune

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 enabled, because they tend to have sparse rather than contiguous memory access patterns. When running MongoDB on Linux, THP should be disabled for best performance.

To ensure that THP is disabled before mongod starts, you should create a service file for your platform's initialization system that disables THP at boot. Instructions are provided below for both the systemd and the System V init initialization systems.

Additionally, for RHEL / CentOS systems that make use of ktune and tuned performance profiles, you must create a custom tuned profile as well.

To create a service file that disables THP, you will use the built-in initialization system for your platform. Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command). Refer to the documentation for your operating system for more information.

Use the initialization system appropriate for your platform:

Important

If using tuned or ktune, you must also perform the steps in this section after creating the service file above.

tuned and ktune are dynamic kernel tuning tools that can affect the transparent huge pages setting on your system. If you are using tuned / ktune on your RHEL / CentOS system while running mongod, you must create a custom tuned profile to ensure that THP remains disabled.

1

Create a new profile from an existing profile by copying the relevant directory. This example uses the virtual-guest profile as the base, and uses virtual-guest-no-thp as the new profile:

sudo cp -r /etc/tune-profiles/virtual-guest /etc/tune-profiles/virtual-guest-no-thp
2

Edit /etc/tune-profiles/virtual-guest-no-thp/ktune.sh and change the set_transparent_hugepages setting to the following:

set_transparent_hugepages never
3

Enable the new profile:

sudo tuned-adm profile virtual-guest-no-thp
1

Create a new directory to hold the custom tuned profile. This example inherits from the existing virtual-guest profile, and uses virtual-guest-no-thp as the new profile:

sudo mkdir /etc/tuned/virtual-guest-no-thp
2

Create and edit /etc/tuned/virtual-guest-no-thp/tuned.conf so that it contains the following:

[main]
include=virtual-guest
[vm]
transparent_hugepages=never

This example inherits from the existing virtual-guest profile. Select the profile most appropriate for your system.

3

Enable the new profile:

sudo tuned-adm profile virtual-guest-no-thp
←  Database Profiler OutputManage Sharded Cluster Health with Health Managers →