LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-01-2009, 09:10 PM   #1
lqu
LQ Newbie
 
Registered: Aug 2009
Posts: 15

Rep: Reputation: 0
kernel page table


Hello,

I'm trying to understand the Linux virtual memory management. I know each process has its own page table. How about the kernel? Does the kernel have its own page table?

User space process page table is in mm_struct -> pgd, and pgd is passed to MMU when the process is scheduled to run. How about the kernel's page table. Where is it defined? When is it used?

Thanks,
lqu
 
Old 10-01-2009, 11:44 PM   #2
epilitimus
Member
 
Registered: Jul 2009
Distribution: Slackware
Posts: 35

Rep: Reputation: 17
As I understand it the kernel runs in the top of physical memory, not virtual memory, so it is essentially invisible to user space processes.

You can find a description of the memory management system at http://www.linuxhq.com/guides/TLK/mm/memory.html
 
Old 10-02-2009, 08:02 AM   #3
lqu
LQ Newbie
 
Registered: Aug 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Thank you for your reply, but what do you mean by "in the top of physical memory, not virtual memory"? After MMU is enabled, every address the CPU issues is virtual, and must be translated by the MMU. I guess the "top" you are talking about is related to the typical partition of address space. User (0x00000000 ~ 0xBFFFFFFF), kernel (0xC00000000 ~ 0xFFFFFFFF). But they are also virtual. Is it so?

So, when writing a device driver for UART, for example, if I want to access the UART control register (physically at 0x50000000, which is mapped to virtual 0xF5000000), I have to issue 0xF5000000, the virtual one, not the physical one.

My question was how (where, when) this 0x50000000 is mapped to 0xF5000000. Where is part of page table for memory above 0xC0000000?

Thanks,
lqu

Quote:
Originally Posted by epilitimus View Post
As I understand it the kernel runs in the top of physical memory, not virtual memory, so it is essentially invisible to user space processes.

You can find a description of the memory management system at http://www.linuxhq.com/guides/TLK/mm/memory.html

Last edited by lqu; 10-02-2009 at 08:08 AM.
 
Old 10-02-2009, 09:00 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by epilitimus View Post
You can find a description of the memory management system at http://www.linuxhq.com/guides/TLK/mm/memory.html
There is a very misleading statement there:

Quote:
Most multi-purpose processors support the notion of a physical address mode as well as a virtual address mode. Physical addressing mode requires no page tables and the processor does not attempt to perform any address translations in this mode. The Linux kernel is linked to run in physical address space.
X86 and most other processors do not support any effective method of mixing physical address mode with virtual address mode as would be required for the kernel to use one while user code uses the other.

If I understand correctly, the statement "The Linux kernel is linked to run in physical address space." is technically true to the extent that it means anything (if you read a lot into the subtle difference between "linked to run in" and "runs in"). In x86, the physical-like address space is achieved by a big sequential mapping into contiguous virtual address space.

Quote:
How about the kernel's page table. Where is it defined?
Sorry, I only know the concepts, not that level of detail. I assume you also know the same concepts.

Don't you hate it when someone who knows less about the subject than you do takes away your thread's zero reply status with a useless answer to a hard question. Since zero reply status gets so much attention around here, there ought to be a way for those of us who sometimes ask hard questions to re flag the thread as having zero useful replies.

Last edited by johnsfine; 10-02-2009 at 09:04 AM.
 
Old 10-02-2009, 11:04 PM   #5
lqu
LQ Newbie
 
Registered: Aug 2009
Posts: 15

Original Poster
Rep: Reputation: 0
I think I have found the answer in the book "Understand the linux kernel", chapter 2.

The kernel page table is in swapper_pg_dir. In the mm_struct for the idle process (process 0), "pgd" points to this swapper_pg_dir. Every process has a (same) copy of this master page table for the entries between 0xC0000000 and 0xFFFFFFFF.

Please correct me if I am wrong.
lqu
 
Old 10-02-2009, 11:55 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
Robert Love knows his stuff (stupid statement, I know), but I'd recommend a read of this.
Has very good chapters on (all) the mm plumbing.
 
  


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
access paging table memory using another page table via MMU? valpa Linux - Kernel 8 08-26-2008 03:26 PM
Page table walk manually WebBeing Programming 0 08-05-2008 06:50 PM
Does each process get its own page table pages? rtaheri Linux - General 1 07-10-2008 07:27 PM
three- level page table in linux 2.6 mehrotraamit-2 Linux - Newbie 1 11-15-2005 10:19 AM
html page layouts with a table acid_kewpie Programming 5 06-20-2003 05:24 AM

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

All times are GMT -5. The time now is 10:54 AM.

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
Open Source Consulting | Domain Registration