Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux - identify process owning a specific address in physical memory

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.

like image 917
avalys Avatar asked Feb 24 '09 20:02

avalys


People also ask

Does each process have its own address space?

A Computer ProcessEach process has a separate memory address space, which means that a process runs independently and is isolated from other processes. It cannot directly access shared data in other processes.

What does the Linux kernel do if it runs out of all physical and virtual memory?

If the kernel is unable to provide a new memory page, all it can do is kill the requesting process, or kill some other process to fill the memory.

What is Dev MEM?

/dev/mem is a character device file that is an image of the main memory of the computer. It may be used, for example, to examine (and even patch) the system. Byte addresses in /dev/mem are interpreted as physical memory addresses. References to nonexistent locations cause errors to be returned.


2 Answers

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. A change went into the kernel that might be almost exactly what you're looking for:

author  Arjan van de Ven <[email protected]>    2008-04-17 15:40:45 (GMT) 
committer   Ingo Molnar <[email protected]>                 2008-04-17 15:40:45 (GMT)
commit  926e5392ba8a388ae32ca0d2714cc2c73945c609 (patch)
tree    2718b50b8b66a3614f47d3246b080ee8511b299e
parent  2596e0fae094be9354b29ddb17e6326a18012e8c (diff) 

x86: add code to dump the (kernel) page tables for visual inspection by kernel developers 

This patch adds code to the kernel to have an (optional)
/proc/kernel_page_tables debug file that basically dumps the kernel
pagetables; this allows us kernel developers to verify that nothing
fishy is going on and that the various mappings are set up correctly.
This was quite useful in finding various change_page_attr() bugs, and
is very likely to be useful in the future as well. 

Signed-off-by:Arjan van de Ven <[email protected]> 
Cc: [email protected] 
Cc: [email protected] 
Cc: [email protected] 
Signed-off-by: Ingo Molnar <[email protected]> 
Signed-off-by: Thomas Gleixner <[email protected]>

The added functionality is enabled by a new config option (X86_PTDUMP).

like image 90
Mark Johnson Avatar answered Oct 21 '22 03:10

Mark Johnson


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.

like image 38
Eric Petroelje Avatar answered Oct 21 '22 04:10

Eric Petroelje