How to clear the transparent_hugepage warning from the Mongo Console logs

The following instructions are for clearing the following control warnings from MongoDB console:

WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-11-12T07:35:01.030-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'

WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-11-12T08:59:41.969-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'

Description

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.

Disable THP

To ensure that THP is disabled before mongod starts, you should create a new systemd unit:


1-Create the file /etc/systemd/system/disable-thp.service:

[Unit]
Description=Disable Transparent Huge Pages (THP)
[Service]
Type=simple
ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"
[Install]
WantedBy=multi-user.target


2-Enable the new unit:

> sudo systemctl daemon-reload
> sudo systemctl start disable-thp
> sudo systemctl enable disable-thp


3-Restart mongod:


> systemctl restart mongod


THP will now be disabled. However, already allocated huge pages are still active. Rebooting the server is advised to bring up the services with THP disabled.