How to avoid transparent_hugepage/defrag warning from mongodb? How to avoid transparent_hugepage/defrag warning from mongodb? linux linux

How to avoid transparent_hugepage/defrag warning from mongodb?


Official MongoDB documentation gives several solutions for this issue. You can also try this solution, which worked for me:

Note: Try official documentation directives if MongoDB version is greater than 3.0

  1. Open /etc/init.d/mongod file.
    (if no such file you might check /etc/init.d/mongod, /etc/init/mongod.conf files - credit: the below comments)

  2. Add the lines below immediately after chown $DAEMONUSER /var/run/mongodb.pid and before end script.

  3. Restart mongod (service mongod restart).

Here are the lines to add to /etc/init.d/mongod:

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then   echo never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; then   echo never > /sys/kernel/mm/transparent_hugepage/defragfi

That's it!


For Ubuntu 14.04 using upstart:

Since we are deploying machines with Ansible I don't like modifying rc files or GRUB configs.

I tried using sysfsutils / sysfs.conf but ran into timing issues when starting the services on fast (or slow machines). It looked like sometimes mongod was started before sysfsutils. Sometimes it worked, sometimes it did not.

Since mongod is an upstart process I found that the cleanest solution was to add the file /etc/init/mongod_vm_settings.conf with the following content:

# Ubuntu upstart file at /etc/init/mongod_vm_settings.conf##   This file will set the correct kernel VM settings for MongoDB#   This file is maintained in Ansiblestart on (starting mongod)script  echo "never" > /sys/kernel/mm/transparent_hugepage/enabled  echo "never" > /sys/kernel/mm/transparent_hugepage/defragend script

This will run the script just before mongod will be started.Restart mongod (sudo service mongod restart) and done.