关于Linux内核页高速缓存的介绍网络上有很多优秀的资源如下:
1、Linux 内核之页高速缓存与页回写
https://www.jianshu.com/p/d33ec2707e7f
2、页高速缓存和页回写
https://blog.csdn.net/yusiguyuan/article/details/12022811
3、《Linux内核设计与实现》读书笔记(十六)页高速缓存和页回写
https://www.cnblogs.com/wang_yb/archive/2013/11/21/3436126.html
4、计算机底层知识拾遗(六)理解页缓存page cache和地址空间address_space
https://blog.csdn.net/ITer_ZC/article/details/44195731
5、Linux内核——第十五章:页高速缓存
https://blog.csdn.net/duxingxia356/article/details/41982771
本文主要讲述内核的查找页相关的处理函数。基于 linux-4.4.4
一、address_space
页高速缓存的核心数据时address_space对象,它是一个嵌入在页所有者的索引节点对象中的数据结构。高速缓存中的许多页可能属于同一个所有者,从而可能被链接到同一个address_space对象。该对象还在所有者的页和对这些页的操作之间建立起链接关系。
每个页描述符都包括把页链接到页高速缓存的两个字段mapping和index。mapping字段指向拥有页的索引节点的address_space对象,index字段表示在所有者的地址空间中以页大小为单位的偏移量,也就是在所有者的磁盘映射中页中数据的位置。在页高速缓存中查找时使用这两个字段。
address_space对象定义在include/linux/fs.h中,其内容如下:
struct address_space {
struct inode *host; /* owner: inode, block_device */
struct radix_tree_root page_tree; /* radix tree of all pages */
spinlock_t tree_lock; /* and lock protecting it */
atomic_t i_mmap_writable;/* count VM_SHARED mappings */
struct rb_root i_mmap; /* tree of private and shared mappings */
struct rw_semaphore i_mmap_rwsem; /* protect tree, count, list */
/* Protected by tree_lo