最近在学mongoDB,安装倒没什么困难,有yum仓库。不过接入ctl后的一条warning倒挺让人烦心的。

2015-03-22T09:27:00.222+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-22T09:27:00.222+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

如果在运行时解决这问题,也不困难,只需要修改hugepage的设置就可以了。执行下面两条命令

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

别忘了重启你的mongoDB,这条warning就消失了。不过下次重新启动系统,这些设置就会消失。

不过想在启动时关掉大内存页面就废了我不少时间了。

首先是网上有人说,把上面的两行命令写入/etc/rc.local,如果是fedora21这样新的系统,应该就是/etc/rc.d/rc.local。不过这无济于事。

我们先看看官方文档怎么说。https://www.kernel.org/doc/Documentation/vm/transhuge.txt 这是关于大内存页面的linux内核文档说明,里面是这样描述如何关闭的。

== Boot parameter ==

You can change the sysfs boot time defaults of Transparent Hugepage
Support by passing the parameter "transparent_hugepage=always" or
"transparent_hugepage=madvise" or "transparent_hugepage=never"
(without "") to the kernel command line.

它说要把 transparent_hugepage=never 这个参数写入 内核命令行(kernel command line)。不过这个内核命令行又在哪里呢。于是继续找,发现了红帽公司的一份补充说明 https://access.redhat.com/solutions/46111 , 里面是这样描述的。

To disable THP at boot time

Append the following to the kernel command line in grub.conf:

transparent_hugepage=never

好了,离真相又更近一步了,不过我的是grub2,所以这篇文章所描述的grub.conf并不存在。继续找,发现了这两篇文章 https://lists.fedoraproject.org/pipermail/users/2012-January/412889.htmlhttp://docs.mongodb.org/manual/reference/transparent-huge-pages/ (mongoDB的官方文档)。这两篇终于看见光明了,为什么我一开始没翻到mongodb的官方文档?果断投诉google,你家的搜索不靠谱啊。前面一篇基本上是正确的,不过下面的命令写错了

grub2-mkconfig /boot/grub2/grub.cfg
应该是
grub2-mkconfig -o /boot/grub2/grub.cfg

不过mongodb的官方文档还留下了这么一句话

See your operating system’s documentation for details on the precise location of the grub-legacy or grub2 configuration file.

所以为了保险起见,我还是认真研读了 http://docs.fedoraproject.org/en-US/Fedora/21/html/System_Administrators_Guide/sec-GRUB_2_over_Serial_Console.html#sec-Configuring_GRUB_2 以防万一。

终于在折腾了一个晚上之后,搞定了。如果你也是grub2的linux系统,请通过以下步骤关闭大内存页面。

step1 编辑 /etc/default/grub,在GRUB_CMDLINE_LINUX加入选项 transparent_hugepage=never

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/swap rd.lvm.lv=fedora/root rhgb quiet transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"

step2 重新生成grub配置文件

On BIOS-based machines, issue the following command as root:
~]# grub2-mkconfig -o /boot/grub2/grub.cfg
On UEFI-based machines, issue the following command as root:
~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

step3 重启你的系统

至此大功告成,如果你使用的是grub,请把选项写入grub.conf文件就好了。

查询hugepage状态,第一种方式

[root@localhost yucanlin]# cat /sys/kernel/mm/transparent_hugepage/enabled 
always madvise [never]
[root@localhost yucanlin]# cat /sys/kernel/mm/transparent_hugepage/defrag 
always madvise [never]

never就对了。

第二种方式

[yucanlin@localhost ~]$ grep Huge /proc/meminfo
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

0就对了。

不过有个小遗憾,重启后我发现 enabled 是never,但defrag却依然是always,不过经过查询meminfo,大内存页面是被禁用了。就不去管他了。

By charlie

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注