Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is kernel mapping in linux?

Tags:

linux

kernel

what is kernel mapping? What are permanent mapping and temporary mapping. What is a window in this context? I went through code and explanation of this but could not understand this

like image 730
user1434287 Avatar asked Sep 19 '25 07:09

user1434287


1 Answers

I'm assuming you're talking about memory mapping in linux kernel.

Memory mapping is a process of mapping kernel address space directly to users process's address space.

Types of addresses : enter image description here

  • User virtual address : These are the regular addresses seen by user-space programs

  • Physical addresses : The addresses used between the processor and the system’s memory.

  • Bus addresses : The addresses used between peripheral buses and memory. Often, they are the same as the physical addresses used by the processor, but that is not necessarily the case.
  • Kernel logical addresses : These make up the normal address space of the kernel.
  • Kernel virtual addresses : Kernel virtual addresses are similar to logical addresses in that they are a mapping from a kernel-space address to a physical address.

High and Low Memory :

  • Low memory : Memory for which logical addresses exist in kernel space. On almost every system you will likely encounter, all memory is low memory.
  • High memory : Memory for which logical addresses do not exist, because it is beyond the address range set aside for kernel virtual addresses.This means the kernel needs to start using temporary mappings of the pieces of physical memory that it wants to access.

Kernel splits virtual address into two part user address space and kernel address space. The kernel’s code and data structures must fit into that space, but the biggest consumer of kernel address space is virtual mappings for physical memory. Thus kernel needs its own virtual address for any memory it must touch directly. So, the maximum amount of physical memory that could be handled by the kernel was the amount that could be mapped into the kernel’s portion of the virtual address space, minus the space used by kernel code.

enter image description here

Temporary mapping : When a mapping must be created but the current context cannot sleep, the kernel provides temporary mappings (also called atomic mappings). The kernel can atomically map a high memory page into one of the reserved mappings (which can hold temporary mappings). Consequently, a temporary mapping can be used in places that cannot sleep, such as interrupt handlers, because obtaining the mapping never blocks.

Ref :

  • kernel.org/doc/Documentation/vm/highmem.txt
  • static.lwn.net/images/pdf/LDD3/ch15.pdf
  • man mmap
  • notes.shichao.io/lkd/ch12/
like image 179
finn Avatar answered Sep 21 '25 00:09

finn