Contents
Does every process have kernel stack?
Each process has a kernel stack (or more generally, each thread has its own stack) Just like there has to be a separate place for each process to hold its set of saved registers (in its process table entry), each process also needs its own kernel stack, to work as its execution stack when it is executing in the kernel.
What does the kernel stack do?
Processes execute user code on a user stack in the user portion of the process virtual address space. Each process has a second kernel stack in kernel space (the kernel portion of the address space). System calls run in kernel mode on the process kernel stack.
Why do we need a separate kernel stack for each process?
A separate kernel stack is needed for each process to save the state of the process. The state needs to be saved in case a task switch is performed, i.e. the current process is put to sleep, and some other process scheduled to run.
What is the kernel stack of a process?
The kernel stack is part of the kernel space. Hence, it is not directly accessible from a user process. Whenever a user process uses a syscall, the CPU mode switches to kernel mode. During the syscall, the kernel stack of the running process is used.
How many stacks does a process have?
@dexter Joachim is right: a process is just a container for threads, and threads have one stack.
How is switching to the kernel stack done?
Switching to the kernel interrupt stack is done by software based on a per CPU interrupt nest counter. This is needed because x86-64 “IST” hardware stacks cannot nest without races.
How are return addresses stored in the kernel?
We always scan the full kernel stack for return addresses stored on the kernel stack (s) 1, from stack top to stack bottom, and print out anything that ‘looks like’ a kernel text address. If it fits into the frame pointer chain, we print it without a question mark, knowing that it’s part of the real backtrace.
When to use IST to debug a kernel?
When debugging a kernel, debug interrupts (both hardware and software) can occur at any time. Using IST for these interrupts avoids making assumptions about the previous state of the kernel stack. To handle nested #DB correctly there exist two instances of DB stacks.
Is the memory in the Linux kernel swappable?
No, kernel memory is unswappable. Kernel pages are not swappable. But it can be freed. UserSpace Pages can reside in ZONE_NORMAL. Linux System Can be configured either to use HIGHMEM or not.