overcommit_memory and overcommit_ratio

5,370

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
Share:
5,370

Related videos on Youtube

pgyogesh
Author by

pgyogesh

Updated on September 18, 2022

Comments

  • pgyogesh
    pgyogesh over 1 year

    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?

    • Michael D.
      Michael D. about 7 years
      you added this to /etc/sysctl.confand run sysctl -p and verified the settings with sysctl -a right?
    • ilkkachu
      ilkkachu about 7 years
      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.