Based on my understanding from Understanding the Linux Kernel, is it correct that:
kernel threads and light weight processes in Linux kernel are both represented by
task_struct
structure in C.kernel threads always run in kernel space, while light weight processes can run in both user space and kernel space
kernel threads and light weight processes are two concepts at the same level. They do not depend on each other? In particular, a light weight process is not created and run based on a kernel thread?
Then why does the following quote from Operating System Concepts mean by saying that a light weight process is attached to a kernel thread? (Note that this book is for general OS concepts, and the quote doesn't say it is for Linux, but most parts of the book are applicable to Linux)
A final issue to be considered with multithreaded programs concerns communication between the kernel and the thread library, which may be required by the many-to-many and two-level models discussed in Section 4.3.3. Such coordination allows the number of kernel threads to be dynamically adjusted to help ensure the best performance.
Many systems implementing either the many-to-many or the two-level model place an intermediate data structure between the user and kernel threads. This data structure—typically known as a lightweight process, or LWP—is shown in Figure 4.13. To the user-thread library, the LWP appears to be a virtual processor on which the application can schedule a user thread to run. Each LWP is attached to a kernel thread, and it is kernel threads that the operating system schedules to run on physical processors. If a kernel thread blocks (such as while waiting for an I/O operation to complete), the LWP blocks as well. Up the chain, the user-level thread attached to the LWP also blocks.
where several concepts are defined in the book as following, in particular the definitions of kernel threads and user threads might be different from those that I mentioned in my questions at the beginning of this post:
support for threads may be provided either at the user level, for user threads, or by the kernel, for kernel threads. User threads are supported above the kernel and are managed without kernel support, whereas kernel threads are supported and managed directly by the operating system.
The many-to-one model (Figure 4.5) maps many user-level threads to one kernel thread. Thread management is done by the thread library in user space, so it is efficient
The many-to-many model (Figure 4.7) multiplexes many user-level threads to a smaller or equal number of kernel threads. The number of kernel threads may be specific to either a particular application or a particular machine (an application may be allocated more kernel threads on a multiprocessor than on a single processor).
Thanks.