5

I want know where Linux stores page tables. Is it in kernel virtual memory?


It seems like this has to do with virtual memory system. but I'm new to it, so if I'm in the wrong direction please let me know. And in order to answer the question myself I read some lines from a book says:

(23.2 page 8)

... Linux virtual address space consists of user portion and kernel portion...

... the kernel portion is the same across processes.

So the address space provided by kernel is in a sense a space for processes to share something? So if the page tables are put in kernel virtual memory would this mean processes can share their page tables?


The book I read: http://www.ostep.org

8

Yes, the page tables are stored in the kernel address space. Each process has its own page table structure, which is set up so that the kernel portion of the address space is shared between processes. The kernel address space is not accessible from user space, however. The user space code communicates with the kernel in a controlled manner using system calls. After a successful system call the processor enters a privileged state in which the kernel address space is available.

| improve this answer | |
  • Can I say that: Each process has an address space, and its page table is stored in the kernel portion of this address space. And all kernel portion of each process are actually maps to the same address space in kernel, and sharing happens at there. Correct? – ptr_user7813604 Dec 10 '18 at 6:35
  • 2
    Yes, all processes share the kernel's address space, but only kernel code can access that part of memory. The kernel is free to do what it wants with it, but the memory is not shared between processes in the sense that user level code in one process could freely write to it and another read it. The kernel can set up memory pages to be shared between processes, but then non-kernel addresses are used, since kernel addresses are always off limit for non-kernel code. – Johan Myréen Dec 10 '18 at 6:46
  • Thanks for your kindness and time, now I understand it! Since my question is ask about Linux, but can I take this as a general understand for other OS? (Or it's not recommend?) – ptr_user7813604 Dec 10 '18 at 7:18
  • 1
    Note that with KPTI (Kernel Page Table Isolation), there are different page tables when a process runs in userspace vs when it runs in kernelspace. This has a performance cost, but for Intel CPUs with the Meltdown vulnerability avoids some trouble. – ninjalj Dec 29 '18 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.