在linux中获取pte页面

时间:2013-09-03 11:40:44

标签: linux linux-kernel kernel paging

我正在尝试编写获取页面的代码并在Linux内核中返回PTE(页表条目)。

函数的原型应该是这样的:

static pte_t getPteOfPage(struct page *page);

我试图在页面的结构描述中找到页面的PTE,但它更复杂。

有人能说明怎么做吗?

1 个答案:

答案 0 :(得分:1)

查看walk_page_range函数的良好起点。

/**
 143 * walk_page_range - walk a memory map's page tables with a callback
 144 * @addr: starting address
 145 * @end: ending address
 146 * @walk: set of callbacks to invoke for each level of the tree
 147 *
 148 * Recursively walk the page table for the memory area in a VMA,
 149 * calling supplied callbacks. Callbacks are called in-order (first
 150 * PGD, first PUD, first PMD, first PTE, second PTE... second PMD,
 151 * etc.). If lower-level callbacks are omitted, walking depth is reduced.
 152 *
 153 * Each callback receives an entry pointer and the start and end of the
 154 * associated range, and a copy of the original mm_walk for access to
 155 * the ->private or ->mm fields.
 156 *
 157 * Usually no locks are taken, but splitting transparent huge page may
 158 * take page table lock. And the bottom level iterator will map PTE
 159 * directories from highmem if necessary.
 160 *
 161 * If any callback returns a non-zero value, the walk is aborted and
 162 * the return value is propagated back to the caller. Otherwise 0 is returned.
 163 *
 164 * walk->mm->mmap_sem must be held for at least read if walk->hugetlb_entry
 165 * is !NULL.
 166 */

请参阅walk_page_range函数实现,以获得一个很好的示例。