Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using /proc/[pid]/pagemap

I am aware that there is a little information regarding the pagemap file here. But nobody seems to indicate how to reference entries in the file. Is it offset by virtual address? Can I take a virtual address VA and simply lseek to offset VA? Or is it by page? If so, how do I retrieve the page number, as maps simply lists them in order. I am trying to translate between virtual and physical addresses, and lseek'ing with the virtual address as the offset always returns the same number, no matter where I seek to.

Thanks

@leeduhem: Yes I have. Here's the relevant part: 3. Open /proc/pid/pagemap and seek to the pages you would like to examine. 4. Read a u64 for each page from pagemap.

That doesn't help me. It wants me to seek to the page, but how do I know where the entry for the page is?

like image 329
HorseHair Avatar asked Feb 20 '14 02:02

HorseHair


2 Answers

There is a tool that will help you to get information you need from the pagemap file.

http://fivelinesofcode.blogspot.com/2014/03/how-to-translate-virtual-to-physical.html

like image 65
Dmitry Avatar answered Sep 20 '22 01:09

Dmitry


You divide the virtual address by the pagesize (normally 0x1000 or 4096) and use that to index in /proc/self/pagemap. After the division, that's known as the PFN, or page frame number.

Larry

like image 23
Larry_C Avatar answered Sep 18 '22 01:09

Larry_C