LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 06-03-2014, 04:16 AM   #1
clp510
LQ Newbie
 
Registered: Aug 2012
Posts: 9

Rep: Reputation: Disabled
linux kernel is running in physical address or virtual address?


linux kernel is running in physical address or virtual address?
 
Old 06-03-2014, 07:44 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
The Linux kernel is using virtual addressing... It has the ability to page out various structures to preserve memory space. Now for a good part it, physical addressing is also used (specifically, for I/O).

The major use is to allow the kernel to be relocated to where ever it needs to go when the physical memory is expanded (new RAM added, and rebooted, changes to the reserved memory, or memory is removed from the system..).

One of the uses for virtual addressing by the kernel is that it allows the kexec system call to replace the existing kernel - by replacing the virtual mapping of the running kernel with that for the new kernel.... and no reboot required.
 
1 members found this post helpful.
Old 06-03-2014, 04:15 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 17,199

Rep: Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563
Kind of one of those questions that may have a hundred answers.

The way I read the question would be that the kernel is loaded into a real physical address. It later then may associate that address by other means.

On a similar post some answers are given too. http://stackoverflow.com/questions/8...ogical-address
 
Old 06-03-2014, 06:00 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
It does get loaded into real physical address (this happens to be due to the I/O used by the BIOS/EFI + boot loader)... but it doesn't/can't run that way (the kernel isn't position independant). The first thing done is to initialize the mapping tables for the kernel. This is how it knows how much memory it can use for the running system, and knows where the starting location for the initrd is.

Every system I have used (from the PDP-11 on) did this. The boot loader uses physical addresses, but the kernel does not. (on the PDP-11, the boot loader offset the physical address by 512 so that the boot loader itself is not part of the kernel - this is because the first 512 bytes of kernel memory is the interrupt vector table - causing corruption due to the vector table not having the proper values).

Last edited by jpollard; 06-03-2014 at 06:03 PM.
 
1 members found this post helpful.
Old 06-03-2014, 06:51 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,001

Rep: Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219
Most people have a hard enough time understanding the difference between virtual and real addressing modes - don't bring absolute into it.

For almost all of humanity, the kernel may be considered to run "real".
 
Old 06-03-2014, 09:09 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 17,199

Rep: Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563Reputation: 2563
Not disagreeing with you jpollard. The way I read the question was is it running in one or the other. Pretty sure the question has many answers depending on the non-exact nature of the question. Then we get into time frame of real mode and protected mode issues depending on version of linux.

I used to have a PDP-11 here. We bought an Alpha running NT with a one of a kind emulator to maintain the software.

Last edited by jefro; 06-03-2014 at 09:15 PM.
 
Old 06-03-2014, 10:19 PM   #7
clp510
LQ Newbie
 
Registered: Aug 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thank you for all your replies,maybe my question is a little confused. Ordinary processes are running in virtual address,that's sure. But as far as I know,linux kernel are some processes that managing these ordinary processes,allocating memory address to a process and managing mapping table for every process. Do these managers run in virtual address or physical address?
 
Old 06-04-2014, 07:47 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
I believe the entire kernel is running under virtual memory - ie, the MMU is used to map kernel memory. The page tables handle the translation between a physical address and the virtual, but only when they are active in the MMU.

The kernel itself uses the page tables when computing the physical location of buffers for I/O (though if an IOMMU is available, I think it does the work).

The kernel also uses virtual mapping to load modules (the memory pages used has to be allocated before the module can be loaded).
 
Old 06-04-2014, 07:53 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
Quote:
Originally Posted by jefro View Post
Not disagreeing with you jpollard. The way I read the question was is it running in one or the other. Pretty sure the question has many answers depending on the non-exact nature of the question. Then we get into time frame of real mode and protected mode issues depending on version of linux.
Yes... but "real" mode is with the MMU disabled, thus all addresses are physical. Once the MMU is enabled, all addresses are virtual - and translated by the MMU.

Quote:
I used to have a PDP-11 here. We bought an Alpha running NT with a one of a kind emulator to maintain the software.
- there are a number of emulators available now... most used in schools for teaching purposes. I still think it is the best CISC CPU, and believe the VAX overextended the concepts.
 
  


Reply


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
linux kernel is running in physical address or virtual address? clp510 Linux - Newbie 3 06-03-2014 07:59 AM
When IOMMU is enabled, how to get the Kernel Virtual Address from a Physical address leechaotang Linux - Kernel 1 11-10-2011 01:21 AM
Converting virtual address to physical address in the kernel DBQ Programming 0 02-07-2010 07:30 PM
how to translate virtual address to physical address in linux application saurin Programming 1 11-18-2009 10:05 PM
how to find physical address of kernel virtual address kushneeraj Programming 0 10-20-2006 08:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration