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(块缓冲)区别与联系

作者:Walk in Mindfields

KEEP CALM AND CARRY ON
原文地址:Linux Kernel: buffers和cached的区别, 感谢原作者分享。

Linux Kernel: buffers和cached的区别的更多相关文章

  1. Buffers与cached啥区别

    A buffer is something that has yet to be “written” to disk. A cache is something that has been “read ...

  2. Linux Buffers和Cached的区别(转)

    在linux下使用free命令查看内存使用情况,有buffers和cached两项,以下是它们的区别: buffers是为块设备设计的缓冲.比如磁盘读写,把分散的写操作集中进行,减少磁盘I/O,从而提 ...

  3. buffers和cached的区别

    原文:https://www.cnblogs.com/kevingrace/p/5991604.html buffers和cached解释 ============================== ...

  4. buffers与cached

    下面是buffers与cached的区别. buffers是指用来给块设备做的缓冲大小,他只记录文件系统的metadata以及 tracking in-flight pages. cached是用来给 ...

  5. Linux kernel memory-faq.txt

    ## Linux kernel memory-faq.txt What is some existing documentation on Linux memory management? Ulric ...

  6. Linux Kernel 代码艺术——编译时断言

    本系列文章主要写我在阅读Linux内核过程中,关注的比较难以理解但又设计巧妙的代码片段(不关注OS的各个模块的设计思想,此部分我准备写在“深入理解Linux Kernel” 系列文章中),一来通过内核 ...

  7. 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 ...

  8. Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State

    目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...

  9. arm linux kernel 从入口到start_kernel 的代码分析

    参考资料: <ARM体系结构与编程> <嵌入式Linux应用开发完全手册> Linux_Memory_Address_Mapping http://www.chinaunix. ...

随机推荐

  1. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 数组Api .map()的使用

    之前并没有过多的使用过这个Api,在此记录下对其的理解,方便以后多多使用. 首先是对map的说明: var mappedArray = array.map(callback[, thisObject] ...

  3. php之分页类代码

    /* 思路 1.把地址栏的URL获取 2.分析URL中的query部分--就是?后面传参数的部分 3.query部分分析成数组 4.把数组中的page单元,+1,-1,形成2个新的数组 5.再把新数组 ...

  4. AspNet WebApi: 了解下HttpControllerDispatcher,控制器的创建和执行

    HttpControllerDispatcher作为ASPNET WEB API消息处理管道中重要的部分,负责最后控制器系统的激活,action方法的执行,以及最后的响应生成. HtppControl ...

  5. pycharm常用快捷键与设置

    pycharm高频率使用的快捷键 Ctrl+Shift+F10 运行当前的页面 Ctrl + / 注释(取消注释)选择的行 Ctrl+Shift+F 高级查找 Shift + Enter 开始新行 T ...

  6. 在Eclipse中安装m2e插件遇到的问题

    最近自己想使用maven来搭建自动化测试框架,当中遇到了很多问题,其中之一就是安装m2e(Maven Integration for Eclipse). 其实原来的eclipse中已经安装好了m2e, ...

  7. 【深入浅出jQuery】源码浅析2--使用技巧

    最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...

  8. CP30,DBCP数据源配置

    Spring中 CP30数据源配置 <!-- 加载属性文件 01--> <bean id= "propertyConfigurer" class="or ...

  9. The Cow Lexicon(dp)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7290   Accepted: 3409 Description Few k ...

  10. ♫【JS基础】壹零零壹

    如何面试一个前端开发者? function spacify(str) { return str.split('').join(' ') } console.log(spacify('hello wor ...