我正在调试一个问题,即同一个程序在不同的Linux机箱(所有2.6内核)上表现不同 . 基本上在一些linux机器上,16MB的mmap()总是成功,但在其他linux机箱上,相同的mmap()会因“ENOMEM”而失败 .

我检查了/ proc // maps并看到不同linux盒子上的虚拟内存映射是完全不同的 . 一件事是:堆的地址范围:

linux box1: the mmap() would return address of 31162000-31164000
linux box2: the mmap() would return address of a9a67000-a9a69000

我的问题是:对于一个特定的进程,如何安排linux虚拟内存?什么决定了实际的地址范围?为什么mmap()会失败,即使我仍然可以看到一些大的未使用的虚拟地址范围?

更新:这是一个16MB的mmap()失败的地址空间示例:

10024000-10f6b000 rwxp 10024000 00:00 0 [heap]
30000000-3000c000 rw-p 30000000 00:00 0 
3000c000-3000d000 r--s 00000000 00:0c 5461 /dev/shm/mymap1
3000d000-3000e000 rw-s 00001000 00:0c 5461 /dev/shm/mymap2
3000e000-30014000 r--s 00000000 00:0c 5463 /dev/shm/mymap3
30014000-300e0000 r--s 00000000 00:0c 5465 /dev/shm/mymap4
300e0000-310e0000 r--s 00000000 00:0b 2554 /dev/mymap5
310e0000-31162000 rw-p 310e0000 00:00 0 
31162000-31164000 rw-s 00000000 00:0c 3554306 /dev/shm/mymap6
31164000-312e4000 rw-s 00000000 00:0c 3554307 /dev/shm/mymap7
312e4000-32019000 rw-s 00000000 00:0c 3554309 /dev/shm/mymap8
7f837000-7f84c000 rw-p 7ffeb000 00:00 0 [stack]

在上面的例子中:最后一个mymap8和[stack]之间仍然有很大的空间 . 但是16MB的mmap()将会失败 . 我的问题是:Linux如何决定mmap()base和允许的范围?

谢谢 .