在内存中查找Process(linux-kernel)页面

时间:2013-11-16 23:19:59

标签: c memory linux-kernel operating-system

基本上我有一个程序可以找到进程的所有VMA,但我想查看页面表中该页面的页面。我很难过。我知道进程的task_struct有一个字段

pgd_t                  *pgd;                /* page global directory */

这只是所有页面的索引数组吗?

我在“/mm/memory.c”

中找到了这个功能
/*
* Do a quick page-table lookup for a single page.
*/
struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
                    unsigned int flags)

我可以传递一个VMA,但我不确定地址和标志应该是什么。或许这不是我想要的?有什么建议吗?

1 个答案:

答案 0 :(得分:2)

听起来你想做一个基本的页面漫步。

给定pgd,您可以遍历查找有效pud的条目,然后遍历pud等等。< / p>

执行此操作的一种方法是使用以下内容:

// iterate through your address space
for (i = 0; i < PAGE_SIZE / sizeof(*pud); i++) {
    pud = pud_offset(pgd, PUD_SIZE * i);
    // Check if the pud is valid
    if (pud_none(*pud) || pud_bad(*pud))
        continue;
    // And so on
}