GoldenSugar GoldenSugar - 5 months ago 21x
Linux Question

Linux Kernel: Threading vs Process - task_struct vs thread_info

I read that Linux does not support the concept of threads or light-weight processes and that it considers kernel threads just like any other process. However this principle is not very accurately reflected inside the code. We see task_struct that holds state information of a process (correct me if wrong) and also thread_info appended to the bottom of a process' kernel stack.

Now the question is why does the code support the concept of individual threading through thread_info when linux is supposed to interpret threads like any other process?

Please let me know what I am missing here - I am a newbie to linux kernel dev.


Threads in Linux are treated as processes that just happen to share some resources. Each thread has its own thread_info (at the bottom of the stack like you said) and its own task_struct. I can think of two reasons why they are maintained as separate structures.

  1. thread_info is architecture dependent. task_struct is generic.
  2. thread_info cuts into the size of the kernel stack for that process, so it should be kept small. thread_info is placed at the bottom of the stack as a micro-optimization that makes it possible to compute its address from the current stack pointer by rounding down by the stack size saving a CPU register.