Skip to content
Advertisement

Can’t Write to /sys/kernel/ to disable Transparent Huge Pages (THP) for MongoDB on OVH CentOS 7

My Issue

I am having trouble removing MongoDB warnings about Transparent Huge Pages (THP) on an OVH CentOS 7 installation, and the issue appears to be the inability to write to /sys/kernel/mm as root.

First, I realize the OVH kernel is customized, and I know many of you will say to go with a fresh non-customized kernel, but that’s not an option right now. I need to solve this problem for the current OS.

MongoDB Warnings:

2016-03-09T00:31:45.889-0500 W CONTROL  [initandlisten] Failed to probe "/sys/kernel/mm/transparent_hugepage": Permission denied
2016-03-09T00:31:45.889-0500 W CONTROL  [initandlisten] Failed to probe "/sys/kernel/mm/transparent_hugepage": Permission denied

MongoDB is trying to read the transparent_hugepage files (below), but they do not exist:

/sys/kernel/mm/transparent_hugepage/enabled
/sys/kernel/mm/transparent_hugepage/defrag

Cannot Create the Files

All of the solutions I’ve seen involve creating the files and populating them with never, including the script in the MongoDB documentation. In all of the solutions, this is the key part:

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

However, the files do not exist, and I cannot create anything under /sys/kernel/mm as root.

root@myhost [~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
-bash: /sys/kernel/mm/transparent_hugepage/enabled: No such file or directory

root@myhost [~]# mkdir -p /sys/kernel/mm/transparent_hugepage
mkdir: cannot create directory ‘/sys/kernel/mm/transparent_hugepage’: Operation not permitted

The owner and group of directory /sys/kernel/mm are root, and I have temporarily changed the permissions from 700 to 777, yet I still cannot create the directory as root.

Tuned Profile Also Doesn’t Help

To be thorough, I have also created the custom Tuned profile (per instructions in MongoDB link above) and activated it, but it generates the error WARNING tuned.plugins.plugin_vm: Option 'transparent_hugepages' is not supported on current hardware.

Tuned Profile (/etc/tuned/no-thp/tuned.conf):

[main]
include=virtual-guest

[vm]
transparent_hugepages=never

Error in Tuned log:

WARNING  tuned.plugins.plugin_vm: Option 'transparent_hugepages' is not supported on current hardware.

Some Solution in MongoDB Itself?

It seems like the best solution would be to somehow explicitly configure MongoDB not to use THP so that it wouldn’t have to check for the missing files, but I’ve seen nothing like this. If there is a way, even if it involves customizing MongoDB (and repeating after every update), I’m willing to do it.

Advertisement

Answer

Right now I’ve installed CentOS 7 on OVH. They use /boot/bzImage-3.14.32-xxxx-grs-ipv6-64 that implements grsecurity (https://grsecurity.net) which precludes access to some folders.

The very simple solution to the warnings from MongoDB about huge pages can be solved by replacing the kernel. The procedure for CentOS7 is as follows:

  1. Download required kernel from OVH ftp: ftp://ftp.ovh.net/made-in-ovh/bzImage2 into /boot folder.
  2. Edit /etc/grub2.cfg:

    # linux /boot/bzImage-3.14.32-xxxx-grs-ipv6-64 root=/dev/md1 ro net.ifnames=0

    linux /boot/bzImage-4.8.17-xxxx-std-ipv6-64 root=/dev/md1 ro net.ifnames=0

Here I replaced bzImage-3.14.32-xxxx-grs-ipv6-64 default by bzImage-4.8.17-xxxx-std-ipv6-64 without grs.

Now, reboot and check if the new kernel is ok:

root@ns506846 ~]# uname -r
4.8.17-xxxx-std-ipv6-64
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement