2010年1月20日 星期三

linux kernel stack size

Advantages of a Fixed-Stack size in kernel
narendrakiranon
March 27, 2006 - 9:29am
1) The fixed stack size (of 8KB) is used since almost all the processes (in kernel space) never need more than 8KB of stack space on x86 (unlike user space process stacks which run into MB). This value was arrived-at after several experiments and tests.

2) The task_struct (aka Process Control Block) of each process is stored on the other end of the stack. (task_struct size is around 1.5 to 2KB).

Kernel space stack of a process

--------------------- 8KB (Stack Start)
| stack pointer |
|
|
|
|
|
|
|--------------------|
| task_struct |
--------------------- 0KB

This mechanism would make it easier to get the task_struct address of the current process i.e by simply ANDing the ESP (stack pointer) register with 0xFFFFF000. This eliminates the necessity to maintain the task_struct address in a seperate variable/place. Also since the task_struct address of a process has to be accessed several times, this mechanism improves performance.

3) Dynamic stacks are useful when the upper limit of the stack size is huge/unknown (mostly for user space stacks). Dynamic stacks are slower when compared to fixed-size stacks.
Also, the task_struct address has to be maintained seperately in this case which further drops the performance.

Due to the above reasons, Linux Kernel stacks are restricted to 8KB on x86.

Regards,
Narendra Kiran Chinnam.

沒有留言:

張貼留言