Different processes have different different page tables for their address spaces.

Does the Linux kernel have its own page table? If not, how are the virtual addresses of kernel translated to physical memory addresses?

In the sense that the address space of each process is divided into user space and kernel space, does the page table of each process contain the "page table" of the kernel?


Related Do page fault, page replacement, and paging happen to the kernel or just to processes, and to the kernel space or the user space?


You are correct. The VM of a process consists of the user address space and kernel address space. The kernel address space is the same across all processes but protected from access. If you've heard the 2/2 or 3/1 memory split (from x32), it was the user/kernel amount of memory in GBs. So for a 4GB address space you could (e.g.) have 3G for processes and 1G for the kernel.

I would recommend reading the "Understanding the Linux Kernel" book which will answer this and many other of your questions.

  • Here is the focus of my questions: Does the Linux kernel have its own page table? does the page table of each process contain the "page table" of the kernel, i.e. is the "page table" of the kernel redundantly repeated in the page table of every process?
    – Tim
    Oct 15 '18 at 23:02
  • @Tim AFAIK, it's one per process and includes the kernel part
    – V13
    Oct 15 '18 at 23:31
  • Do you mean repetition? Isn't that redundant and waste space?
    – Tim
    Oct 16 '18 at 0:05

"Page tables" are actually a type of tree structure. E.g. see "Four-level page tables" [LWN.net, 2004].

The top level is a single page (4096 bytes). The entries which map the kernel range, are set to the same values in all processes, and hence are shared. Kernel temporary mappings happen at a lower level of the tree, so they only need to modify inside the shared kernel page tables, and they do not need to modify each process page table separately.

At least, that's my high-level overview. I don't have all the words.

The above is cross-posted from my answer here: https://unix.stackexchange.com/a/513184/29483


This is an interesting question that I was also curious about. I'll try to answer the question on following condition:

  • kernel version 5.10.7
  • arch x86
  • CONFIG_PGTABLE_LEVELS is 2 (using two level page tables)
  • kernel address space is 1G

For each process, the first level page table is called "page global directory", or pgd. Entry index #768 to index #1023 in pgd is used to map kernel address. Each process has its own unique 4K-byte page that is used for pgd. And yes, to your question, entries from #768 to #1023 in pgd are the same and are duplicated by each process. But this is only a very small part. The second level page table for kernel are still shared across all processes.

Please refer to arch/x86/mm/pgtable.c, function pgd_ctor(), to understand how the duplicate part of the first level page table(pgd) is created.

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.