kernel stack for linux process

后端 未结 4 904
自闭症患者
自闭症患者 2021-01-31 18:35

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_s

相关标签:
4条回答
  • 2021-01-31 19:12

    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.

    0 讨论(0)
  • 2021-01-31 19:23

    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.

    0 讨论(0)
  • 2021-01-31 19:27

    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

    0 讨论(0)
  • 2021-01-31 19:31

    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.

    0 讨论(0)
提交回复
热议问题