gpt4 book ai didi

linux - 文件读取是否来自页面缓存中的脏页?

转载 作者:太空宇宙 更新时间:2023-11-04 09:22:49 27 4
gpt4 key购买 nike

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

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

最佳答案

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com