Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


❑ preempt_countis a counter needed to implement kernel preemption, discussed in Section 2.8.3.
❑ addr_limitspecifies up to which address in virtual address space a process may use. As already
noted, there is a limit for normal processes, but kernel threads may access the entire virtual
address space, including the kernel-only portions. (This doesnotrepresent any kind of restric-
tion on how much RAM a process may allocate.) Recall that I have touched on the separation
between user and kernel address space in the Introduction, and will come back to the details in
Section 4.
❑ restart_blockis needed to implement the signal mechanism (see Chapter 5).

Figure 2-9 shows the relationship betweentask_struct,thread_infoand the kernel stack. When a
particular component of the kernel uses too much stack space, the kernel stack will crash into the thread
information, and this will most likely lead to severe failures. Besides, this can also lead to wrong informa-
tion when an emergency stack trace is printed, so the kernel provides the functionkstack_endto decide
if a given address is within the valid portion of the stack or not.


Kernel stack

thread_info

task_struct

thread_info->task
task_struct->stack

INIT_THREAD_SIZE

Figure 2-9: Relationship betweentask_struct,thread_info,andthe
kernel stack of a process.

dup_task_structcopies the contents oftask_structandthread_infoinstances of the parent process,
but thestackpointer is set to the newthread_infoinstance. This means that the task structures of
parent and child processes are absolutely identical at this point except for the stack pointer. The child
will, however, be modified in the course ofcopy_process.


There are also two symbols namedcurrentandcurrent_thread_infothat are defined as macros or
functions by all architectures. Their meanings are as follows:


❑ current_thread_infodelivers a pointer to thethread_infoinstance of the process currently
executing. The address can be determined from the kernel stack pointer because the instance is
always located at the top of the stack.^11 Because a separate kernel stack is used for each process,
the process to stack assignment is unique.
❑ currentspecifies the address of thetask_structinstance of the current process. This function
appears very frequently in the sources. The address can be determined usingget_thread_info:
current = current_thread_info()->task.

(^11) The pointer to the kernel stack is usually held in a specially reserved register. Some architectures, especially IA-32 and AMD64,
use a different solution discussed in Section A.10.3.

Free download pdf