Linux 2.6 内核中需要 thread_info 结构吗?

发布于 2024-11-10 02:41:46 字数 486 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吻风 2024-11-17 02:41:46

FrankH,他正在寻找(我怀疑是出于纯粹的兴趣)这种变化的原因。这是我用我的 l33t 谷歌技能发现的。链接后面有更多信息:

“task_struct 很大。在 32 位机器上大约为 1.7KB。在
另一方面,你可以很容易地看到 thread_info 更精简。

内核堆栈要么是 4KB,要么是 8KB,无论哪种方式,1.7KB 都不错
太多了,所以存储一个更精简的结构,指向task_struct,
立即节省大量堆栈空间,并且是一个可扩展的解决方案。”

(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:

"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

蹲墙角沉默 2024-11-17 02:41:46

我们需要thread_info的原因是我们使用Slab Allocatortask_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.

腻橙味 2024-11-17 02:41:46

您好,在 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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文