Kvm: startup error

Kvm:启动报错:error: internal error: process exited while connecting to monitor: 2020-11-01T01:47:14.993371Z qemu-system-x86_64: cannot set up guest memory ‘pc.ram’: Cannot allocate memory

Obviously, the error report shows that the memory is insufficient and the memory cannot be allocated. Check that the physical machine memory is used normally, and the error is still reported after the virtual machine memory is modified in .xml.

At this time, you need to look at the host to ensure how much memory can be allocated
Insert picture description here

Kernel parameter overcommit_memory

It is a memory allocation strategy

Optional values: 0, 1, 2.
0, means that the kernel will check whether there is enough available memory for the application process; if there is enough available memory, the memory application is allowed; otherwise, the memory application fails and an error is returned to the application process.
1. Indicates that the kernel allows all physical memory to be allocated, regardless of the current memory status.
2. Indicates that the kernel allows the allocation of memory exceeding the sum of all physical memory and swap space

What is Overcommit and OOM

Linux responds "yes" to most requests for memory, so that more and larger programs can be run. Because memory is not used immediately after memory is requested. This technique is called Overcommit. When Linux finds that the memory is insufficient, OOM killer (OOM=out-of-memory) will occur. It will choose to kill some processes (user mode processes, not kernel threads) in order to release memory.

When oom-killer occurs, which processes will Linux choose to kill? The function for selecting the process is the oom_badness function (in mm/oom_kill.c), which calculates the number of points for each process (0~1000). The higher the number of points, the more likely this process is to be killed. The number of points for each process is related to oom_score_adj, and oom_score_adj can be set (-1000 is the lowest, 1000 is the highest).

Solution:

It's very simple, just follow the prompts (set vm.overcommit_memory to 1):

There are three ways to modify kernel parameters, but you must have root privileges:

(1) Edit /etc/sysctl.conf, change vm.overcommit_memory=1, and then sysctl -p to make the configuration file effective

(2)sysctl vm.overcommit_memory=1

(3)echo 1 > /proc/sys/vm/overcommit_memory
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45961525/article/details/109588910