理解overcommit_memory

Redis在启动的时候会报如下WARNING

WARNING overcommit_memory is set to 0! Background save may failunder low memory condition.
To fix this issue add 'vm.overcommit_memory = 1'to /etc/sysctl.conf and then reboot or run the command 'sysctlvm.overcommit_memory=1' for this to take effect.

Linux这个参数默认是0,因此会报这个WARNING,参数的意思参考:https://www.kernel.org/doc/Documentation/vm/overcommit-accounting,前不久线上JVM出现一个问题就是和这个参数相关:java虚拟机启动失败

java -Xmx20g -version

Error occurred during initialization of VM

Could not reserve enough space for object heap

Could not create the Java virtual machine.

但是给10g的时候就OK

java -Xmx10g -version

java version "1.6.0_37"

Java(TM) SE Runtime Environment (build 1.6.0_37-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)

内存明明是够的,后来发现在这台服务器上overcommit_memory被设置了2

cat /proc/meminfo |grep -i commit
CommitLimit(=memory*overcommit_ratio+swap):49744512 kB
Committed_AS: 33947660 kB

从上面可知只能再分配不到14GB的空间,因此也就解释了上面的这个错误,后改成0解决;


你可能感兴趣的:(redis,jvm,overcommit)