Reputation: 454
I need to get the physical address of a huge-page (2 MB) from user-space. 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. How is a huge-page page frame number represented in pagemap? Any references and especially any piece of code would be highly appreciated.
Upvotes: 5
Views: 3528
Reputation: 2207
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).
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).
If you are getting -EINVAL from your reads, check out this quote from the pagemap documentation(the example reads the wrong number of bytes):
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.
Upvotes: 1