12

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?

PersianGulf
  • 2,845
  • 6
  • 47
  • 67

2 Answers2

4

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

Dmitry
  • 310
  • 4
  • 5
  • why `offset` is not used in this function? I refer to `offset` as the 3rd filed in a `maps` entry – Paschalis Nov 12 '14 at 17:57
  • Is is the case that `maps` entry `offset` is the offset of the particular file/device+inode that is backing the mapping? – Paschalis Nov 12 '14 at 17:58
  • Paschalis, I didn't quite get your question, but are you referring to "Bits 5-54 swap offset if swapped" from here: https://www.kernel.org/doc/Documentation/vm/pagemap.txt ? – Dmitry Mar 06 '15 at 02:27
  • Hmm... I don't even get the question I asked you some time ago. It seems that I was expecting `offset` of the `maps` entry to be used for indexing the pagemaps file. – Paschalis Mar 06 '15 at 09:37
2

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

Larry_C
  • 316
  • 1
  • 9