【问题标题】:get all pages from the page cache从页面缓存中获取所有页面
【发布时间】:2013-09-10 08:32:54
【问题描述】:

我正在尝试在 Linux 内核空间中编写一个遍历页面缓存并搜索包含特定块的页面的函数。

我不知道如何逐一获取页面缓存中的页面。

我看到find_get_page是一个可以帮助我的函数,但是我不知道如何获取首页偏移量以及如何继续。 正如我所说,我正在尝试做这样的事情:

for(every page in struct address_space *mapping)
{
    for(every struct buffer_head in current_page->buffers)
    {
        check if(my_sector == current_buffer_head->b_blocknr)
            ...
    }
}

谁能帮助找到如何遍历所有页面缓存?

我相信Linux内核中有一段代码会做这样的事情(例如:当有一个页面写入并且在缓存中搜索该页面时),但我没有找到它......

谢谢!

【问题讨论】:

    标签: linux caching linux-kernel kernel paging


    【解决方案1】:

    address_space 结构包含radix_tree 中的所有页面(在您的情况下为mapping->page_tree)。所以你只需要遍历那棵树。 Linux 内核具有基数树 API(参见 here),包括 for_each 迭代器。例如:

    396 /**
    397  * radix_tree_for_each_chunk_slot - iterate over slots in one chunk
    398  *
    399  * @slot:       the void** variable, at the beginning points to chunk first slot
    400  * @iter:       the struct radix_tree_iter pointer
    401  * @flags:      RADIX_TREE_ITER_*, should be constant
    402  *
    403  * This macro is designed to be nested inside radix_tree_for_each_chunk().
    404  * @slot points to the radix tree slot, @iter->index contains its index.
    405  */
    406 #define radix_tree_for_each_chunk_slot(slot, iter, flags)               \
    407         for (; slot ; slot = radix_tree_next_slot(slot, iter, flags))
    408 
    

    【讨论】:

      猜你喜欢
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 2012-02-05
      相关资源
      最近更新 更多