Kvm internal error: process exited :cannot set up guest memory ‘pc.ram‘:Cannot allocate memory

An error message indicates that the memory is insufficient and cannot be allocated. Check that the physical machine memory is used normally. After modifying the virtual machine memory, an error message is still reported when starting

report errors:

At this time, you need to see how much memory the host can allocate

sysctl -a | grep overcommit

Kernel parameter overcommit_ memory  

It is   Memory allocation strategy

Optional values: 0, 1, 2
0 indicates that the kernel will check whether there is enough available memory for processes to use; If there is enough available memory, the memory application is allowed; Otherwise, the memory request fails and the error is returned to the application process
1 indicates that the kernel is allowed to allocate all physical memory regardless of the current memory state
2 indicates that the kernel allows to allocate more memory than the sum of all physical memory and swap space

What are overcommit and oom

     Linux replies “yes” to most requests for memory so that it can run more and larger programs. Because after applying for memory, memory will not be used immediately. This technology is called overcommit. When Linux finds that there is insufficient memory, an oom killer (OOM = out of memory) occurs. It will choose to kill some processes (user state processes, not kernel threads) to free memory.

     When oom killer happens, which processes will Linux choose to kill?The function to select a process is oom_ Badness function (in mm/oom_kill. C), which calculates the number of points (0 ~ 1000) for each process. The higher the number of points, the more likely the process is to be killed. The number of points per process is the same as oom_ score_ Adj related, and OOM_ score_ Adj can be set (- 1000 min, 1000 max).


      Simply follow the prompts (set vm.overcommit_memory to 1):

      There are three ways to modify kernel parameters, but with root permission:

    (1) Edit/etc/sysctl.conf to vm.overcommit_ Memory = 1, then sysctl – P makes the configuration file effective

  (2)sysctl vm.overcommit_ memory=1

  (3)echo 1 >/proc/sys/vm/overcommit_ memory

Read More: