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.
thread_infois architecture dependent.
thread_infocuts into the size of the kernel stack for that process, so it should be kept small.
thread_infois 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.