这是Linux内核或系统管理员的问题。尽管免费报告“可用”,但“无法分配内存”
我从QEMU这个错误,尝试启动虚拟机与3GB内存:
ioctl(KVM_CREATE_VM) failed: 12 Cannot allocate memory
failed to initialize KVM: Cannot allocate memory
据我所知,这可能是因为没有足够的内存或提交限制太低,但显然不是......有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
于是我就写了一个C++程序来分配先后更大的块。我发现它未能分配超过2.1 GB。 (N.B.它被编译为64位)。这与Qemu没有启动一致,但为什么?
然后我修改它写入内存。这导致一些缓存被倾倒,提供免费的报告,在这个分配约2 GB:
$ free -m
total used free shared buff/cache available
Mem: 7696 2988 288 143 4420 4268
Swap: 2892 525 2367
...这在程序终止:
$ free -m
total used free shared buff/cache available
Mem: 7696 1258 2253 147 4185 5994
Swap: 2892 525 2367
现在我试图启动的Qemu和神奇有效!免费报告:
$ free -m
total used free shared buff/cache available
Mem: 7696 2438 4451 147 806 4834
Swap: 2892 530 2362
所以看起来内核不愿意当问一大块释放一些缓存,但是愿意让他们在几个步骤走。这是怎么回事?
我运行Debian测试: 的Linux - 4.11.0-1-AMD64#1 SMP的Debian 4.11.6-1(2017年6月19日)x86_64的GNU/Linux的