Why doing I/O in Linux is uninterruptible?

a 夏天 提交于 2019-11-28 12:09:53

Now that I've read the book "The Design of the Unix Operating Systems" by Maurice Bach, let me answer this question by myself.

In short, making I/O uninterruptible is for the purpose of making the I/O task finish ASAP, without being interfered by signals.

Some related knowledge that I gained from the book:

  1. The word "uninterruptible" should refer to "uninterruptible sleep". When a process is in uninterruptible sleep, it can NOT be waked up by signals, nor would it handle signals.
  2. A process handles signals when: a. it is running in kernel mode and is about to return to the user mode. b. it is about to enter and leave sleep state when the sleep is interruptible.
  3. What happens when a sleeping process is waken up by a signal? It would handle the signal, with the default action being exiting the process. When a process is waiting for I/O completion, you of course do not want it to exit prematurely.

According to the Linux Developers Documentation, it is to prevent data loss and avoid hardware getting into an inconsistent state.

Imagine what could occur if a read() (such as from disk) were interruptible and the signal handler, among other duties, altered the read buffer. Since the signal is asynchronous, the read results would not be reproducible. Similar chaos would ensue if writing were interrupted.

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