How is the threaduse kernel memory handle (mm_struct) of the last running process in Linux?

Some of the questions mentioned in Linux Kernel Development (Robert Love) about mm_struct and kernel thread:

"Kernel threads do not have a process address space and therefore do not have a memory descriptor associated with it. Thus, the kernel mm field is a thread descriptor for a thread NULL."

"Since kernel threads do not have user-space pages, they do not really deserve their own memory descriptor and page tables (page tables are discussed later in the chapter). Despite this, kernel threads need some data, such as page tables, even to access kernel memory. "

"Kernel threads have no address space, and mm is NULL. So when a kernel thread is scheduled, the kernel notices that mm is NULL and keeps the previous process address space loaded. The kernel then updates the active_mm in the process descriptor of the kernel thread to refer to the previous process memory handle. The kernel thread can then use the process's previous page tables as needed. "

Now my queries: 1. First it is mentioned that the kernel threads do not have any user page and therefore they do not deserve the descriptions of the memory descriptor and page tables and the next line says that it needs some data like page tables for kernel memory access. Which page table is being referenced here? Each process has its own page table to map to the virtual physical address, why does the core thread require that?

How do I use a page table using a kernel thread?

+3


source to share


2 answers


Each thread, regardless of whether its space requires space or kernel space for a page table. Kernel address space (virtual memory address space) maps directly to physical address space where user space address space is not directly mapped. In addition, user application space address space mappings change as new processes are created, terminated, replaced, while the kernel space mappings remain constant. To find out more, you can visit the following link: -

Process address space



Or post requests here.

+1


source


There are multiple usepaces and kernel threads on your system. Each virtual address space consists of a kernel and a user portion. The kernel is the same for all processes, the user part is different.

Each process has its own page table to map to virtual physical address, what does it require a kernel thread for?

Kernel threads need page tables to make the virtual to physical translation when accessing memory.



How do I use a page table using a kernel thread?

Imagine a simple case, a memory write such as [i] = 5; in kernel space. This usually goes through the MMU, which uses page tables to obtain a physical address according to the virtual address (in this case & a [i]). So there is nothing special about kernel threads, the difference is that when context switches they do not change the pgd (global page directory), they use the pgd of the last process, because all processes have the same part of the kernel and you can choose only the last one (see actime_mm) and you will be fine.

+1


source







All Articles