最近在學mongoDB,安裝倒沒什么困難,有yum倉庫。不過接入ctl后的一條warning倒挺讓人煩心的。
1
2
|
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的設置就可以了。執行下面兩條命令
1
2
|
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內核文檔說明,里面是這樣描述如何關閉的。
1
2
3
4
5
6
|
== 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 , 里面是這樣描述的。
1
2
3
4
5
|
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.html 跟 http://docs.mongodb.org/manual/reference/transparent-huge-pages/(mongoDB的官方文檔)。這兩篇終於看見光明了,為什么我一開始沒翻到mongodb的官方文檔?果斷投訴google,你家的搜索不靠譜啊。前面一篇基本上是正確的,不過下面的命令寫錯了
1
2
3
|
grub2-mkconfig
/boot/grub2/grub
.cfg
應該是
grub2-mkconfig -o
/boot/grub2/grub
.cfg
|
不過mongodb的官方文檔還留下了這么一句話
1
|
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
1
2
3
4
5
6
7
|
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配置文件
1
2
3
4
|
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狀態,第一種方式
1
2
3
4
|
[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就對了。
第二種方式
1
2
3
4
5
6
7
|
[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,大內存頁面是被禁用了。就不去管他了。