Here is my current setting:

vm.overcommit_ratio = 50 (default)
vm.overcommit_memory = 2

And Current Memory Usage:

[localhost~]$ free -g
             total       used       free     shared    buffers     cached
Mem:            47         46          0          0          0         45
-/+ buffers/cache:          1         45
Swap:           47          0         47

As per the documentation what I understood is:

vm.overcommit_memory = 2 will not allow to overcommit memory than 50 % of RAM (as vm.overcommit_ratio is 50) but still I can see that current memory usage is 46 GB out of 47 GB.

Did I misunderstood anything?

  • you added this to /etc/sysctl.confand run sysctl -p and verified the settings with sysctl -a right? – Michael D. Mar 1 '17 at 15:38
  • 46 GB out of 94 GB doesn't seem like anything has been committed over. Though I don't think free can show you how much virtual memory has been allocated, anyway. – ilkkachu Mar 1 '17 at 15:46

Actually, setting vm.overcommit_memory=2 DOES allow overcommit. If you set overcommit_ratio to (say) 200, then memory can be committed to the extent of swap +(RAM * 200/100).

The kernel documentation is slightly misleading in implying that '2' means don't overcommit - it means commit to this limit, which in the case of overcommit_ratio (and that's a misnomer as it's really a percentage) being greater than 100, does allow for overcommit.

vm.overcommit_memory is more accurately described as setting a limit to overcommit, which by default doesn't allow any overcommit.

You can see the commit limit:

    $free -m | awk '$1 ~/[Mm]em/ {print $2}' ; sysctl -a 2>/dev/null | grep vm.over  ; grep -i commitlimit /proc/meminfo

vm.overcommit_kbytes = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 800
CommitLimit:    23449596 kB

The vm.overcommit_* settings control userspace memory allocation. They have no effect on the memory the kernel can allocate. Additionally the value you are taking 50% of is physical memory + swap. 47+47=94. So userspace can allocate up to 47gb.

Your free output shows you have 1gb used by userspace, and 45gb used by the kernel for caching. 1gb userspace is well under 50% of 94gb.

Additional correction:

vm.overcommit_memory = 2 will not allow to overcommit memory than 50 % of RAM

This setting will not allow overcommit at all. Combined with vm.overcommit_ratio=50, it will allow userspace to commit up to 50% of total memory. "commit" != "overcommit"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.