linux - 是否从页面缓存中的脏页面进行文件读取?

标签 linux caching linux-kernel filesystems page-caching

当字节写入文件时,内核不会立即将这些字节写入磁盘,而是将这些字节存储在页缓存中的脏页中(回写缓存)。

问题是,如果在脏页刷新到磁盘之前发出文件读取,字节是否会从缓存中的脏页提供服务,或者脏页首先会刷新到磁盘,然后再进行磁盘读取以提供服务字节(将它们存储在进程中的页面缓存中)?

最佳答案

文件读取将从页面缓存中获取数据,而不写入磁盘。来自 Robert Love 的Linux 内核开发第三版:

Whenever the kernel begins a read operation—for example, when a process issues the read() system call—it first checks if the requisite data is in the page cache. If it is, the kernel can forgo accessing the disk and read the data directly out of RAM.This is called a cache hit. If the data is not in the cache, called a cache miss, the kernel must schedule block I/O operations to read the data off the disk.

定期写回磁盘,与读取分开:

The third strategy, employed by Linux, is called write-back. In a write-back cache, processes perform write operations directly into the page cache.The backing store is not immediately or directly updated. Instead, the written-to pages in the page cache are marked as dirty and are added to a dirty list. Periodically, pages in the dirty list are written back to disk in a process called writeback, bringing the on-disk copy in line with the inmemory cache.

关于linux - 是否从页面缓存中的脏页面进行文件读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40034642/

相关文章:

memory - 从自由命令理解 "Buffers"和 "Cached"

TUNSETIFF ioctl 类型的混淆

c - 将硬安装的 NFS 卷视为软卷

c - 我们什么时候应该关心缓存丢失?

javascript - 如何从 Node js上的http get请求中删除缓存

java - 运行 GWT 应用程序时出现 Unitcahche 异常

c - 原始套接字和 NF_INET_POST_ROUTING

c - C中的数组打印错误

Linux,查找 > zcat > wc

php - 已安装 intl 扩展,但在 phpinfo() 中看不到