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?
kernel virtual address translation
Asked Answered
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).
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. –
Extracurricular
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. –
Fca
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) –
Extracurricular
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?). –
Clinkstone
© 2022 - 2024 — McMap. All rights reserved.