我正在尝试在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内核中有一个代码可以执行类似的操作(例如:当写入页面并在缓存中搜索页面时),但我没有找到它...
谢谢!
答案 0 :(得分:3)
address_space
结构包含radix_tree
中的所有网页(在您的情况下为mapping->page_tree
)。所以你需要的是迭代那棵树。 Linux内核具有基数树API(参见here),包括for_each
迭代器。对于eaxmple:
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