Why CPU spent time on IO(wa)?
I know wa
(in top
) measures the CPU time on waiting for I/O. Many articles say that.
But I am confused that, based on 2 knowledge points:
- if a process uses a system call to read disk, the process is blocked.
- If a process is blocked, it is cannot be scheduled running on CPU.
Right?
It seems there no time for CPU waiting on I/O... What happens?
If recommend some books or articles for me to further reading, so much the better.
Solution 1:
The CPU idle status is divided in two different "sub"-states: iowait
and idle
.
If the CPU is idle, the kernel then determines if there is at least one I/O currently in progress to either a local disk or a remotely mounted disk (NFS) which had been initiated from that CPU. If there is, then the CPU is in state iowait
. If there is no I/O in progress that was initiated from that CPU, the CPU is in idle
state.
So, iowait
is the percentage of time the CPU is idle AND there is at least one I/O in progress initiated from that CPU.
The iowait
counter states that the system can handle more computational work. Just because a CPU is in iowait
state does not mean that it can't run other threads or processes on that CPU.
So, iowait
is simply a form of idle time.