Fix Disparity Between `top` CPU % and Process CPU Usage Total

cpu usagelinuxtop

I've noticed that there are sometimes (large) differences between the reported total CPU usage and a summation of the per-process CPU utilization given by apps like top and wmtop.

As an example: I recently ran a git filter-branch --index-filter on a fairly large repo, with the index-filter command piping git ls-files through a grep filter and into xargs git rm --cached. This took a few minutes to run; while it was going I noticed that both wmtop and top were displaying a high (above 50% on my 2-core machine) total CPU usage, but that neither showed any individual processes which were using a significant amount of CPU time.

Are some processes not shown in the process list? What sorts of processes are these, and is there a way to find out how much CPU time they are using?

Best Answer

You should add a snapshot of tops output to your question so we can see exactly what you see.

The most common discrepancy in processor use indicators is some counting "I/O wait" time as well as "actually CPU busy" time. I/O wait time is when a process would be actively doing something, so could potentially have used all the time-slice the scheduler has given it, but has yielded as it is blocked waiting for I/O operations to complete.

Short running processes have an effect too: if there are many processes starting, doing something small, then closing, they may not be seen at all by top or similar (especially if you don't have top updating often) because they did their thing and stopped between updates. Even though they were not present when top took its samples (so don't appear in the tasks list) they overall counts in the /proc filesystem will still show since the last sample the CPU was busy for X scheduler ticks and idle for Y.