[Linux内存]页缓存和块缓存
2015-08-01 17:42
519 查看
1, 内核为设备提供了两种通用的缓存方案:
a, 页缓存(page cache)
b, 块缓存
2,内核管理页缓存所用的数据结构
内核通过基数树(radix tree)来管理页缓存的,
3,内核如何回写内存中修改的数据到物理设备
a, 内核的守护进程在后台运行,为pdflush,这些守护进程周期性激活,
b, pdflush的第二种运作模式是:如果缓存中修改的数据项目数目在短期内显著增加,则由内核激活pdflush.
c,内核提供了相关的系统调用,如sync()
4,地址空间的概念
页缓存中的页是通过地址空间(address_space)来和物理设备内存(如底层文件系统的struct inode结构)相互关联的。对应与page结构的struct address_space *mapping成员。
(1) 如果page->mapping等 于0,说明该页属于交换告诉缓存swap cache
(2) 如果page->mapping不 等于0,但第0位为0,说明该页为匿名也,此时mapping指向一个struct anon_vma结构变量;
(3) 如果page->mapping不 等于0,但第0位不为0,则apping指向一个struct address_space地址空间结构变量;
};
比如页高速缓存中页的拥有者是一个文件的时候,那么此时索引节点的i_mapping字段总是指向索引节点的数据页所有者的address_space.而address_space对象就嵌入在VFS索引节点对象的i_data字段中。而address_space中的字段host则指向它所有者的索引节点对象。
5,页缓存的常用操作函数
页高速缓存的还有几个常用处理函数:查找页,增加页,删除页更新页。
a, 页缓存(page cache)
b, 块缓存
2,内核管理页缓存所用的数据结构
内核通过基数树(radix tree)来管理页缓存的,
3,内核如何回写内存中修改的数据到物理设备
a, 内核的守护进程在后台运行,为pdflush,这些守护进程周期性激活,
b, pdflush的第二种运作模式是:如果缓存中修改的数据项目数目在短期内显著增加,则由内核激活pdflush.
c,内核提供了相关的系统调用,如sync()
4,地址空间的概念
页缓存中的页是通过地址空间(address_space)来和物理设备内存(如底层文件系统的struct inode结构)相互关联的。对应与page结构的struct address_space *mapping成员。
(1) 如果page->mapping等 于0,说明该页属于交换告诉缓存swap cache
(2) 如果page->mapping不 等于0,但第0位为0,说明该页为匿名也,此时mapping指向一个struct anon_vma结构变量;
(3) 如果page->mapping不 等于0,但第0位不为0,则apping指向一个struct address_space地址空间结构变量;
struct address_space { struct inode *host; /*拥有节点*/ struct radix_tree_root page_tree; /*包含全部页面的radix树 */ spinlock_t tree_lock; /*保护page_tree的自旋锁*/ unsigned int i_mmap_writable; /* VM_SHARED计数*/ struct prio_tree_root i_mmap; /*私有映射链表*/ struct list_head i_mmap_nonlinear; /* VM_NONLINEAR 链表*/ spinlock_t i_mmap_lock; /* 保护i_mmap的自旋锁 */ atomic_t truncate_count; /* 截断计数*/ unsigned long nrpages; /* 页总数*/ pgoff_t writeback_index; /* 回写的起始偏移*/ struct address_space_operations *a_ops; /* 操作表*/ unsigned long flags; /* gfp_mask 掩码与错误标识*/ struct backing_dev_info *backing_dev_info; /*预读信息*/ spinlock_t private_lock; /*私有address_space锁*/ struct list_head private_list; /*私有address_space链表*/ struct address_space *assoc_mapping; /*相关的缓冲*/
};
比如页高速缓存中页的拥有者是一个文件的时候,那么此时索引节点的i_mapping字段总是指向索引节点的数据页所有者的address_space.而address_space对象就嵌入在VFS索引节点对象的i_data字段中。而address_space中的字段host则指向它所有者的索引节点对象。
5,页缓存的常用操作函数
页高速缓存的还有几个常用处理函数:查找页,增加页,删除页更新页。
struct page * find_get_page(struct address_space *mapping, unsigned long offset) unsigned find_get_pages(struct address_space *mapping, pgoff_t start,unsigned int nr_pages, struct page **pages) struct page *find_lock_page(struct address_space *mapping,unsigned long offset) struct page *find_trylock_page(struct address_space *mapping, unsigned long offset) struct page *find_or_create_page(struct address_space *mapping,unsigned long index, unsigned int gfp_mask) int add_to_page_cache(struct page *page, struct address_space *mapping,pgoff_t offset, int gfp_mask) remove_from_page_cache(struct page *page)
相关文章推荐
- Linux下安装软件遇见的问题汇总
- linux解决xhost: unable to open display ""
- [C] zintrin.h : 智能引入intrinsic函数。支持VC、GCC,兼容Windows、Linux、Mac OS X
- linux 问题总结
- centos中文乱码
- Linux常用命令-文件处理命令
- Linux下gcc编译生成动态链接库*.so文件并调用它
- Linux 命令行快捷键
- linux下创建和删除软、硬链接
- linux安装
- 在linux上移植xserver、tslib、gtk和桌面系统(用buildroot)
- linux 常用(二)常用文件操作命令
- 在CentOS上搭建LAMP+vsftpd环境的简单指南
- linux下 echo 输出字体颜色的用法
- [odroid-pc] ubuntu12.04 安装jdk-6u45-linux-x64.bin
- centos6.5下postgres-XC集群安装与配置
- 网站移植,从window的WAMP 转移到线上linux的LNMP
- Linux下实现简单Echo中继服务器
- CentOS中MySQL的开机自动启动开启与关闭
- 高效Linux之Terminal下实用快捷键