No address space for Linux Kernel threads

后端 未结 2 736
既然无缘
既然无缘 2021-02-04 19:48

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?

相关标签:
2条回答
  • 2021-02-04 20:04

    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.

    0 讨论(0)
  • 2021-02-04 20:06

    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.

    0 讨论(0)
提交回复
热议问题