我需要从用户空间获取大页面 (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/