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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.