这是一个Linux内核或sys管理大师的问题.
我从qemu收到此错误,试图启动一个3GB内存的VM:
ioctl(KVM_CREATE_VM) failed: 12 Cannot allocate memory
failed to initialize KVM: Cannot allocate memory
Run Code Online (Sandbox Code Playgroud)
据我所知,这可能是因为没有足够的内存或提交限制太低,但显然不是......通过转储缓存而没有提交限制可用5.9 GB:
$ free -m
total used free shared buff/cache available
Mem: 7696 1287 135 139 6274 5973
Swap: 2892 525 2367
$ cat /proc/sys/vm/overcommit_memory
1
Run Code Online (Sandbox Code Playgroud)
然后我写了一个c ++程序来连续分配更大的块.我发现它未能分配超过2.1 GB.(注意它被编译为64位.)这与Qemu没有启动一致,但为什么???
所以我修改了它以写入内存.这导致一些缓存被转储,免费报告大约2 GB分配:
$ free -m
total used free shared buff/cache available
Mem: 7696 2988 288 143 4420 4268
Swap: 2892 525 2367
Run Code Online (Sandbox Code Playgroud)
......当程序终止时:
$ free -m
total used free shared buff/cache available
Mem: 7696 1258 2253 …Run Code Online (Sandbox Code Playgroud)