gpt4 book ai didi

linux - 在 linux 中获取页面的 pte

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

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

函数的原型(prototype)应该是这样的:

static pte_t getPteOfPage(struct page *page);

我试图在页面的struct描述中找到该页面的PTE,但是比较复杂。

谁能告诉我怎么做?

最佳答案

查看 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函数实现,一个很好的例子。

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

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