Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 332
kimi Avatar asked Dec 09 '13 20:12

kimi


People also ask

How is virtual memory mapped to physical memory?

To map virtual memory addresses to physical memory addresses, page tables are used. A page table consists of numerous page table entries (PTE). One memory page in a PTE contains data structures consisting of different sizes of 'words'.

Can kernel access physical memory?

The physical memory can only be directly accessed in kernel-mode debugging.

Where is the kernel in physical memory?

In physical memory the kernel usually resides at a random offset above 0x1000000 .

Why is kernel mapped to the same address space as processes?

Another important reason why we say kernel is in the process address space is that kernel can access the user code/data of the CURRENT process, i.e. the virtual address space 0~3G.


1 Answers

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. I.e. virtual address X is mapped to physical address X-C (where C is some constant, e.g. 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.

like image 191
ugoren Avatar answered Nov 02 '22 06:11

ugoren