7

Considering Linux and 32 bit x86 arch there is 3:1 divide of the accessible 4GB address space. The user space is allocated 0-3 Gb while 3-4 Gb is allocated to kernel. How does a virtual address that is greater than 3Gb and hence lies into the kernel address space is transformed to the physical address? Does page tables would come into picture?

user593575
  • 71
  • 1
  • 3

1 Answers1

5

There is some information in Mel Gorman's book Understanding the Linux Virtual Memory Manager.

The short answer: Yes, the kernel sets up page tables to translate physical address 0 to virtual address 3 GiB. (Section 3.7.1). This includes the physical location the kernel was loaded to (usually 1MB on x86).

Eric Seppanen
  • 5,923
  • 30
  • 24
  • Thanks for the answer. After doing some googling I found that there is a #define PAGE_OFFSET which is 3GB ( configurable ) and the kernel virtual address has one to one mapping to physical address obtained by simply subtracting PAGE_OFFSET from kernel virtual address and hence no use of page tables. please correct me if I am wrong. – user593575 Jan 31 '11 at 05:33
  • 1
    That simple mapping makes the implementation of virt_to_phys() easy: as you said, just subtract PAGE_OFFSET. But paging is enabled-- this allows the translation of virtual addresses to physical in hardware, as instructions are fetched and data is accessed. – Eric Seppanen Jan 31 '11 at 16:08
  • I got your point. Page tables are always used when paging is enabled regardless the virtual address belongs to kernel or user space. (Alas!!! I cant vote up as it requires minimum of 15 points) – user593575 Feb 04 '11 at 14:25
  • My 0.2: one might wonder- if we use paging in the kernel won't it slow things down? Yes but this is mitigated in a modern OS like Linux by: (a) pinning down kernel mapping TLB entries, (b) modern processors have large-ish TLBs, and (c) using large/huge pages for the kernel mappings (Transparent Huge Pages?). – kaiwan Mar 19 '15 at 03:23