`
m635674608
  • 浏览: 4929566 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

转载和积累系列 - Page cache和Buffer cache

 
阅读更多

Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的数据会缓存到page cache。文件的逻辑层需要映射到实际的物理磁盘,这种映射关系由文件系统来完成。当page cache的数据需要刷新时,page cache中的数据交给buffer cache,但是这种处理在2.6版本的内核之后就变的很简单了,没有真正意义上的cache操作。

Linux 2.6的内核中Page cacheBuffer cache进一步结合,Buffer pages其实也是Page cache里面的页。从Linux算法实现的角度,Page cacheBuffer cache目前是一样的,只是多了一层抽象,通过buffer_head来进行一些访问管理。可以理解为只有Page cache概念亦可。在Linux 2.6的内核中Page cacheBuffer cache进一步结合,Buffer pages其实也是Page cache里面的页。从Linux算法实现的角度,Page cacheBuffer cache目前是一样的,只是多了一层抽象,通过buffer_head来进行一些访问管理。可以理解为只有Page cache概念亦可。

 

标准IO

Linux中,这种访问文件的方式是通过两个系统调用实现的:read()write()。当应用程序调用read() 系统调用读取一块数据的时候,如果该块数据已经在内存中了,那么就直接从内存中读出该数据并返回给应用程序;如果该块数据不在内存中,那么数据会被从磁盘上读到页高缓存中去,然后再从页缓存中拷贝到用户地址空间中去。如果一个进程读取某个文件,那么其他进程就都不可以读取或者更改该文件;对于写数据操作来说,当一个进程调用了write() 系统调用往某个文件中写数据的时候,数据会先从用户地址空间拷贝到操作系统内核地址空间的页缓存中去,然后才被写到磁盘上。但是对于这种标准的访问文件的方式来说,在数据被写到页缓存中的时候,write()系统调用就算执行完成,并不会等数据完全写入到磁盘上。Linux在这里采用的是我们前边提到的延迟写机制( deferred writes)。如果用户采用的是延迟写机制( deferred writes),那么应用程序就完全不需要等到数据全部被写回到磁盘,数据只要被写到页缓存中去就可以了。在延迟写机制的情况下,操作系统会定期地将放在页缓存中的数据刷到磁盘上。

 

直接IO

凡是通过直接 I/O方式进行数据传输,数据均直接在用户地址空间的缓冲区和磁盘之间直接进行传输,完全不需要页缓存的支持。操作系统层提供的缓存往往会使应用程序在读写数据的时候获得更好的性能,但是对于某些特殊的应用程序,比如说数据库管理系统这类应用,他们更倾向于选择他们自己的缓存机制,因为数据库管理系统往往比操作系统更了解数据库中存放的数据,数据库管理系统可以提供一种更加有效的缓存机制来提高数据库中数据的存取性能。

简单说来,page cache用来缓存文件数据,buffer cache用来缓存磁盘数据。在有文件系统的情况下,对文件操作,那么数据会缓存到page cache,如果直接采用dd等工具对磁盘进行读写,那么数据会缓存到buffer cache

补充一点,在文件系统层每个设备都会分配一个def_blk_ops的文件操作方法,这是设备的操作方法,在每个设备的inode下面会存在一个radix tree,这个radix tree下面将会放置缓存数据的page页。这个page的数量将会在top程序的buffer一栏中显示。如果设备做了文件系统,那么会生成一个inode,这个inode会分配ext3_ops之类的操作方法,这些方法是文件系统的方法,在这个inode下面同样存在一个radix tree,这里会缓存文件的page页,缓存页的数量在top程序的cache一栏进行统计。从上面的分析可以看出,2.6内核中的buffer cachepage cache在处理上是保持一致的,但是存在概念上的差别,page cache针对文件的cachebuffer是针对磁盘块数据的cache,仅此而已。

"如果一个进程读取某个文件,那么其他进程就都不可以读取或者更改该文件;"对这一句话存在质疑。

原文

http://blog.chinaunix.net/uid-1829236-id-3152172.html

分享到:
评论

相关推荐

    springmodules-cache.xsd&springmodules-ehcache.xsd.rar

    解决web.xml中 <page-encoding>UTF-8</page-encoding>报错。错误提示: cvc-complex-type.2.4.a: Invalid content was found starting with element 'page-encoding'. One of '{"http:// java.sun....

    微软内部资料-SQL性能优化2

    The system address space is where the kernel, executive, HAL, boot drivers, page tables, pool, and system cache reside. For specific information regarding address space layout, refer to Inside ...

    Bochs - The cross platform IA-32 (x86) emulator

    - NE2K: Fixed "send buffer" command issue on big endian hosts - USB - converted common USB code plus devices to the new 'usb_common' plugin Now the USB device classes no longer exist twice if both...

    The Indispensable PC Hardware Book - rar - part1. (1/7)

    Page Directory, page tables, and page frames. Test registers TR6 and TR7. Virtual 8086 mode. Virtual machines and virtual 8086 monitors. Addresses in virtual 8086 mode. Entering and leaving ...

    php.ini-development

    user_ini.cache_ttl = 300 ;;;;;;;;;;;;;;;;;;;; ; Language Options ; ;;;;;;;;;;;;;;;;;;;; ; Enable the PHP scripting language engine under Apache. ; http://php.net/engine engine = On ; This directive...

    SimIt-ARM-3.0 ARM指令模拟器

    SimIt-ARM-3.0 给予命令行ARM指令模拟器,短小精悍,是研究ARM处理器的好工具,该模拟器既可以运行用户级别的ELF程序,又可以模拟运行Linux操作系统;提供了简单易用的调试命令,可以逐条跟踪指令的执行。...

    BURNINTEST--硬件检测工具

    - Updated Level 2 and Level 3 CPU cache information for newer Intel CPU's. - Updated the detection of Hyperthreading and the number of logical CPUs for a new Intel CPU. Release 5.3 build 1025 WIN32...

    asp.net 开发的一些常用技巧

    不使用页面缓存: 你可以在不想被缓存的页面Page_Load事件中加上如下代码 代码如下:Response.Expires = 0; Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); Response.AddHeader...

    验证码下载jsp

    <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" ...

    Oracle DBA的UNIX袖珍参考手册之服务器监控

    Buffer cache hit ratio (for the Unix JFS buffer cache) for write requests pread/s Number of reads per second from disk pwrit/s Number of writes per second to disk 3. 使用 vmstat vmstat 是通用的 UNIX...

    ARM_Linux启动分析.pdf

    创建和设置内部及通用cache("slab_cache",kmem_cache_sizes_init()) 创建uid taskcount SLAB cache("uid_cache",uidcache_init()) 创建文件cache("files_cache",filescache_init()) 创建目录cache(...

    Wrox.Professional.Linux.Kernel.Architecture.

    Chapter 16: Page and Buffer Cache949 Chapter 17: Data Synchronization . 989 Chapter 18: Page Reclaim and Swapping. 1023 Chapter 19: Auditing 1097 Appendix A: Architecture Specifics . 1117 Appendix B:...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    When true then in ftmPanning mode the whole document image cache created in currect scale. - FIX: Support for the Import/Export modules that can't work with Streams. Added TFlexFileFormat....

    PHP 实现页面静态化的几种方法

    1、通过buffer来实现 需要用file_put_contents ob_get_clean()...$pageCache = str_replace('submit2','login',ob_get_contents());//将缓存去中的内容替换 ob_end_clean(); echo $mtime; echo $pageCache; 2、通过$_SE

    计算机网络第六版答案

    exploiting the buffer overflow vulnerability that might exist in an application). After finding the vulnerability, the attacker needs to scan for hosts that are vulnerable. The target is basically to...

    SQL Server性能调优之缓存

    在执行任何查询时,SQL Server都会将数据...Data Cache是存储数据页(Data Page)的缓冲区,当SQL Server需要读取数据文件(File)中的数据页(Data Page)时,SQL Server会把整个Page都调入内存(内存中的一个Page叫

    uboott移植实验手册及技术文档

    实验三 移植U-Boot-1.3.1 实验 【实验目的】 了解 U-Boot-1.3.1 的代码结构,掌握其移植方法。 【实验环境】 1、Ubuntu 7.0.4发行版 2、u-boot-1.3.1 3、FS2410平台 4、交叉编译器 arm-softfloat-linux-gnu-...

    The Art of Assembly Language Programming

    The 886 Processor 3.3.11 - The 8286 Processor 3.3.12 - The 8486 Processor 3.3.12.1 - The 8486 Pipeline 3.3.12.2 - Stalls in a Pipeline 3.3.12.3 - Cache, the Prefetch Queue, and the ...

    JLink_Windows_V648.zip

    DLL: Under some circumstances Flash Cache was not cleaned after erase operations. DLL: Unsecure read protection for STM32L151xx series devices, fixed. DLL: Unsecure write protection for STM32L151xxx ...

    Linux-0.11 [内核源代码带中文注释]

    buffer cache as in minix ! ! The loader has been made as simple as possible, and continuos ! read errors will result in a unbreakable loop. Reboot by hand. It ! loads pretty fast by getting whole ...

Global site tag (gtag.js) - Google Analytics