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. CSAPP LAB: Buffer Overflow

    这是CSAPP官网上的著名实验,通过注入汇编代码实现堆栈溢出攻击.实验材料可到我的github仓库 https://github.com/Cheukyin/CSAPP-LAB/ 选择buffer-ov ...

  2. 学C++不得不看的一篇文章[转]

    1. 扎实的基础.数据结构.离散数学.编译原理,这些是所有计算机科学的基础,如果不掌握他们,很难写出高水平的程序.据我的观察,学计算机专业的人比学其他专业的人更能写出高质量的软件.程序人人都会写,但当 ...

  3. C#/.NET整数的三种强制类型转换(int)、Convert.ToInt32()、int.Parse()的区别

    这三种方式都是强制把内容转换为整数,但他们之间是有区别的,如下: 一.(int)适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型). 二.int.Parse(string sP ...

  4. js动态加载脚本

    最近公司的前端地图产品需要做一下模块划分,希望用户用到哪一块的功能再加载哪一块的模块,这样可以提高用户体验. 所以到处查资料研究js动态脚本的加载,不过真让人伤心啊!,网上几乎都是同一篇文章,4种方法 ...

  5. windows系统安装ubuntu后,grub中没有windows启动项

    我的问题: 安装系统时候,选择grub安装在sdb磁盘 http://forum.ubuntu.org.cn/viewtopic.php?f=139&t=474289&start=15 ...

  6. 优秀开源项目的svn地址

    很多优秀的开源项目已经提供SVN源码签出了,无论是解疑还是学习,都是一大幸福之事啊! Apache的SVN库,强烈推荐! http://svn.apache.org/repos/asf/ 里面不但有S ...

  7. Python3 time()

    在<Python基础教程(第二版)>一书中, if time % 60 == 0 : print 'on the hour! '在3.3.2版本中显示错误.于是自己查了一下帮助文档,也在网 ...

  8. 关于如何在BCB中使用CodeGuard

    作者:深圳虫 来自:深圳虫网本文来自http://www.szbug.com/disparticle.aspID=4 一. 为什么写这篇东西自己在使用BCB5写一些程序时需要检查很多东西,例如内存泄漏 ...

  9. http请求方式和状态管理

    1.  HTTP协议 Internet的基本协议是TCP/IP协议(传输控制协议和网际协议),目前广泛使用的 FTP.HTTP(超文本传输协议).Archie Gopher都是建立在TCP/IP上面的 ...

  10. 【HDOJ】2645 find the nearest station

    裸BFS. /* 2645 */ #include <iostream> #include <queue> #include <cstdio> #include & ...