Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to traverse page cache tree (radix tree) of a file address space in linux kernel

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.

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.

like image 608
Sushmita Bhattacharya Avatar asked Sep 28 '22 04:09

Sushmita Bhattacharya


1 Answers

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");                 
    }
}
like image 196
Sushmita Bhattacharya Avatar answered Oct 06 '22 01:10

Sushmita Bhattacharya