how to get physical memory address from virtual memory address - Linux

This is a discussion on how to get physical memory address from virtual memory address - Linux ; Hi , I am using Linux 2.4.20 Kernel. I am runing a application which will malloc and give a virtual memory address. I need to get the physical memory location of that. Can any one help me in this ? ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: how to get physical memory address from virtual memory address

  1. how to get physical memory address from virtual memory address

    Hi ,

    I am using Linux 2.4.20 Kernel. I am runing a application which will
    malloc and give a virtual memory address. I need to get the physical
    memory location of that. Can any one help me in this ?

    Thanks in advance,
    -Hari


  2. Re: how to get physical memory address from virtual memory address

    Hari wrote:
    > Hi ,
    >
    > I am using Linux 2.4.20 Kernel. I am runing a application which will
    > malloc and give a virtual memory address. I need to get the physical
    > memory location of that. Can any one help me in this ?


    You have to do this in the kernel.

    Firstly, the page obviously has to be nailed down (unswappable).
    Otherwise it has no fixed physical address. When paged out, it has no
    address at all, and may get a different physical address each time it
    is paged out.

    You can do this using the get_user_pages() kernel function, which will
    reduce a range of user space addresses into an array of ``struct page
    *'' pointers which are, in the same step, also nailed down, and
    refcounted up (so even if the process subsequently exits, those
    references remain valid, and are never swapped out). Once you are done
    with these pages, you eventually have to drop their references, and
    also give a hint to the VM system whether you made them dirty (i.e.
    changed the contents).

    Given a ``struct page *'', you can use the page_to_pfn() function to
    determine which page it is in the array of pages (pfn = physical frame
    number).

    The physical address is just that number times the page size.


+ Reply to Thread