2

I'm working on a project about Linux kernel mm(memory management) and with a page, I need to find the process which the page belongs to.

However, I could not find any way without modifying the kernel. So, I'm really wondering whether it is possible to do that without modifying kernel.

In detail, when I have a VMA then, it is also possible to convert the VMA into the corresponding page, I want to know what process the VMA or page belongs to.

for example, in mm/page_io.c (of linux kernel source tree):

    int __swap_writepage(struct page *page, struct writeback_control *wbc,
        void (*end_write_func)(struct bio *, int))
{
        struct bio *bio;
        int ret, rw = WRITE;
        struct swap_info_struct *sis = page_swap_info(page);
...
        ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc);
        if (!ret) {
                count_vm_event(PSWPOUT);

                /* I should figure out what process is having the page above.
                 * But it is hard to know, because page is managed in LRU and
                 * it is not directly related to its process. What hints I have
                 * are page struct and some data structures which I could
                 * infer from the page only.
                 */
                // here!

In where I mark "here!", I should do that work what I said above. I'm waiting for your great answer. Thank you!

lokusking
  • 7,396
  • 13
  • 38
  • 57
nickeys
  • 137
  • 2
  • 10
  • The folks at [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) may be able to help. – jww Jan 29 '17 at 17:18
  • 1
    Can you provide some code, which shows a context where you want to achive requested functionality? In general, your question is clear, but context may give additional possibilities. – Tsyvarev Jan 29 '17 at 17:20
  • Something like `for PID in /proc/*; do grep xxx /proc/$PID/maps; done` ? – 0andriy Jan 29 '17 at 19:13
  • Tsyvarev // Oh, I'm sorry. I add a code snippet. – nickeys Jan 30 '17 at 06:21
  • jww // Thank you for your advise :-) – nickeys Jan 30 '17 at 06:37
  • A page may be mapped to more than one process. – n. m. could be an AI Jan 30 '17 at 06:53
  • n.m. // I know that, but I just want to know the way how to find the owner process(es) with the page struct, regardless of the number of owner for a page. – nickeys Jan 30 '17 at 07:46
  • 0andriy // Thanks for your reply, but the utilities what you mentioned does not use page struct in kernel. I need to figure out the owner process of a page with its page struct. – nickeys Jan 30 '17 at 07:52
  • @nickeys http://stackoverflow.com/questions/24639275/how-to-get-list-of-all-pages-that-belong-to-a-process-linux can help. – Parthiv Shah Feb 06 '17 at 11:57

0 Answers0