免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1473 | 回复: 2
打印 上一主题 下一主题

[内核入门] 怎么查找缺少什么资源导致的pthread_create返回EAGAIN [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-26 14:48 |只看该作者 |倒序浏览
我们在测试时发现日志中创建线程报错:Resource temporarily unavailable(errno = 11, EAGAIN)
但是用limit查看资源很充足,物理内存2T
[####]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16543461
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 500000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 42768
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


我的问题是:怎么查找是什么资源导致某次调用失败。
我写了一个简单的测试程序,一直创建线程,然后用systemstap检测,检测脚本是
  1. probe kernel.function("SyS_clone").return
  2. {
  3.         if ($return != 0)
  4.         {
  5.                 print_backtrace();
  6.                 exit();
  7.         }

  8. }
复制代码
得出的结果是:
Returning from:  0xffffffff81066bd0 : SyS_clone+0x0/0x20 [kernel]
Returning to  :  0xffffffff8172c9c9 : stub_clone+0x69/0x90 [kernel]


可惜什么都看不懂,请大侠们指点一下。

测试程序:
  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <sys/stat.h>
  4. #include <sys/ipc.h>
  5. #include <sys/shm.h>
  6. #include <spawn.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <errno.h>
  12. #include <dirent.h>
  13. #include <pthread.h>

  14. #include <iostream>
  15. #include <string>

  16. using namespace std;

  17. void *func(void *)
  18. {
  19.         while (true)
  20.                 sleep(10);
  21.         return NULL;
  22. }
  23. int main(int argc, char **argv)
  24. {
  25.         pthread_t tid;
  26.         int ret = 0;
  27.         int count = 0;
  28.         while (!ret)
  29.         {
  30.                 ret = pthread_create(&tid, NULL, func, NULL);
  31.                 count ++;
  32.         }
  33.         count--;
  34.         printf("max thread is : %d, errno is %d\n", count, ret);
  35.         return EXIT_SUCCESS;
  36. }
复制代码

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-08-17 06:20:00程序设计版块每日发帖之星
日期:2016-07-16 06:20:00程序设计版块每日发帖之星
日期:2016-07-18 06:20:00每日论坛发贴之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16赛季CBA联赛之江苏
日期:2017-06-26 11:05:5615-16赛季CBA联赛之上海
日期:2017-07-21 18:12:5015-16赛季CBA联赛之青岛
日期:2017-09-04 17:32:0515-16赛季CBA联赛之吉林
日期:2018-03-26 10:02:16程序设计版块每日发帖之星
日期:2016-07-15 06:20:0015-16赛季CBA联赛之江苏
日期:2016-07-07 18:37:512015亚冠之萨济拖拉机
日期:2015-08-17 12:21:08
2 [报告]
发表于 2016-02-26 17:45 |只看该作者
不知道是不是address space用完了(每个线程需要一个独立的stack)?
测试得到的count(建议换成long)是多少?

论坛徽章:
0
3 [报告]
发表于 2016-02-27 10:10 |只看该作者
nswcfd 发表于 2016-02-26 17:45
不知道是不是address space用完了(每个线程需要一个独立的stack)?
测试得到的count(建议换成long)是多 ...

是的,每个线程都需要自己独立的stack,要不然不同线程中的函数执行就会混乱
我自己的虚拟机上测试大概是3W多(root)和1.5W(普通用户)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP