My Profile Photo

Sheogorath's Blog

Linux memory management

Today I learned that memory over-commitment in Linux is a rather complicated topic. The first thing is that there are 3 modes for memory over-commitment (/proc/sys/vm/overcommit_memory) in the kernel which range from 0 which tries to determine how much of the allocated memory an application actually uses and allow over-commitment to 2 which requires the kernel to have enough free memory for each memory allocation that is happening in the system. Important to know is, that while the former option ignores the over-commit ration (/proc/sys/vm/overcommit_ratio), the latter takes it very seriously and use Swap + RAM * (overcommit_memory / 100) as total memory limit. Which means while overcommit_memory mode 0 provides more memory than your system has to offer, mode 2 might leaves multiple gigabyte of memory unused if not adjusted to your needs.

I came across this after having my system killing my GNOME shell when starting a VM which I assigned 6GB of RAM, while only having 4GB of free memory available. After that the OOM killer decided to go on a rampage and kill various programs, including the GNOME shell which killed my entire user session. Doing my research I came across some quite interesting articles which explained some of the backgrounds. Now I’m experimenting with some settings to improve the memory management on my system.