我想产生大量的过程。所以我有master
进程来完成它。
int master(int argc, char* argv[]){
for (int i = 0; i < 50000; ++i) {
std::string name = std::to_string(i);
MSG_process_create(name.c_str(), slave, NULL, MSG_host_self());
}
return 0;
}
int slave(int argc, char* argv[]){
XBT_INFO("%s", MSG_process_get_name(MSG_process_self()));
return 0;
}
启动此程序后,我有以下输出:
....
....
[Master:32734:(32736) 0.000000] [master/INFO] 32734
[Master:32735:(32737) 0.000000] [master/INFO] 32735
[0.000000] /home/ken/Downloads/simgrid-master/src/simix/smx_context.cpp:187: [xbt/CRITICAL] Failed to protect stack: Cannot allocate memory
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
然后我被建议使用contexts/stack-size
参数来更改堆栈大小,因为默认情况下以前的程序需要50000 * 8192 KiB。
我添加了这个参数--cfg=contexts/stack-size:10
,但我有相同的输出:
...
...
[Master:32735:(32737) 0.000000] [master/INFO] 32735
[0.000000] /home/ken/Downloads/simgrid-master/src/simix/smx_context.cpp:187: [xbt/CRITICAL] Failed to protect stack: Cannot allocate memory
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
或--cfg=contexts/stack-size:100000
:
...
...
[Master:32734:(32736) 0.000000] [master/INFO] 32734
[0.000000] /home/ken/Downloads/simgrid-master/src/simix/smx_context.cpp:187: [xbt/CRITICAL] Failed to protect stack: Cannot allocate memory
似乎我的程序看不到这个参数,但事实并非如此,因为stack-parameter是5
给了我:
Finally, if nothing of the above applies, this can result from a stack overflow.
Try to increase stack size with --cfg=contexts/stack_size (current size is 1 KiB).
我做错了什么?
答案 0 :(得分:2)
您可以尝试增加系统上每个进程允许的最大映射数值吗?
您可以使用sudo sysctl -w vm.max_map_count = 500000将最大值设置为500000
我们最近看到这在一些SMPI运行中引起了一些问题,也许它在您的结束时是相同的。 &#34;无法分配内存&#34;消息可能确实具有误导性,因为ENOMEM错误代码是出于各种原因设置的(根据http://man7.org/linux/man-pages/man2/mprotect.2.html,其中一个可能是映射的数量)。