简体   繁体   English

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

[英]How to get the physical address of a huge-page

I need to get the physical address of a huge-page (2 MB) from user-space. 我需要从用户空间获取大页面(2 MB)的物理地址。 I managed to get the physical address of a normal 4 KB page from pagemap as shown in https://shanetully.com/2014/12/translating-virtual-addresses-to-physcial-addresses-in-user-space/#codeprocpidpagemapcode however I don't understand how I should use pagemap to get the physical address of a huge-page. 我设法从页面地图获取正常4 KB页面的物理地址,如https://shanetully.com/2014/12/translating-virtual-addresses-to-physcial-addresses-in-user-space/#codeprocpidpagemapcode所示但是我不明白我应该如何使用pagemap来获取大页面的物理地址。 How is a huge-page page frame number represented in pagemap? 如何在页面映射中表示巨大的页面页框号? Any references and especially any piece of code would be highly appreciated. 任何参考,特别是任何代码都将受到高度赞赏。

It should be the same. 应该是一样的。 The primary difference between normal pages and huge pages are a few layers of the page tables. 普通页面和大页面之间的主要区别是页面表的几层。 The page table walk ends early for huge pages (at least on x86). 对于大页面(至少在x86上),页表行程提前结束。

Huge-pages generally end in more zeros than typical pages, as they need to be aligned to their size (in the 2MB case, the low 21 bits should all be zero). 巨页通常以比典型页面更多的零结束,因为它们需要与它们的大小对齐(在2MB的情况下,低21位应该都是零)。

If you are getting -EINVAL from your reads, check out this quote from the pagemap documentation (the example reads the wrong number of bytes): 如果从读取中获取-EINVAL,请从页面地图文档中查看此引用(该示例读取错误的字节数):

Reading from any of the files will return -EINVAL if you are not starting the read on an 8-byte boundary (eg, 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. 如果您没有在8字节边界上开始读取(例如,如果您在文件中寻找奇数个字节),或者如果读取的大小不是多个,则从任何文件读取将返回-EINVAL 8个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从结构页中获取关联数据的物理地址? - How to get the physical address of the associated data from a struct page? 如何获取C指针的物理地址作为值? - How to get the Physical address of a C pointer as a value? 如何从用户空间获取 FreeBSD 中任何地址的物理地址? - How to get physical address for any address in FreeBSD from userspace? 如何在Linux中以编程方式获取物理内存地址范围 - how to programmatically get physical memory address range in linux 如何获得巨大页面尺寸的价值? - How to get the value of huge page size? 如果 CPU 看到虚拟地址,页面错误处理程序如何用物理地址填充页表条目? - How does page fault handler fill up the page table entry with a physical address if CPU sees virtual addresses? 如何将kmalloc()地址转换为物理地址 - How to convert kmalloc() address to physical address 如何在内核模块(x86-64)中将物理地址转换为内核页面结构? - How to convert physical address to kernel page structure inside kernel module (x86-64)? 我们如何为变量指定物理地址? - How can we specify physical address for variable? 如何通过虚拟寻址区域中的指针获取物理寻址区域中的地址? - How can I get address in physical addressing area by pointer in virtual addressing area?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM