我的操作系统是 arch linux 64 位。
free -m 结果如下
total used free shared buffers cached Mem: 32172 31909 262 0 119 13054 -/+ buffers/cache: 18735 13436 Swap: 258 258 0
ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 20 file size (blocks, -f) unlimited pending signals (-i) 257329 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 257329 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
kenerl 选项 overcommit_memroy 为 0
但是当我尝试使用 malloc 分配 2G 字节时,我失败了,原因是:无法分配内存?
最佳答案
实际上,它可以是任何东西。它可能以前有效,因为可用内存都是连续的,而现在可用内存不是连续的,或者可能是您的内存请求未通过正在使用的试探法。
请在此处查看此链接 - http://linuxtoolkit.blogspot.com/2011/08/tweaking-linux-kernel-overcommit.html - 有关转变过度使用的更多信息。
基本上:
- 0 = 系统启发式地确定是否允许过度使用
- 1 = 总是过度使用(即使超出地址范围,如果你问我的话,那真是太蠢了)
- 2 = 从不过度 promise 超过某些限制
关于c - malloc 可以分配的最大大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13339509/