Linux kernel: task vs thread

Linux kernel: task vs thread

책(Linux 커널 프로그래밍)을 읽을 때 아래와 같이 mm_segment_t addr_limit(의 구성원 중 하나 )에 대한 흥미롭고 혼란스러운 단락을 발견했습니다.struct_task

mm_segment_t addr_limit;
Unlike the older kernels, since 2.4 tasks (threads) also can be within the kernel. These can access a larger address space than tasks in user space. addr_limit describes the address space, which it is possible to access using the kernel of the task.

Questions:

  1. In the first point, it says "(tasks) threads also can be within the kernel" is there. What does it mean? Are threads not necessarily within the kernel?

  2. In the second sentence, "These can access a larger address space than tasks in user space." I don't understand what these means? If he is talking about threads, how can threads have larger address space than tasks?

답변1

The phrase "within the kernel" is likely referring to kernel threads which are used by the kernel itself for work that can be preformed asynchronously. You can see examples of these threads in your process tree:

# ps aux | grep '\[.*\]$' | head
root         2  0.0  0.0      0     0 ?        S    May05   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    May05   0:03 [ksoftirqd/0]
root         4  0.0  0.0      0     0 ?        S    May05   0:00 [kworker/0:0]
root         5  0.0  0.0      0     0 ?        S    May05   0:00 [kworker/u:0]
root         6  0.0  0.0      0     0 ?        S    May05   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    May05   0:00 [watchdog/0]
root         8  0.0  0.0      0     0 ?        S    May05   0:00 [migration/1]
root         9  0.0  0.0      0     0 ?        S    May05   0:00 [kworker/1:0]
root        10  0.0  0.0      0     0 ?        S    May05   0:02 [ksoftirqd/1]
root        11  0.0  0.0      0     0 ?        S    May05   0:00 [watchdog/1]

Such threads are created by kernel code that calls kthread_create(). These threads run in kernel mode, performing various tasks that you expect from the kernel.

"Tasks in user space" on the other hand, represent threads or processes as you would normally think of them, created via fork+exec or pthread_create. These run in user mode and make system calls when they require services from the kernel. The wording there is a bit odd because, of course, the kernel knows about these tasks and maintains information (such as struct_task's) about them so it can schedule time for them on the CPU.

As for (2), The "these" refers specifically to "Kernel threads." I believe that kernel threads share the same address space as the kernel.

관련 정보