使用mmap2系统调用时,C ++应用程序耗时太长。一旦进程达到大约2.7 GB,mmap2调用最多需要100秒,并且被进程中内置的心跳机制杀死。开始了一个过程,当进程内存达到接近〜2GB RSS时,strace显示mmap2正在返回ENOMEM,但应用程序是 分配内存。
OS:redhat 6.5 64位编译器:gcc 4.4.6进程内存限制(32位):4 gb,
没有配置交换
当发生这种情况时,主机仍然有50GB的内存。
我们试图将vm.max_map_count从65530增加到1000000,它改进了一点mmap2 ENOMEM被延迟但是这个过程最终被杀死了 mmap2系统调用时间过长。
我们还通过测试程序证明我们可以分配和使用最多~4GB。
从strace看起来它不是一个应用程序问题,因为mmap2正在从内核请求内存,并且想知道为什么mmap2花费的时间太长。
mmap2采用时的堆栈跟踪> 100秒,最终被心跳机制杀死:
#0 0x55575430 in __kernel_vsyscall ()
#1 0x560f9dd8 in mmap () from /lib/libc.so.6
#2 0x5608cc14 in new_heap () from /lib/libc.so.6
#3 0x5608f17f in _int_malloc () from /lib/libc.so.6
#4 0x5608fb7e in malloc () from /lib/libc.so.6
#5 0x55fb509a in operator new(unsigned int) () from /usr/lib/libstdc++.so.6
#6 0x0830b051 in __gnu_cxx::new_allocator<std::_List_node<unsigned long> >::allocate (this=0xb642b04, __n=1) at /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/ext/new_allocator.h:89
Following is snapshot from strace:
---successful mmap2
2211 21:31:18 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffffffe0e01000 <0.000454>
2211 21:31:20 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffffffe0700000 <0.000379>
2211 21:31:20 mmap2(NULL, 524288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x57b12000 <0.000042>
2211 21:31:25 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffffffe0700000 <0.000359>
2211 21:31:25 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffffffe0e01000 <0.000021>
2211 21:31:25 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffffffe1502000 <0.000020>
----encountered first ENOMEM a day later
2211 12:21:28 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000444>
2211 12:21:28 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000140>
2211 12:21:29 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xfffffffffde01000 <0.000482>
2211 12:21:30 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xfffffffffd700000 <0.000649>
2211 12:21:31 mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0xfffffffffc500000 <0.000582>
2211 12:21:31 mmap2(NULL, 7344128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xfffffffffe502000 <0.000634>
---------mmap2 taking more than 100 seconds
2211 13:04:25 mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000179>
2211 13:04:25 mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000158>
2211 13:04:25 mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000191>
2211 13:04:25 mmap2(NULL, 1048576, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = -1 ENOMEM (Cannot allocate memory) <0.000252>
2211 13:04:25 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 <unfinished ...>