Linux 2.6 内核中需要 thread_info 结构吗?
在 Linux 2.6 内核之前,struct task_struct 位于每个进程的内核堆栈的末尾。没有 thread_info struct
概念。但在 Linux 2.6 内核中,task_struct
不再被放置在进程的内核堆栈的末尾,而是 thread_info struct
被放置在末尾。这个 thread_info 结构包含一个指向 task_struct
结构的指针。
需要引入 thread_info
结构吗?如果 task_struct
位于进程内核堆栈的末尾,我们可以直接使用堆栈指针
访问task_struct
结构。
在2.6内核中,task_struct
是使用slab_allocator
动态分配的。在 2.6 内核之前,它是静态分配的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FrankH,他正在寻找(我怀疑是出于纯粹的兴趣)这种变化的原因。这是我用我的 l33t 谷歌技能发现的。链接后面有更多信息:
(c) http:// www.spinics.net/lists/newbies/msg22263.html
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:
(c) http://www.spinics.net/lists/newbies/msg22263.html
我们需要thread_info的原因是我们使用Slab Allocator为task_struct分配内存。现在你可能会问这之间有什么关系?
要了解这一点,您需要了解 Slab Allocator 的工作原理。
如果没有 Slab Allocator ,内核开发人员可以为特定进程的内核堆栈中的 task_struct 分配内存,以便可以轻松访问它。现在随着 Slab Allocator 的出现,内存被分配给由 Slab Allocator 确定的 task_struct 。因此,使用 Slab 分配器,您可以将 task_struct 存储在其他位置,而不是存储在特定进程的内核堆栈中。现在内核开发人员引入了thread_info,并在其中放置了一个指向task_struct所在位置的指针。这就是为什么我们必须接受 thread_info。
您可以在 Robert Love 的《Linux 内核开发》一书中阅读有关 Slab Allocator 的内容。
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.
您好,在 Linux 内核开发第三版的第 25 页上写有以下语句,这可能有助于您理解
“新结构还使得计算其值的偏移量以在汇编代码中使用变得相当容易”
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"