LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   kernel page table (https://www.linuxquestions.org/questions/linux-kernel-70/kernel-page-table-759115/)

lqu 10-01-2009 09:10 PM

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

epilitimus 10-01-2009 11:44 PM

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

lqu 10-02-2009 08:02 AM

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 (Post 3704577)
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


johnsfine 10-02-2009 09:00 AM

Quote:

Originally Posted by epilitimus (Post 3704577)
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.

lqu 10-02-2009 11:04 PM

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

syg00 10-02-2009 11:55 PM

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.


All times are GMT -5. The time now is 04:07 PM.