I would like to know, where the code and the data of the currently running processes are being placed physically in RAM. It should be very informative if it is possible to represent this distribution graphically, so that the distinctive process IDs are the points with distinctive colors. How and where to get this information? It looks like /proc doesn't provide it. Should I write a kernel module or a conventional user space application can also retrieve such info (if yes - how?) ?
I 100% agree with the "why would you?" comments.
But if you do want it, a kernel module could do it.
Given a virtual address in the current address space (if you run in a system call done from a process, the current process), you can translate it to the physical address.
Using the macros pgd_offset_k, pud_offset, pmd_offset, pte_offset in sequence, you should be able to get the physical address.
@Daniel's answer would help you know what addresses you want.
You can also try to use mem_map[i].address_space. It should contain some ownership information per physical page. I don't really know how to make sense of it.
Note that there may be overlap between processes. Libraries such as libc, which are loaded by multiple processes, may have a single copy in physical memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With