Convert vmalloc address to physical address
Hi all ,
vmalloc returns the virtual address. How to convert this virtual address to physical address. FYI : address returned by kmalloc can be converted to physical address using __pa(addr) macro. Regards, Prabagaran. |
Quote:
|
Hi,
I have a statement addr = vmalloc(size); Now addr is the virtual address. I need to know where it is located in the RAM(ie., physical address). How can i know the physical address of this addr?. |
Quote:
http://www.makelinux.net/ldd3/chp-8-sect-4 "When a driver needs a real physical address (such as a DMA address, used by peripheral hardware to drive the system's bus), you can't easily use vmalloc." |
Indeed ... please read that manual section carefully!
Now consider, "why is it so?" The answer, of course, is that this function allocates virtual memory. This is a chunk of memory as perceived by the user-land process. It will now exist in the process's address space and be accessible to that process at thus-and-so virtual address (since by definition every address perceived by a userland program is a virtual address). What does that mean to the kernel? As always, it means that the area is physically divided into pages ... and any of those pages may or may not at any point in time actually be resident in RAM. Actually, it might not yet exist, since physical pages (and swap space) are allocated only on-demand. (The area appears as zeroes until the process, or you, actually write to it.) Kernel code has the prerogative to use either virtual or physical addresses, and in the case of kernel threads they can even tolerate page faults. But you must very clearly understand at all times what is going on. "With great power comes great responsibility." |
All times are GMT -5. The time now is 06:18 AM. |