tags:

views:

2833

answers:

4

Is the kernel stack for all process shared or there is a seperate kernel stack for each process? If it is seperate for each process where is this stack pointer stored? In task_struct ?

+4  A: 

This old article says that each process has its own kernel stack. See comments to why that seems to be a very good design.

I tried reading the current source to make sure, but since the kernel stack is "implicit", it's not visible in the task_struct. This is mentioned in the article.

This answer was edited to incorporate wisdom from comments. Thanks.

unwind
I seriously doubt that this can be changed. The kernel stack is a non-shared space where system calls can put their data. If you'd share them between processes, several kernel routines could use the same stack at the same time -> data corruption.
Aaron Digulla
I would think each process needs its own kernel stack, because several different process could be executing system calls simultaneously and you wouldn't want them to get mixed up.
David Zaslavsky
Each process has its own kernel stack and every kernel stack have its associated process. It have never been changed.That's why there are some pseudo-process like thing in "ps".
J-16 SDiZ
I would think that each task needs its own kernel stack, but the code to control it is probably hidden in the architecture-specific arch/ directory.
MarkR
+2  A: 

There is just one common kernel memory. In it each process has it's own task_struct + kernel stack (by default 8K).

In a context switch the old stack pointer is saved somewhere and the actual stack pointer is made to point to the top of the stack (or bottom depending on the hardware architecture) of the new process which is going to run.

robert.berger
where is this stack pointer stored ?
suresh
In a context switch the old stack pointer value is stored in the task_struct of the process which is being replaced with a new process and the stack pointer for the new process is read from the task_struct of this new process.
robert.berger
A: 

The book "Linux kernel Development" of Robert Love has a good explanation about process kernel stack.

And yes, each process has its own kernel stack and if I´m not wrong its pointer is stored on thread_info structure. But I´m not really sure about it, and the struct task_struct is stored on beginning or the end of process kernel stack, depending of CPU architecture.

Cheers. Carlos Maiolino

Carlos Maiolino
A: 

I think each process has its own kernel mode stack. Driver is executing in the kernel mode, the process sometimes will be blocked while executing driver routine. and the operating system can schedule another process to run. The scheduled process can call driver routine again. If kernel stack is shared, 2 processes are using the kernel stack, things will be mixed up. I'm puzzled by this question for a long time. At first I think kernel stack is shared, some books say that. After I read the Linux kernel Development, and see some driver code, I begin to think the kernel stack is not shared.

Jackie Wang