Kernel – How to Modify /sys/kernel/mm/transparent_hugepage/enabled

16.04kernelmongodbsysfssystemd

I use mongodb 3.0 and I find a warning:

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]

~# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

~# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never

I try to use echo, but it's not permanent, after reboot it will be reset.

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

How do I modify /sys/kernel/mm/transparent_hugepage/enabled permanently?

Best Answer

You can

  1. install the sysfsutils package:

    sudo apt install sysfsutils
    
  2. and append a line with that setting to /etc/sysfs.conf:

    kernel/mm/transparent_hugepage/enabled = never
    

This is the cleanest solution, because it keeps all the sysfs configuration in one place instead of relying on custom start-up scripts. The other answers, with the scripts and conditional expressions, are suitable if you don't know through which path the kernel will expose that setting, i. e. if you don't even have a rough idea of the kernel version running on the affected machine.

Related Question