Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1668336
  • 博文数量: 1493
  • 博客积分: 38
  • 博客等级: 民兵
  • 技术积分: 5834
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 17:28
文章分类

全部博文(1493)

文章存档

2016年(11)

2015年(38)

2014年(137)

2013年(253)

2012年(1054)

2011年(1)

分类:

2012-11-19 12:38:45

原文地址:linux内核之页高速缓存 作者:jeffchencsj

/概述页高速缓存(page cache
1.
页高速缓存是Linux内核所使用的主要磁盘高速缓存。
2.
页高速缓存中可能包含的内容:a,含有普通文件数据的页;b,含有目录的页;c,含有直接从块设备文件读出的
数据的页;d,含有用户态进程数据的页;e,属于特殊文件系统文件的页。注:内核的代码和内核数据不必从磁盘
读也不必写入磁盘,因此页高速缓存中不可能有。
/页高速缓存的组织
1.
页高速缓存的核心数据结构是address_space对象,它是一个嵌入在页所有者的索引节点对象中的数据结构。
页描述符的struct address_space* mapping 字段指向address_space,unsigned long index 标志存放所有者的
磁盘映像中页中数据的位置。
2.
如果页属于一个文件,那么页的所有者就是文件的索引节点,而且相应的address_space对象存放在VFS索引
节点对象的i_data字段中。索引节点的i_mapping 字段指向同一个索引节点的i_data字段,而address_space
对象的host字段也指向这个索引节点。
3.address_space
对象的关键字段是a_ops,它指向一个类型为address_space_operations的表,表中定义了对所有
者的页进行各种操作的方法。

    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 */

    unsigned int i_mmap_writable;/* count VM_SHARED mappings */

    struct prio_tree_root i_mmap; /* tree of private and shared mappings */

    struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */

    spinlock_t i_mmap_lock; /* protect tree, count, list */

    unsigned int truncate_count; /* Cover race condition with truncate */

    unsigned long nrpages; /* number of total pages */

    pgoff_t writeback_index;/* writeback starts here */

    const struct address_space_operations *a_ops; /* methods */

    unsigned long flags; /* error bits/gfp mask */

    struct backing_dev_info *backing_dev_info; /* device readahead, etc */

    spinlock_t private_lock; /* for use by the address_space */

    struct list_head private_list; /* ditto */

    struct address_space *assoc_mapping; /* ditto */

    } __attribute__((aligned(sizeof(long))));

4.每个address_space对象对应一颗搜索树,address_space对象的page_tree字段是基树(radix tree)的根,
它指向所有者的页描述符的指针。

/页高速缓存的处理函数
1.
查找页:a,find_get_page()//以指向address_space对象的指针和偏移量为参数,返回改页的地址或NULL
                 b,find_lock_page()//
与上类似,只是可以让调用者互斥的访问返回的页。
2.
增加页:add_to_page_cache()//把一个新页的描述符插入到页高速缓存。参数:页描述符的地址page,
address_space
对象的地址mapping,表示地址空间内页索引值的offset,为基树分配新节点时所使用的内存
分配标志gfp_mask
3.
删除页:remove_from_page_cache()
4.
更新页:read_cache_page()
/把块放在页高速缓存中
1.VFS
和各种文件系统以叫做块的逻辑单位组织磁盘数据。所以一个页中存放有几个块,那么如何找到页中相应的
块呢?每个块缓冲区都有buffer_head类型的缓冲去首部描述符,该描述符包含内核必须了解的有关如何处理块
的所有信息。
2.
缓冲区首部的管理

一个页包含多个块缓冲,每个块缓冲都有缓存器首部管理,而每个页描述符中包含多个缓冲区首部。这样就完成

块缓冲区的管理。

阅读(278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~