1

When I was reading a book(Linux kernel programming), I found an interesting/confusing paragraph about mm_segment_t addr_limit(one of the member in struct_task) as shown below:

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?

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.