linux页缓存作用,Linux缓存机制之页缓存

下图为地址空间与内核其他部分的关联。

dfd2132252e73a60873cdbe8cb9d36dc.gif

内核采用一种通用的地址空间方案,来建立缓存数据与其来源之间的关联。

1)内存中的页分配到每个地址空间。这些页的内容可以由用户进程或内核本身使用各式各样的方法操作。这些数据表示了缓存中的内容;

2)后备存储器structbacking_dev_info指定了填充地址空间中页的数据的来源。地址空间关联到处理器的虚拟地址空间,是由处理器在虚拟内存中管理的一个区域到设备device上对应位置之间的一个映射。

如果访问了虚拟内存中的某个位置,该位置没有关联到物理内存页,内核可根据地址空间结构来找到读取数据的来源。

为支持数据传输,每个地址空间都提供了一组操作,以容许地址空间所涉及双方面的交互。

地址空间是内核中最关键的数据结构之一,对该数据结构的管理,已经演变为内核面对的最关键的问题之一。页缓存的任务在于,获得一些物理内存页,以加速在块设备上按页为单位执行的操作。

内核使用了基数树来管理与一个地址空间相关的所有页,以便尽可能降低开销。对于基数树的理解在这里就不分析了,后面有空的时候再做分析。

地址空间操作

structaddress_space_operations {

/*将地址空间的一页或多页写回到底层设备

这是通过向块层发出一个相应的请求来完成的*/

int(*writepage)(structpage *page,structwriteback_control *wbc);

/*从后备存储器将一页或多个连续的页读入页帧*/

int(*readpage)(structfile *,structpage *);

/*对尚未回写到后备存储器的数据进行同步*/

void(*sync_page)(structpage *);

/* Write back some dirty pages from this mapping. */

int(*writepages)(structaddress_space *,structwriteback_control *);

/* Set a page dirty.  Return true if this dirtied it */

int(*set_page_dirty)(structpage *page);

int(*readpages)(structfile *filp,structaddress_space *mapping,

structlist_head *pages, unsigned nr_pages);

/*执行由write系统调用触发的写操作*/

int(*write_begin)(structfile *,structaddress_space *mapping,

loff_t pos, unsigned len, unsigned flags,

structpage **pagep,void**fsdata);

int(*write_end)(structfile *,structaddress_space *mapping,

loff_t pos, unsigned len, unsigned copied,

structpage *page,void*fsdata);

/* Unfortunately this kludge is needed for FIBMAP. Don't use it */

sector_t (*bmap)(structaddress_space *, sector_t);

void(*invalidatepage) (structpage *, unsignedlong);

int(*releasepage) (structpage *, gfp_t);

ssize_t (*direct_IO)(int,structkiocb *,conststructiovec *iov,

loff_t offset, unsignedlongnr_segs);

int(*get_xip_mem)(structaddress_space *, pgoff_t,int,

void**, unsignedlong*);

/* migrate the contents of a page to the specified target */

int(*migratepage) (structaddress_space *,

structpage *,structpage *);

int(*launder_page) (structpage *);

int(*is_partially_uptodate) (structpage *, read_descriptor_t *,

unsignedlong);

int(*error_remove_page)(structaddress_space *,structpage *);

};

32/3<123>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值