Prior to the Linux 2.6 kernel, struct task_struct
was present at the end of the kernel stack of each process. There was no thread_info struct
concept. But开发者_高级运维 in Linux 2.6 kernel, instead of task_struct
being placed at the end of the kernel stack for the process, the thread_info struct
is placed at the end. This thread_info struct contains a pointer to the task_struct
structure.
What was the need for thread_info
structure to be introduced ?. We could have accessed the task_struct
structure using the stack pointer
directly if task_struct
was placed at the end of the kernel stack of the process.
In 2.6 Kernel, task_struct
is dynamically allocated using slab_allocator
. Prior to 2.6 Kernel, was it statically allocated?
FrankH, he is looking (out of pure interest as I am, I suspect) for a reason for this change. This if what I've found with my l33t google skills. A bit more info behind the link:
"task_struct is huge. it's around 1,7KB on a 32 bit machine. on the other hand, you can easily see that thread_info is much slimmer.
kernel stack is either 4 or 8KB, and either way a 1.7KB is pretty much, so storing a slimmer struct, that points to task_struct, immediately saves a lot of stack space and is a scalable solution."
(c) http://www.spinics.net/lists/newbies/msg22263.html
The reason why we need the thread_info is due to the fact that we are allocating the memory for task_struct using the Slab Allocator. Now you may ask what is the relation between these?
To understand that you need to understand how Slab Allocator works.
Without the Slab Allocator , the kernel developers could allocate memory for task_struct in the kernel stack for the particular process so that it can be accessed easily. Now with the advent of Slab Allocator , the memory is allocated to the task_struct as determined by the Slab Allocator. So with the Slab Allocator you have task_struct stored somewhere else and not in the kernel stack of the particular process. Now the Kernel developers introduced thread_info and placed a pointer in it to the place where the task_struct resides. And that is why we have to live with thread_info.
You can read about Slab Allocator in Robert Love's book Linux Kernel Development.
hi on page 25 of linux kernel development 3rd edition following statement is written, this may help you understand
"The new structure also makes it rather easy to calculate offsets of its values for use in assembly code"
精彩评论