Linux 内核线程没有地址空间
为什么Linux内核线程没有地址空间。对于任何要执行的任务,它都应该有一个内存区域,对吗?内核线程的文本和数据去了哪里?
Why the Linux kernel threads do not have an address space. For any task to execute, it should have a memory region right? Where do the text and data of kernel threads go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
内核线程确实有一个地址空间。只是他们都有同一个。这并不妨碍它们各自拥有不同的堆栈。
文本和数据放置在内核地址空间(由所有线程共享的地址空间)中,具体取决于分配方式和时间以及用途。
Linux MM 站点有很多有关 Linux 这方面的文档。往那边走去。
Kernel threads do have an address space. It's just that they all share the same one. This does not prevent them from each having a different stack.
Text and data are laid out in the kernel address space (the one that is shared by all the threads), depending on how and when it was allocated, and what it's used for.
The Linux MM site has a lot of documentation about this aspect of Linux. Head over there.
我不知道确切的答案,因为我不是 Linux 架构师。
但一般来说,所谓的内核线程确实有一个地址空间:它是包含内核的地址空间。它可能不需要为每个内核线程显式表示,因为它在许多线程之间共享。
我希望任何真正的线程实现都有一个包含寄存器值(和堆栈指针等)的机器上下文块,以及一个指向线程应该运行的地址空间的指针。然后,启动就绪线程的调度程序可以轻松确定内存管理单元是否设置为允许访问地址空间(如果没有,则进行设置)以使线程能够在其所需的空间中运行。
I don't know the precise answer, because I'm not a Linux architect.
But in general, so-called kernel threads do have an address space: it is the address space which contains the kernel. It might not need to be explicitly represented for each kernel thread, since it is shared among many threads.
I'd expect any real thread implementation to have a machine context block containing register values (and stack pointer, etc.), and a pointer to a the address space in which the thread is supposed to run. Then a scheduler, starting a ready thread, can easily determine whether the memory management unit is set up to enable access to the address space (and if not, set it up) to enable the thread to run in its desired space.