简体   繁体   English

Linux内核中磁盘文件的I / O缓冲区缓存

[英]I/O buffer cache for disk file in Linux kernel

I have a question about kernel I/O cache for disk file. 我有一个关于磁盘文件的内核I / O缓存的问题。 As I know when write() or read() is called, there's a buffer cache in kernel space for disk file I/O operation. 据我所知,当调用write()或read()时,内核空间中有一个缓冲区缓存用于磁盘文件I / O操作。 My question is that, is this I/O buffering only applies to disk file, or it also applies to terminal, FIFO, pipe, and sockets? 我的问题是,这个I / O缓冲只适用于磁盘文件,还是适用于终端,FIFO,管道和套接字?

Thanks 谢谢

It is called the "page cache". 它被称为“页面缓存”。 It consists of pages backed by files and "anonymous pages" backed by swap. 它由文件支持的页面和由swap支持的“匿名页面”组成。 This is all part of the Linux virtual memory (VM) subsystem. 这是Linux虚拟内存(VM)子系统的所有部分。

It is not used for TTYs, FIFOs, pipes, or sockets. 它不用于TTY,FIFO,管道或套接字。 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. 但是这种缓冲与VM子系统无关。

[update] [更新]

Note that this buffering is totally independent of the user-space buffering provided by (eg) fwrite() . 请注意,此缓冲完全独立于(例如) fwrite()提供的用户空间缓冲。 (I see you asked a similar question earlier, and it is not clear whether you understand the distinction.) (我看到你之前问了一个类似的问题,目前尚不清楚你是否理解这种区别。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM