Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doing I/O in Linux is uninterruptible?

What's the rationale behind it? What would the bad consequences be if a process doing I/O is allowed to handle signal?

like image 317
twimo Avatar asked Jan 27 '13 00:01

twimo


People also ask

What causes uninterruptible sleep Linux?

An Uninterruptible sleep state is one that won't handle a signal right away. It will wake only as a result of a waited-upon resource becoming available or after a time-out occurs during that wait (if the time-out is specified when the process is put to sleep).

What causes uninterruptible sleep?

One of the curious features of Unix systems (including Linux) is the "uninterruptible sleep" state. This is a state that a process can enter when doing certain system calls. In this state, the process is blocked performing a sytem call, and the process cannot be interrupted (or killed) until the system call completes.

What is an uninterruptible process?

An uninterruptible process is a process which happens to be in a system call (kernel function) that cannot be interrupted by a signal. To understand what that means, you need to understand the concept of an interruptible system call. The classic example is read() .

What does it mean when a Linux system process is in ad 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.


2 Answers

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.

like image 160
wallyk Avatar answered Nov 16 '22 04:11

wallyk


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.
like image 22
twimo Avatar answered Nov 16 '22 02:11

twimo