Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

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

I'm receiving the following warning from mongodb about THP

2015-03-06T21:01:15.526-0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-06T21:01:15.526-0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

But I did manage to turned THP off manually

frederick@UbuntuVirtual:~$ cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
frederick@UbuntuVirtual:~$ cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

I did the trick by adding transparent_hugepage=never to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub and adding

if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

to /etc/rc.local

How on earth can I avoid the warning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

That's it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...