How to deal with virtual address when trying to get memory access pattern statistics?

209 views Asked by At

I'm working on a project that needs to get statistics of memory access pattern of a program. (by memory access pattern, I mean a accessing probability distribution of different regions of memory)

I used Intel Pintool and have got the address of all instructions(Instruction Pointer) and the all memory addresses that is accessed in these instructions. The statistics are like this: in the format of:

fprintf(trace,"%p: R/W %p\n", ip, addr); //IP Read/Write addr

0x7f096b04e2d3: W 0x7fff17713f68
0x7f096b051a70: W 0x7fff17713f60
0x7f096b051a74: W 0x7fff17713f58
0x7f096b051a76: W 0x7fff17713f50
0x7f096b051a78: W 0x7fff17713f48
0x7f096b051a7a: W 0x7fff17713f40
0x7f096b051a7c: W 0x7fff17713f38
0x7f096b051a8f: R 0x7f096b26fe70
0x7f096b051a96: W 0x7f096b26fc98
0x7f096b051aa7: R 0x7f096b270000

The questions is, in the perspective of CPU, these address are all Virtual Addr, which cannot be used if I want to get the physical memory access pattern.

Do you have any ideas?

1

There are 1 answers

0
hayesti On

I'm not sure if you can do that in Pin, but I don't think so. You might want to check out pagemap. This should at least give you a resource to translate the virtual addresses to physical addresses although you'll have to process it a little. From the documentation:

The general procedure for using pagemap to find out about a process' memory usage goes like this:

  1. Read /proc/pid/maps to determine which parts of the memory space are mapped to what.
  2. Select the maps you are interested in -- all of them, or a particular library, or the stack or the heap, etc.
  3. Open /proc/pid/pagemap and seek to the pages you would like to examine.
  4. Read a u64 for each page from pagemap.
  5. Open /proc/kpagecount and/or /proc/kpageflags. For each PFN you just read, seek to that entry in the file, and read the data you want.