Linux Kernel: buffers和cached的区别
The page cache caches pages of files to optimize file I/O. The buffer cache caches disk blocks to optimize block I/O.
Page Cache缓存文件内容以优化文件I/O,Buffer Cache缓存磁盘blocks以优化block I/O。
注释:Block 块是用来管理磁盘空间的,而Page 页是针对内存管理,从磁盘读出的数据就缓存在内存页中。当一个块被调入到内存中,它要被存储在一个缓冲区中。
Prior to Linux kernel version 2.4, the two caches were distinct: Files were in the page cache, disk blocks were in the buffer cache. Given that most files are represented by a filesystem on a disk, data was represented twice, once in each of the caches. Many Unix systems follow a similar pattern.
Linux kernel 2.4以前,这两个cache的使用是有明显区别的:文件的内容在Page Cache中缓冲,(管理基于磁盘的文件系统的VFS所访问的)blocks在Buffer Cache中缓冲。鉴于大多数的文件都是由基于磁盘的文件系统来存储和表示(represented )的,这样数据就被CACHE了两次,每个缓存(PageCache & BufferCache)中各表示一次。许多Unix系统都遵循此类的模式。
This is simple to implement, but with an obvious ineleganceand inefficiency. Starting with Linux kernel version 2.4, the contents of the two caches were unified. The VM subsystem now drives I/O and it does so out of the page cache. If cached data has both a file and a block representation—as most data does—the buffer cache will simply point into the page cache; thus only one instance of the data is cached in memory. The page cache is what you picture when you think of a disk cache: It caches file data from a disk to make subsequent I/O faster.
这样易于实现,但存在明显的槽点(CACHE重复)和低效。从Linux kernel 2.4(2.4.10)开始,两个cache中的内容统一了(buffer cache不再真正的存在,实际上buffer cache不再独立分配,而是在page cache中用专门的buffer page来替代,buffer page在形式上就是缓冲区描述符,称为buffer_head)。现在由VM子系统来驱动I/O(并独立于Page Cache)。如果缓冲的数据既有文件表示(file representation)又有块表示(block representation)——大多数数据都是如此——那么buffer cache就简单的指向page cache;这样就仅有一份数据被缓冲在内存中了。当你想象一个磁盘缓存,page cache即是:它缓冲磁盘中的文件数据,以使后续的I/O操作更快。
注释:每个缓冲区与一个块对应,它相当于磁盘块在内存中的表示。在内存页中,有一种叫专门用途的页面叫“缓冲区页”,用来存放块缓冲区。而每个块缓存区由两部分组成:缓冲区首部(用数据结构buffer_head表示)及真正的缓冲区内容(即所存储的数据,这些数据就放在刚刚说到的缓冲区页中)。而文件在内存中由file结构体表示,而磁盘块在内存中是由缓冲区来进行表示的。
The buffer cache remains, however, as the kernel still needs to perform block I/O in terms of blocks, not pages. As most blocks represent file data, most of the buffer cache is represented by the page cache. But a small amount of block data isn't file backed—metadata and raw block I/O for example—and thus is solely represented by the buffer cache.
Buffer cache还被保留,因为内核还要以block为单位(而不是page)来进行block I/O操作。由于大多数情况下block就已经代表了文件数据,所以大多数的buffer cache由page cache来代替了。但还有少量block数据不是文件内容本身——例如文件系统的元数据(metadata)和裸设备(raw) block I/O——这些还是在buffer cache中缓冲的。
注释:由于内核处理块时需要一些信息(比如将CACHE中的脏数据写入到磁盘中,而数据是被文件系统组织存储在block中的),如块属于哪个设备与块对应于哪个缓冲区。所以每个缓冲区都有一个缓冲区描述符,称为buffer_head。它包含了内核操作缓冲区所需要的全部信息。通过buffer_head 可以快速的定位page中独立的blocak在磁盘上的逻辑地址。
See also my answer to What is the difference between Buffers and Cached columns in /proc/meminfo output?

图1:page cache 和 buffer cache 的关系

图2:the buffer cache
原文链接:Linux Kernel: What is the major difference between the buffer cache and the page cache?
参考文章:block(块),page(页),buffer cache(块缓冲)区别与联系
Linux Kernel: buffers和cached的区别的更多相关文章
- Buffers与cached啥区别
A buffer is something that has yet to be “written” to disk. A cache is something that has been “read ...
- Linux Buffers和Cached的区别(转)
在linux下使用free命令查看内存使用情况,有buffers和cached两项,以下是它们的区别: buffers是为块设备设计的缓冲.比如磁盘读写,把分散的写操作集中进行,减少磁盘I/O,从而提 ...
- buffers和cached的区别
原文:https://www.cnblogs.com/kevingrace/p/5991604.html buffers和cached解释 ============================== ...
- buffers与cached
下面是buffers与cached的区别. buffers是指用来给块设备做的缓冲大小,他只记录文件系统的metadata以及 tracking in-flight pages. cached是用来给 ...
- Linux kernel memory-faq.txt
## Linux kernel memory-faq.txt What is some existing documentation on Linux memory management? Ulric ...
- Linux Kernel 代码艺术——编译时断言
本系列文章主要写我在阅读Linux内核过程中,关注的比较难以理解但又设计巧妙的代码片段(不关注OS的各个模块的设计思想,此部分我准备写在“深入理解Linux Kernel” 系列文章中),一来通过内核 ...
- Linux Kernel sys_call_table、Kernel Symbols Export Table Generation Principle、Difference Between System Calls Entrance In 32bit、64bit Linux
目录 . sys_call_table:系统调用表 . 内核符号导出表:Kernel-Symbol-Table . Linux 32bit.64bit环境下系统调用入口的异同 . Linux 32bi ...
- Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State
目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...
- arm linux kernel 从入口到start_kernel 的代码分析
参考资料: <ARM体系结构与编程> <嵌入式Linux应用开发完全手册> Linux_Memory_Address_Mapping http://www.chinaunix. ...
随机推荐
- 关于alarm函数
#include<unistd.h> #include<signal.h> void handler() { printf("Hello\n"); sign ...
- C#快速导入海量XML数据至SQL Server数据库
#region 将Xml中的数据读到Dataset中,然后用SqlBulkCopy类把数据copy到目的表中using (XmlTextReader xmlReader = new XmlTextRe ...
- 微信小程序,大多数人误解的8个问题
作者:王安,数字天堂DCloud公司创始人兼CEO 注:本文内容包含技术.商业,不懂技术的读者可以只看商业相关的内容.本文仅代表作者一家之言,如有不同意见,欢迎留言讨论~ 8个误解 坊间所传的信息很多 ...
- html embed用法
(一).基本语法: embed src=url 说明:embed可以用来插入各种多媒体,格式可以是 Midi.Wav.AIFF.AU.MP3等等, Netscape及新版的IE 都支持.u ...
- Python新手学习基础之初识python——与众不同2
看完了Python的缩进,现在来看看Python的标识符.引号和注释. 标识符 关于Python的标识符,其实不是与众不同,只是有一定的规则. 标识符是编程时使用的名字.在Python中,标识符有几点 ...
- MySQL zip版安装配置
文章出处:http://www.cnblogs.com/winstic/,请保留此连接 这段时间在学习Python 数据库操作知识,简单整理MySQL zip文件安装方法 下载 在MySQL官网htt ...
- C++实现base64编码
将昨天的php代码改造成C++ /*base_64.h文件*/ #ifndef BASE_64_H #define BASE_64_H /** * Base64 编码/解码 * @author lir ...
- CodeFirst中DB保存时报错:对一个或多个实体的验证失败。
错误提示如下: 开始以为有字段可能没有添加数据,可是检查了很久,仍然没有任何头绪. 后使用DbEntityValidationException进行调试,问题才得以解决
- nginx+uwsgi+WSGI applications
uwsgi一个专业的部署运用的工具,不仅能够部署Python运用,还能够部署其他运用比如Perl,Ruby等 uWSGI 安装: pip install uwsgi WSGI application( ...
- hdu 5139 Formula
http://acm.hdu.edu.cn/showproblem.php?pid=5139 思路:这道题要先找规律,f(n)=n!*(n-1)!*(n-2)!.....1!; 不能直接打表,而是离 ...