I have a question about kernel I/O cache for disk file.
As I know when write() or read() is called, there’s a buffer cache in kernel space for disk file I/O operation.
My question is that, is this I/O buffering only applies to disk file, or it also applies to terminal, FIFO, pipe, and sockets?
Thanks
It is called the “page cache”. It consists of pages backed by files and “anonymous pages” backed by swap. This is all part of the Linux virtual memory (VM) subsystem.
It is not used for TTYs, FIFOs, pipes, or sockets. Each of those do provide buffering of their own by their nature; for example, the data you write to a pipe has to reside somewhere before it is read back out again. But that buffering has nothing to do with the VM subsystem.
[update]
Note that this buffering is totally independent of the user-space buffering provided by (e.g.)
fwrite(). (I see you asked a similar question earlier, and it is not clear whether you understand the distinction.)