LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 10-16-2011, 01:23 PM   #1
prabagaranvt
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Rep: Reputation: 0
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.
 
Old 10-18-2011, 04:00 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 1,384

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Quote:
Originally Posted by prabagaranvt View Post
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.
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.
 
Old 10-19-2011, 08:31 AM   #3
prabagaranvt
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Original Poster
Rep: Reputation: 0
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?.
 
Old 10-19-2011, 01:17 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 1,384

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
Quote:
Originally Posted by prabagaranvt View Post
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?.
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."
 
Old 10-21-2011, 08:24 AM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,263

Rep: Reputation: 1085Reputation: 1085Reputation: 1085Reputation: 1085Reputation: 1085Reputation: 1085Reputation: 1085Reputation: 1085
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."
 
  


Reply

Tags
kernel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert guest logical address to host physical address hmd429 Linux - Virtualization and Cloud 1 10-07-2011 03:44 AM
Convert guest logical address to host physical address hmd429 Linux - Kernel 0 10-07-2011 02:35 AM
Converting virtual address to physical address in the kernel DBQ Programming 0 02-07-2010 06:30 PM
how to translate virtual address to physical address in linux application saurin Programming 1 11-18-2009 09:05 PM


All times are GMT -5. The time now is 08:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration