|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!体系情况:CentOS6.5x86_64
1、成绩体现
体系负载降低,某一个核的cpu资本被top历程耗尽,以下图所示:
2、剖析历程
<olclass="list-paddingleft-2"style="padding-right:0px;padding-left:20px;margin:0px;color:rgb(85,85,85);font-family:宋体,ArialNarrow,arial,serif;font-size:14px;line-height:28px;"><listyle="padding:0px;margin:0px0px0px20px;">经由过程strace下令打印top历程信息,呈现大批反复的体系挪用,以下:
检察top历程的fd信息以下:
经由过程以上信息揣度,top历程的输出输入非常,触发select前往文件形貌符,可是文件形貌符未处置或处置不妥形成select无穷触发,堕入逝世轮回,占用一个核的cpu资本。
<listyle="padding:0px;margin:0px0px0px20px;">下载procps-3.2.8检察top源码,在第3398行找到了相干挪用。如代码所示尺度输出被放到了select挪用里,由于尺度输出毛病招致触发select前往fd,无tv时长的守候。
<listyle="padding:0px;margin:0px0px0px20px;">
[size=1em][size=1em]longfile_flags;
[size=1em]intrc;
[size=1em]charc;
[size=1em]fd_setfs;
[size=1em]FD_ZERO(&fs);
[size=1em]FD_SET(STDIN_FILENO,&fs);
[size=1em]file_flags=fcntl(STDIN_FILENO,F_GETFL);
[size=1em]if(file_flags==-1)file_flags=0;
[size=1em]fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK|file_flags);
[size=1em]
[size=1em]//check1st,incasetvzeroed(bysighandler)beforeitgotset
[size=1em]rc=chin(0,&c,1);
[size=1em]if(rc<=0){
[size=1em]//EOFisprettymucha"canthappen"exceptforakernelbug.
[size=1em]//WeshouldquicklydieviaSIGHUP,andthusnotspinhere.
[size=1em]//if(rc==0)end_pgm(0);/*EOFfromterminal*/
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]select(1,&fs,NULL,NULL,&tv);
[size=1em]fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK|file_flags);
[size=1em]}
[size=1em]if(chin(0,&c,1)>0){
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]do_key((unsigned)c);
[size=1em]}else{
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]}
<listyle="padding:0px;margin:0px0px0px20px;">尺度输出的处置代码以下:
<listyle="padding:0px;margin:0px0px0px20px;"><divstyle="padding:0px;margin:0px;"><divclass="syntaxhighlightercpp"id="highlighter_426957"style="width:680px;padding:0px!important;margin:0.3em0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow-y:visible!important;overflow-x:auto!important;position:relative!important;right:auto!important;top:auto!important;vertical-align:baseline!important;box-sizing:content-box!important;font-family:Consolas,BitstreamVeraSansMono,CourierNew,Courier,monospace!important;font-size:1em!important;min-height:inherit!important;">
<divclass="container"style="padding:0px!important;margin:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow:visible!important;position:relative!important;right:auto!important;top:auto!important;vertical-align:baseline!important;width:auto!important;box-sizing:content-box!important;font-size:1em!important;min-height:inherit!important;"><divclass="linenumber1index0alt2"style="white-space:nowrap;padding:0px1em!important;margin:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow:visible!important;position:static!important;right:auto!important;top:auto!important;vertical-align:baseline!important;width:auto!important;box-sizing:content-box!important;font-size:1em!important;min-height:inherit!important;">static |
|