解决 redis 4 启动日志中的 2 个警告问题
redis | 1:M 18 Oct 08:33:10.456 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis | 1:M 18 Oct 08:33:10.456 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
解决 overcommit_memory
立即生效
sysctl vm.overcommit_memory=1
重启后生效
将 'vm.overcommit_memory = 1' 添加到 /etc/sysctl.conf 中
关闭 Transparent HugePages
查询系统 THP 状态
cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
cat /sys/kernel/mm/transparent_hugepage/defrag
always defer defer+madvise madvise [never]
关闭 THP 立即生效
echo never >> /sys/kernel/mm/transparent_hugepage/enabled
echo never >> /sys/kernel/mm/transparent_hugepage/defrag
关闭 THP 重启后生效
cat >> /etc/rc.local << EOF
# disable THP
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
EOF