zoukankan      html  css  js  c++  java
  • page cache & buffer cache

    What is the major difference between the buffer cache and the page cache? Why were they separate entities in older kernels? Why were they merged later on?

    表述page cache与buffer cache的区别:
    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与buffer cache间的存在冗余:
    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.
     
    介绍是如何优化page cache与buffer cache的:
    This is simple to implement, but with an obvious inelegance and 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.
     
     
    这里讲述了buffer cache为什么还保留,及其存在的意义:
    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与Page cache的区别是什么?为什么它们在旧内核中是独立的实体?为什么后来它们合并了?

    区别:Page cache对应文件系统(file sysem),Page cache缓存文件的页(page),用来优化文件I/O。Buffer cache对应磁盘(disk),Buffer cache缓存磁盘的块(block)。

    缺点:在Linux内核2.4版本之前,这两个cache是不同的。文件在page cache中,磁盘块在buffer cache中。由于文件是由磁盘上的文件系统表示的,因此数据被表示了两份,每个cache中拥有一份(这里是说page cache和buffer cache中缓存了相同的数据)。

    这样很容易实现,但是存在不雅和低效。

    优化:从Linux内核版本2.4开始,两个cache的内容统一了。虚拟内存子系统现在驱动I/O,它从page cache中这样做。如果缓存的数据同时具有文件和块的表示,正如大多数数据所做的那样,buffer cache将简单的指向page cache,因此只有一份数据缓存在内存中。当你想到磁盘缓存的时候,你就会想到page cache。


    然而,buffer cache依然存在,因为内核仍然需要根据块(block)而不是页面(page)来执行block I/O。由于大多数的块表示文件数据,所以大多数的buffer cache由page cache表示。但是少量的块数据不是文件备份的,例如元数据和原始的块I/O,因此只能由buffer cache表示。

    =============================================

    file -> inode -> address_page -> page_cache

    link:

    https://blog.csdn.net/iter_zc/article/details/44195731

    https://manybutfinite.com/post/page-cache-the-affair-between-memory-and-files/

  • 相关阅读:
    最长公共子序列-动态规划
    归并排序
    最大子段和-3种方法
    kafka compaction 分析(基于kafka 0.10.2版本)
    [转载]interp1
    [转]mat2gray函数原理分析
    Java 位运算(移位、位与、或、异或、非)与逻辑运算
    ML01a
    [第1集] 机器学习的动机与应用
    tap4fun公司面试总结
  • 原文地址:https://www.cnblogs.com/zcqkk/p/9844185.html
Copyright © 2011-2022 走看看