gpt4 book ai didi

linux - 从页面缓存中获取所有页面

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:56:04 24 4
gpt4 key购买 nike

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

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

我看到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 内核中有一段代码会做这样的事情(例如:当有一个页面被写入并且在缓存中搜索该页面时),但我没有找到它......

谢谢!

最佳答案

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

关于linux - 从页面缓存中获取所有页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com