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. ...
随机推荐
- python split()黑魔法
split()用法: #!/usr/bin/python str = "Line1-abcdef \nLine2-abc \nLine4-abcd"; print str.spli ...
- NPOI使用手册
HSSFSheet sheet = hssfworkbook.CreateSheet("new sheet"); // Create a row and put some cell ...
- Chrome 中的彩蛋——T-Rex
今天,从网页上看到chrome的T-Rex的彩蛋,眨眼间完了10分钟.分享出来,只是好玩. 当 Chrome 无法连接到互联网时,或者上着网突然掉线,刷新页面时报错,我们都会看到T-Rex的身影,没错 ...
- IE 6最小最大宽度与高度的写法
最小最大宽度,最小最大高度,这是CSS很常见的一个要求.在现代浏览器中,一个 min-height,min-width 就可以解决问题,但是在IE系列,比如IE6则比较繁琐一点.下面总结一些IE 6下 ...
- YII 自动引入juquery进行表单验证
在form表单 里面引入这么一句话 array( 'enableClientValidation'=>true, 'clientOptions'=>array( ...
- VS2010 release 和 debug 调试区别
VC下Debug和Release区别 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下又无法进行调试,于是只能采用printf方式逐步 ...
- linux 和 ubuntu 修改主机名
原始主机名:jeepend-VirtualBox linux 修改方法: 1.使用secure CRT或其他方式 用root用户 登入系统.2.在终端输入: #hostname [修改后的主机名]3. ...
- Day12(补充) Python操作MySQL
本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...
- 实现OC与JS的交互
oc-->js stringByEvaluatingJavaScriptFromString,其参数是一NSString 字符串内容是js代码(这又可以是一个js函数.一句js代码或他们 ...
- Biathlon Track
Codeforces Round #242 (Div. 2) D:http://codeforces.com/contest/424/problem/D 题意:给你一个n*m的矩阵,每个格子上面有个数 ...