Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
Virtual address ranges a) might not exist in physical memory, and b) might not be contiguous, so what you are asking for is not possible in the general case.
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?.
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?.
I guess you either didn't read my reply or didn't believe me, so please see here: 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."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.