2

As I understand the lower part of the kernel memory is 1:1 mapped with physical address (RAM), I wonder what benefit it brings in, especially in context of x86. When MMU/TLB is enabled, every address sent over CPU address bus is treated as a virtual/logical address. Even if the the linear-to-physical translation can be done by subtracting an offset, but the MMU will still walk the page table to translate the linear address. I can't see any performance benefit apparently. What do I miss?

sherlock
  • 2,397
  • 3
  • 27
  • 44
  • Does this answer your question? [What is the rationality of Linux kernel's mapping as much RAM as possible in direct-mapping(linear mapping) area?](https://stackoverflow.com/questions/27370435/what-is-the-rationality-of-linux-kernels-mapping-as-much-ram-as-possible-in-dir) – Peter Cordes Oct 29 '22 at 21:54

1 Answers1

1

There is no benefit. Protect Mode provides paging mechanism, so each process can be isolated completely and be protected. When paging is enabled, all address used in code (kernel or user program) must be virtual address and it's impossible to use physical address directly. Kernel just needs a simple method to access every byte in RAM. Under paging mechanism, the simplest mapping schema is 1:1 mapping. Although kernel still can't skip the page mapping process, this schema is very simple to implement. Any other complex mapping schema won't have obvious benefits.

haolee
  • 892
  • 9
  • 19
  • So why offset is needed in linear mapping? It would be simpler to use exact 1:1 mapping without offset – Dzmitry Sankouski Mar 14 '21 at 11:13
  • @DzmitrySankouski this may be a historical problem... – haolee Apr 13 '21 at 01:26
  • @DzmitrySankouski I can think of two reasons based on what I've read thus far. 1) For security, `kaslr` (address space randomization) means the kernel will always be in a new location every boot, making it harder to hack. 2) Kernel address space placed in low memory (with no offset) will limit the address space available of 16 or 32 bit legacy programs which start at virtual address 0. See [here](https://stackoverflow.com/a/8698578/13020139). – wxz Jun 25 '21 at 22:49