Search code examples
clinuxlinux-kernelsystem-calls

What is a "slow" device in the context of I/O call?


In man 7 signal, it describes certain constraints regarding when the SA_RESTART flag takes effect.

read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. If an I/O call on a slow device has already transferred some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). Note that a (local) disk is not a slow device according to this definition; I/O operations on disk devices are not interrupted by signals.

My questions are

  1. According to the manual, a terminal device, pipe, and socket are slow device whereas a disk isn't. What about a network device (eth, wlan, etc), a GPU, or an ASIC accelerator? It's difficult for me to judge according to the property "indefinite time".
  2. In which kernel file or function, is the one making this done (i.e. Does kernel distinguish a slow and non-slow device? How does kernel restart the operation when it's interrupted by a signal, etc.) under the hood? Maybe I can go there to find out more details.

Thanks.


Solution

  • The answer is simpler to understand than the manual.

    A "slow" device is one for which the device driver can be interrupted by a signal.

    Most device drivers can be interrupted. The block drivers can't.

    For the other devices you list, network devices are character devices and must be interruptible. (A packet driver can only interrupt between packets but that's not really relevant as you can't receive half a packet over the wire...) As for a GPU or ASIC accelerator I'd have to literally open up the driver and check, but if I had to guess I'd guess they aren't slow devices, because somebody would have to bother to implement the ability to interrupt and didn't because those devices are faster than the disk.

    Block device being non-interruptable can be painful when it's waiting for a scratched CD-ROM but that's nothing compaired to a device that could theoretically wait forever.