views:

441

answers:

4

Under Linux, how can I tell what specific process owns / is using a given address in physical memory?

I understand that this may require writing a kernel module to access some kernel data structure and return the results to a user - I need to know how it can be done, regardless of how complicated it is.

+1  A: 

Might want to start here for a discusson of how process virtual memory is mapped to physical memory. That would give you a good place to start as far as figuring out where you would need to hook into the kernel to access the page table, etc. where that information is stored.

Eric Petroelje
A: 

Well due to the way things are done under Linux, a process may own memory at one instance, and then will not anymore, due to paging.

http://en.wikipedia.org/wiki/Paging

Essentially this means that the computer switches out data it doesn't need at one moment so that the memory can be used for something else.

I'm not sure if this helped or not, but I'd advise you to look at page tables and directories, since you can use these to translate to physical addresses.

samoz
+1  A: 

You might be able to use pmap -d [pid] for this... unfortunately you'd have to run it on all processes to see which one returned a result for the given memory address. Certainly not as efficient as a kernel module (and you might not even get a result, if the memory is paged out while you're looking for it).

David Zaslavsky
I don't believe this is correct. `pmap` reports virtual addresses. Physical addresses are only reported for devices, and not for main memory with this command. At least from what I can tell.
Matt Joiner
+5  A: 

The pages in use by a process and their location in physical memory are not static pieces of information. However, the information you seek should be in the page tables. This might be almost exactly what you're looking for.

Mark Johnson