在最近的libc或Linux内核中是否存在非ulimit堆内存限制?

时间:2013-09-02 23:58:12

标签: linux

Linux mint64 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

以上程序在上面提到的64位系统上刚刚安装的Linux Mint 15上失败了。它运行在具有4GB“物理”内存的VM中。在我的Mac和

上正常工作
Linux hercules 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

ulimit声称没有限制生效。 strace显示mmap失败:

mmap(NULL, 4836167680, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)

进一步的实验表明,开启过度使用会使其“有效”。

free命令显示:

$ free
             total       used       free     shared    buffers     cached
Mem:       3993228    3098188     895040          0     137680    2255620
-/+ buffers/cache:     704888    3288340
Swap:      1046524          0    1046524

图片中是否有一些新的控制机制?如果手头有足够的(?)物理内存,为什么交换很重要?

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
  void *m = malloc(4836032512);
  if (m == 0) {
    fprintf(stderr, "Could not allocate ~4MB of memory with malloc?\n");
    return 1;
  }
  return 0;
}

现在看来很明显,如果你要求4GB的内存,你最好有超过4GB的内存,而我试过的其他系统都有超过4GB的内存。

0 个答案:

没有答案