我个人遇到过一次uninterruptable sleep (D state)的进程,当时很疑惑,当时也没有深究。What is I/O wait?
To understand I/O wait, one must first understand about process states
. At any given moment, a process is in one of several states. This state is indicated by the STAT
column in ps
or top
. From the ps(1) man page:
-
D
- Uninterruptible sleep (usually IO)
-
R
- Running or runnable (on run queue)
-
S
- Interruptible sleep (waiting for an event to complete)
-
T
- Stopped, either by a job control signal or because it is being traced
-
W
- Paging (not valid since the 2.6.xx kernel)
-
X
- Dead (should never be seen)
-
Z
- Defunct ("zombie") process, terminated but not reaped by its parent
I/O wait comes solely from processes in uninterruptable sleep (D state). Generally, a process is put into D state when waiting for some sort of I/O to complete. The process has made a call into the kernel and is waiting for the result. During this period, it is unable to be interrupted, as doing so might jeopardize the state of the driver and hardware.
上一段加入baidu翻译:
I/O等待仅来自处于不间断睡眠(D状态)的进程。通常,当等待某种I/O完成时,进程将进入D状态。进程已调用内核,正在等待结果。在此期间,它无法被中断,因为这样做可能会危及驱动程序和硬件的状态。
When a process goes into D state, the kernel knows on which CPU the process was last running and will attribute the time that the process spends in D state to I/O wait on that CPU.
It is important to note that from a CPU standpoint, I/O wait is equivalent to idle time. A process in I/O wait will not block a process that is ready to run (R state).
It is also important to note that high I/O wait percentages are not necessarily a problem. On a machine that is running primarily I/O bound applications, high I/O wait percentages are often to be expected. This is simply a reflection of how the machine is spending its time (mostly just waiting for I/O to complete).