How do I work with a virtual address when trying to get statistics on memory access patterns?

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

I used Intel Pintool and got the address of all instructions (instruction pointer) and all memory addresses that are accessed in those instructions. The statistics looks like this: in the format:

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

      

Questions, from a CPU perspective, these addresses are all Virtual Addr's that cannot be used if I want to get a physical memory access pattern.

Do you have any ideas?

+3


source to share


1 answer


I'm not sure if you can do this in Pin, but I don't think so. You can check pagemap . This should at least give you a resource for translating virtual addresses to physical addresses, although you'll have to do a little bit of processing. From the documentation:



The general procedure for using pagemap to figure out the "memory usage" process is as follows:

  • Read / proc / pid / maps to determine which parts of the memory space are mapped to which.
  • Select the cards you are interested in - all of them or a specific library, stack or heap, etc.
  • Open / proc / pid / pagemap and find the pages you would like to explore.
  • Read u64 for each page from pagemap.
  • Open / proc / kpagecount and / or / proc / kpageflags. For each PFN, you just read, look for that record in the file and read the data you want.
0


source







All Articles