Home > mongodb > mongo shell: WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’

mongo shell: WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’

You start the mongo shell (with the command “mongo“) and you get some warnings:

MongoDB shell version: 3.0.0
connecting to: test
Server has startup warnings:
2015-03-13T16:28:29.405+0800 I CONTROL  [initandlisten]
2015-03-13T16:28:29.406+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-03-13T16:28:29.406+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-03-13T16:28:29.406+0800 I CONTROL  [initandlisten]
2015-03-13T16:28:29.407+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-13T16:28:29.407+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-03-13T16:28:29.407+0800 I CONTROL  [initandlisten]

How to get rid of these warnings?

This issue is addressed at http://docs.mongodb.org/manual/tutorial/transparent-huge-pages/#transparent-huge-pages-thp-settings . Here they explain what to do under Ubuntu.

Update (20160329): The method above didn’t work for me under Ubuntu 14.04 with Mongo 3.2.4. Here is method that did work: http://stackoverflow.com/a/29181918/232485. It should also work with Manjaro, so first try this trick.

But what about Manjaro? ;)

First, follow the steps of this post: https://ubuntuincident.wordpress.com/2015/08/11/manjaro-run-a-command-at-startup-as-root/ . Here it is explained how to create a script that is executed at startup. When ready, go on with the following operations:

Create the file /etc/rc.d/disable-transparent-hugepages with this content (copied from here):

#!/usr/bin/env sh

# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.

case $1 in
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      return 0

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    unset thp_path

Make it executable (chmod u+x). Then edit /etc/rc.d/rc.local and add the previous script to it. Mine looks like this:

#!/usr/bin/env bash

/etc/rc.d/disable-transparent-hugepages start

Next time you reboot and start mongo you won’t see the warnings.

Categories: mongodb Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: