How to navigate the page cache tree (radix tree) of file address space in linux kernel

I need to get statistics on the open file cache pages. The file structure has an address_space ( f_mapping ) pointer , which in turn has the root of the page_tree base tree . I need to go through this tree to get information about all cached pages for this open file.

There are several functions, such as radix_tree_for_each_chunk (for iterating over chunks), radix_tree_for_each_chunk_slot (for repeating over slots in one fragment), etc., using these features. I am not sure about the correct use (arguments) of the same. It would be helpful if an example were published.

+4
source share
1 answer

I understood this from the source code of the Linux kernel.

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");                 
    }
}
+2
source

Source: https://habr.com/ru/post/1584489/


All Articles