Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is kernel said to be in process address space?

Tags:

This might be a silly question but it just popped up in my mind. All the text about process address space and virtual memory layout mentions that the process address space has space reserved for kernel. For e.g. on 32 bit systems the process address space is 4GB of which 1 GB is reserved for kernel in Linux (Might be different on other OS).

I am just wondering why kernel is said to be in the process address space when a process cannot address the kernel directly. Why don't we say that the kernel has a separate address space than a process and why can't we have a different page table for kernel itself which is separate from the page tables of the processes?

like image 785
vjain27 Avatar asked Sep 01 '11 19:09

vjain27


People also ask

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

The reason why kernel is mapped into userspace is mostly performance-related. Kernel can also set own different page table at any time to access physical memory it wants, but that would also trash all caches and degrade performance dramatically.

How kernel uses the address space?

The kernel address space is statically mapped into the address space. The top 1 GB of the user's space is reserved for system elements while the bottom 1 GB holds the user code, data, stack, and heap.

Does kernel have its own address space?

Because the address spaces are virtualized, many can exist. In fact, the kernel itself resides in one address space, and each process resides in its own address space.

Are kernel physical address space the same for all process?

The answer depends on whether kernel page-table isolation is enabled (which depends on the architecture and whether it supports KPTI). Without KPTI, the kernel is fully mapped in each process' address space, but as mentioned in the diagram, those mappings are inaccessible from user space (barring side-channel leaks).


1 Answers

When the process makes a system call, we don't need to switch the page tables (from process address space page table to kernel address space page table) for servicing the system call (which should be done only in kernel mode). This is said to be that the kernel is running in the process context.

Some kernel events which won't run in process context will load the page tables only for kernel.

Got it ?

like image 194
viji Avatar answered Oct 02 '22 07:10

viji