linux memory overcommit

Memory overcommit can be disabled by vm.memory_overcommit=2

0 is the default mode, where kernel heuristically determines the allocation by calculating the free memory compared to the allocation request being made. And setting it to 1 enables the wizardry mode, where kernel always advertises that it has enough free memory for any allocation. Setting to 2, means that processes can only allocate upto (RAM+swap) and will start getting allocation failure or OOM messages when it goes beyond that amount.

Is it safe to do so, no. I haven’t seen any proper use case where disabling memory overcommit actually helped, unless you are 100% certain of the workload and hardware capacity. In case you are interested, install kernel-docs package and go to /Documentation/sysctl/vm.txt to read more.

If you set overcommit=2 then you don’t have to worry about overcommit_ratio.

echo 0/1/2 > /proc/sys/vm/overcommit_memory 

This will not survive a reboot. For persistence, put this in /etc/sysctl.conf file

vm.overcommit_memory=X

and run sysctl -p. No need to reboot

Leave a Reply

Your email address will not be published. Required fields are marked *