简体   繁体   中英

How is kernel virtual memory mapped to physical memory

How do I find out the memory mappings for kernel space? VA -> PA

I'm aware of the proc file system /proc/pid/maps & /proc/pid/mappings which gives us the mappings of user space applications. Anything similar to find kernel space mappings?

Thanks!

Here's a partial answer, maybe it will help.

Linux divides the kernel virtual address space to two parts - lowmem and vmalloc.

Lowmem uses a 1-1 mapping between virtual and physical addresses. Ie virtual address X is mapped to physical address XC (where C is some constant, eg 3GB). This mapping is built during boot, and is never changed.

Vmalloc uses a dynamic mapping, on demand. On each allocation, a bunch of physical pages are found, and a virtual address range, and the paging tables are modified to create the mapping.

Two two are separated by virtual addresses. Different virtual address ranges are used by each. The lowmem range is always mapped, the vmalloc range is mapped when allocated.

Actually, kernelspace devided into LOW and HIGH memory (vmalloc area is a part of high memory). As ugoren said lowmem is direct mapping, built at the time of booting. High memory could be used, for example, to map some userspace pages using kmap (pkmap area). Here is more detailed picture, which you can find in kernel logs at the boot time. Example:

fixmap  : 0xffc57000 - 0xfffff000   (3744 kB)
pkmap   : 0xff800000 - 0xffa00000   (2048 kB)
vmalloc : 0xf7ffe000 - 0xff7fe000   ( 120 MB)
lowmem  : 0xc0000000 - 0xf77fe000   ( 887 MB)
.init : 0xc0906000 - 0xc0973000   ( 436 kB)
.data : 0xc071ae6a - 0xc08feb78   (1935 kB)
.text : 0xc0400000 - 0xc071ae6a   (3179 kB)

In this example 1Gb kernel space devided into 887 low mem against 120 high mem. As you can see 120 MBs of high memory occupied by vmalloc area, and only 2 and 3 Kbs reserved for pkmap and fixmap areas. About fixmaps you can read here http://embeddedma.blogspot.ru/2013/06/linux-fixmap-role.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM