如何遍历Linux内核中文件地址空间的页面缓存树(基数树) [英] how to traverse page cache tree (radix tree) of a file address space in linux kernel

查看:232
本文介绍了如何遍历Linux内核中文件地址空间的页面缓存树(基数树)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取打开文件的页面缓存统计信息.文件结构中有一个address_space指针( f_mapping ),该指针又具有名为 page_tree 的基数树的根.我需要遍历该树以获取有关该打开文件的所有缓存页面的信息.

I need to get page-cache statistics of an open file. There is a address_space pointer(f_mapping) in file struct which in turn has the root of the radix tree called page_tree. I need to traverse that tree to get information about all the cached pages for that open file.

有一些功能,例如 radix_tree_for_each_chunk (用于遍历块), radix_tree_for_each_chunk_slot (用于遍历一个块中的插槽)等,使用这些功能可以实现.我不确定是否正确使用(参数).如果发布任何示例,将很有帮助.

There are some functions like radix_tree_for_each_chunk(to iterate over chunks), radix_tree_for_each_chunk_slot (to iterate over slots in one chunk) etc, using these the functionality can be achieved. I am unsure about the proper use (arguments) of the same. It would be helpful if any example is posted.

推荐答案

我从Linux内核源代码中弄清楚了.

I figured it out from Linux kernel source code.

struct file *file = filp_open("filename",O_RDONLY,0);
struct address_space *file_addr_space = file->f_mapping;            
if(file_addr_space==NULL){
    printk("error")
}           
struct radix_tree_root file_page_tree_root  = file_addr_space->page_tree;   //contains all pages in page cache                                      
struct radix_tree_iter iter;            
void **slot;            
int num_dirty = 0;
radix_tree_for_each_slot(slot,&file_page_tree_root,&iter,0){
    struct page *page = radix_tree_deref_slot(slot);
    if(page!=NULL){
        //printk("information about page");                 
    }
}

这篇关于如何遍历Linux内核中文件地址空间的页面缓存树(基数树)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆