I'm receiving the following warning from mongodb about THP
我收到了mongodb关于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
但我确实手动关闭了THP
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
我通过在/etc/default/grub中添加透明的- hugepage=从不到GRUB_CMDLINE_LINUX_DEFAULT,并添加。
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
to /etc/rc.local
对/etc/rc.local
How on earth can I avoid the warning?
我怎么才能避免这种警告呢?
6 个解决方案
#1
159
Official MongoDB documentation gives several solutions for this issue. You can also try this solution, which worked for me:
官方的MongoDB文档为这个问题提供了几个解决方案。你也可以尝试一下这个解决方案,对我很有效:
Note: Try official documentation directives if MongoDB version is greater than 3.0
注意:如果MongoDB版本大于3.0,请尝试官方文档指令
-
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)打开/etc/init.d / mongod文件。(如果没有这样的文件,您可以检查/etc/ initit。d / mongod /etc/init/mongod.conf文件-信贷:以下评论)
-
Add the lines below immediately after
chown $DAEMONUSER /var/run/mongodb.pid
and beforeend script
.在chown $DAEMONUSER /var/run/mongodb之后立即添加下面的行。在结束脚本之前。
- Restart
mongod
(service mongod restart
). - 重启mongod(服务mongod重启)。
Here are the lines to add to /etc/init.d/mongod
:
以下是添加到/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!
就是这样!
#2
24
MongoDB have updated their recommendation to use an init.d script now: http://docs.mongodb.org/master/tutorial/transparent-huge-pages/
MongoDB已经更新了他们的建议来使用init。现在d脚本:http://docs.mongodb.org/master/tutorial/transparent-huge-pages/
#3
10
For Ubuntu 14.04 using upstart:
对于Ubuntu 14.04使用upstart:
Since we are deploying machines with Ansible I don't like modifying rc files or GRUB configs.
由于我们部署的机器是可访问的,所以我不喜欢修改rc文件或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.
我尝试使用sysfsutils / sysfs。但是在快速(或低速机器上)启动服务时遇到了时间问题。看起来有时候《mongod》是在sysfsutils之前开始的。有时行得通,有时行不通。
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:
由于mongod是一个新的进程,我发现最干净的解决方案是添加文件/etc/init/mongod_vm_settings。同意以下内容:
# 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 Ansible
start on (starting mongod)
script
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
end script
This will run the script just before mongod will be started. Restart mongod (sudo service mongod restart
) and done.
这将在mongod开始之前运行脚本。重新启动mongod (sudo服务mongod重启)并完成。
#4
8
-
Open /etc/default/grub
打开/etc/default/grub
sudo vi /etc/default/grub
sudo vi /etc/default/grub
-
Update
GRUB_CMDLINE_LINUX_DEFAULT="" to GRUB_CMDLINE_LINUX_DEFAULT="transparent_hugepage=never"更新GRUB_CMDLINE_LINUX_DEFAULT = " " GRUB_CMDLINE_LINUX_DEFAULT =“transparent_hugepage =永远”
- Save file
:wq (in vi) - 保存文件:wq (vi)
-
Run update-grub
运行update-grub
sudo update-grub
sudo update-grub
-
Reboot machine
重新启动机器
Update: If you are using a virtual hosting provider, this will work IFF grub boot is supported. DigitalOcean DOES NOT support grub boot.
更新:如果您正在使用虚拟主机提供程序,则支持IFF grub boot。DigitalOcean不支持grub boot。
#5
5
Verified that the defrag is examined without regard to the enabled:
验证defrag是在不考虑启用的情况下进行检查的:
$ cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
$ cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
$ service mongod start
... (in log) WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'
$ echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
$ cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
$ service mongod stop
$ service mongod start
... (no warning in log)
Therefore, the fix to this bug is to first look at transparent_hugepage/enabled, and if it is never, don't bother looking at the irrelevant transparent_hugepage/defrag setting.
因此,对这个bug的修复是首先查看透明的hugepage/启用的,如果它是永远的,就不要费心去查看无关的透明的hugepage/defrag设置。
源。
#6
0
Ubuntu 16.04 using systemd:
Ubuntu 16.04使用systemd:
systemctl edit mongod
systemctl编辑mongod
Paste the following:
粘贴如下:
[Service]
PermissionsStartOnly=true
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/defrag"
#1
159
Official MongoDB documentation gives several solutions for this issue. You can also try this solution, which worked for me:
官方的MongoDB文档为这个问题提供了几个解决方案。你也可以尝试一下这个解决方案,对我很有效:
Note: Try official documentation directives if MongoDB version is greater than 3.0
注意:如果MongoDB版本大于3.0,请尝试官方文档指令
-
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)打开/etc/init.d / mongod文件。(如果没有这样的文件,您可以检查/etc/ initit。d / mongod /etc/init/mongod.conf文件-信贷:以下评论)
-
Add the lines below immediately after
chown $DAEMONUSER /var/run/mongodb.pid
and beforeend script
.在chown $DAEMONUSER /var/run/mongodb之后立即添加下面的行。在结束脚本之前。
- Restart
mongod
(service mongod restart
). - 重启mongod(服务mongod重启)。
Here are the lines to add to /etc/init.d/mongod
:
以下是添加到/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!
就是这样!
#2
24
MongoDB have updated their recommendation to use an init.d script now: http://docs.mongodb.org/master/tutorial/transparent-huge-pages/
MongoDB已经更新了他们的建议来使用init。现在d脚本:http://docs.mongodb.org/master/tutorial/transparent-huge-pages/
#3
10
For Ubuntu 14.04 using upstart:
对于Ubuntu 14.04使用upstart:
Since we are deploying machines with Ansible I don't like modifying rc files or GRUB configs.
由于我们部署的机器是可访问的,所以我不喜欢修改rc文件或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.
我尝试使用sysfsutils / sysfs。但是在快速(或低速机器上)启动服务时遇到了时间问题。看起来有时候《mongod》是在sysfsutils之前开始的。有时行得通,有时行不通。
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:
由于mongod是一个新的进程,我发现最干净的解决方案是添加文件/etc/init/mongod_vm_settings。同意以下内容:
# 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 Ansible
start on (starting mongod)
script
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
end script
This will run the script just before mongod will be started. Restart mongod (sudo service mongod restart
) and done.
这将在mongod开始之前运行脚本。重新启动mongod (sudo服务mongod重启)并完成。
#4
8
-
Open /etc/default/grub
打开/etc/default/grub
sudo vi /etc/default/grub
sudo vi /etc/default/grub
-
Update
GRUB_CMDLINE_LINUX_DEFAULT="" to GRUB_CMDLINE_LINUX_DEFAULT="transparent_hugepage=never"更新GRUB_CMDLINE_LINUX_DEFAULT = " " GRUB_CMDLINE_LINUX_DEFAULT =“transparent_hugepage =永远”
- Save file
:wq (in vi) - 保存文件:wq (vi)
-
Run update-grub
运行update-grub
sudo update-grub
sudo update-grub
-
Reboot machine
重新启动机器
Update: If you are using a virtual hosting provider, this will work IFF grub boot is supported. DigitalOcean DOES NOT support grub boot.
更新:如果您正在使用虚拟主机提供程序,则支持IFF grub boot。DigitalOcean不支持grub boot。
#5
5
Verified that the defrag is examined without regard to the enabled:
验证defrag是在不考虑启用的情况下进行检查的:
$ cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
$ cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
$ service mongod start
... (in log) WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'
$ echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
$ cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
$ service mongod stop
$ service mongod start
... (no warning in log)
Therefore, the fix to this bug is to first look at transparent_hugepage/enabled, and if it is never, don't bother looking at the irrelevant transparent_hugepage/defrag setting.
因此,对这个bug的修复是首先查看透明的hugepage/启用的,如果它是永远的,就不要费心去查看无关的透明的hugepage/defrag设置。
源。
#6
0
Ubuntu 16.04 using systemd:
Ubuntu 16.04使用systemd:
systemctl edit mongod
systemctl编辑mongod
Paste the following:
粘贴如下:
[Service]
PermissionsStartOnly=true
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
ExecStartPre=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/defrag"