文件读取是否来自页面缓存中的脏页?
Are file reads served from dirtied pages in the page cache?
当字节写入文件时,内核不会立即将这些字节写入磁盘,而是将字节存储在页面缓存(回写缓存)中的脏页中。
问题是,如果在将脏页刷新到磁盘之前发出文件读取,字节是从缓存中的脏页提供服务还是先将脏页刷新到磁盘,然后再读取磁盘提供字节(在进程中将它们存储在页面缓存中)?
从应用程序开发人员的角度来看,可以合理地假设 read 在 write 之后将获取由写.
Linux 提供此类保证,隐藏实施细节。所以,无论是否使用缓存,写入的效果都是一样的:fuffer read will return write .
文件读取将从页面缓存中获取数据而不写入磁盘。来自 Linux 内核开发第 3 版,作者:Robert Love:
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.
当字节写入文件时,内核不会立即将这些字节写入磁盘,而是将字节存储在页面缓存(回写缓存)中的脏页中。
问题是,如果在将脏页刷新到磁盘之前发出文件读取,字节是从缓存中的脏页提供服务还是先将脏页刷新到磁盘,然后再读取磁盘提供字节(在进程中将它们存储在页面缓存中)?
从应用程序开发人员的角度来看,可以合理地假设 read 在 write 之后将获取由写.
Linux 提供此类保证,隐藏实施细节。所以,无论是否使用缓存,写入的效果都是一样的:fuffer read will return write .
文件读取将从页面缓存中获取数据而不写入磁盘。来自 Linux 内核开发第 3 版,作者:Robert Love:
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.