CPU Utilization high for sleeping processes

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 07:09:18

问题


I have a process that appears to be deadlocked:

# strace -p 5075
Process 5075 attached - interrupt to quit
futex(0x419cf9d0, FUTEX_WAIT, 5095, NULL

It is sitting on the "futex" system call, and seems to be indefinitely waiting on a lock. The process is shown to be consuming a large amount of CPU when "top" is run:

# top -b -n 1
top - 23:13:18 up 113 days,  4:19,  1 user,  load average: 1.69, 1.74, 1.72
Tasks: 269 total,   1 running, 268 sleeping,   0 stopped,   0 zombie
Cpu(s):  8.1%us,  0.1%sy,  0.0%ni, 91.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  12165696k total,  3810476k used,  8355220k free,    29440k buffers
Swap:  8388600k total,    43312k used,  8345288k free,   879988k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
5075 omdb      18   0 2373m 1.7g  26m S 199.7 14.9 102804:11 java

The process is also shown to be in a "S" - Sleep state, which makes sense if it's waiting on some resource. However, I don't understand why CPU utilization would be close to 200% if the process is in the sleep state. Why does top report such high CPU utilization on a sleeping process? Shouldn't its CPU utilization be zero?


回答1:


There is no correlation between CPU usage as reported by top and process state. The man page says (emphasis mine):

%CPU -- CPU usage

The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.

So, your process indeed used a huge amount of processor time since the last screen update. It is sleeping, yes, but that's because the currently running process is top itself (which makes sense, since it's currently updating the screen).




回答2:


Does your application fork child processes? The strace output may indicate that the main process is just waiting for child processes to finish their work. If so, you could try running

strace -f -p 5075

to trace the child processes as well.




回答3:


The top output is perfectly normal.

The load average calculations include processes that are waiting on something (mutexes/futexes, IO etc) as well as processes that are actually using the CPU. Test it by, say, running something like:

dd if=/dev/sda of=/dev/null

and watching top output to see what happens. It will increase the load average by 1.

If you look at this line:

Cpu(s):  8.1%us,  0.1%sy,  0.0%ni, 91.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

the "id" in "91.8%id" means "idle". So the CPU isn't actually doing much at all.



来源:https://stackoverflow.com/questions/10628037/cpu-utilization-high-for-sleeping-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!