c - 如何获取大页面的物理地址

标签 c linux linux-kernel huge-pages

我需要从用户空间获取大页面 (2 MB) 的物理地址。我设法从页面映射中获取了普通 4 KB 页面的物理地址,如 https://shanetully.com/2014/12/translating-virtual-addresses-to-physcial-addresses-in-user-space/#codeprocpidpagemapcode 所示。但是我不明白我应该如何使用页面映射来获取大页面的物理地址。页面映射中如何表示大页面页面框架编号?任何引用,尤其是任何代码片段,我们都将不胜感激。

最佳答案

应该是一样的。普通页面和大页面之间的主要区别在于页表的几层。大页面的页表遍历提前结束(至少在 x86 上)。

大页面通常比典型页面以更多的零结尾,因为它们需要与其大小对齐(在 2MB 的情况下,低 21 位应全部为零)。

如果您从阅读中得到 -EINVAL,请查看 pagemap documentation 中的这句话(示例读取了错误的字节数):

Reading from any of the files will return -EINVAL if you are not starting the read on an 8-byte boundary (e.g., if you sought an odd number of bytes into the file), or if the size of the read is not a multiple of 8 bytes.

关于c - 如何获取大页面的物理地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556216/

相关文章:

c - 如何更改 CFS 中使用的数据结构

将 byte* 转换为十六进制字符串

c - 两段几乎相同的代码出错

编译错误 "s is undeclared,"但它是 `scanf` 的结果

linux - "kill 0"和 "kill -‍- -$$"有什么区别?

regex - 替补中的坏旗

javascript - 无法在 Ubuntu 上打开 VS Code

linux-kernel - 通用 netlink - PID 不是线程唯一的

c - 内核的哪一部分加载了PS3的framebuffer模块?

android - 使用 gcc 的 C++ 前端编译 C 代码的好处