Information Technology Reference
In-Depth Information
Figure 1. Kernel Memory Stack and the Process Descriptor
process descriptor
virtual address space if the CPU triggers a page
fault exception.
In order to manage its processes, Linux has for
each process a process descriptor containing the
information related to this process (Gorman,
2004). Linux stores the process descriptors in a
circular doubly linked list called the task list. The
process descriptor's pointer is a part of a structure
named “thread_info” that is stored under the bot-
tom of the kernel mode stack of each process as
shown in Figure 1.
This feature allows referencing the process
descriptor using the stack pointer without any
memory referencing. The reason for this method
of implementation is improved performance. The
stack pointer address is frequently used; hence, it
is stored in a special purpose register. In order to
get a reference for the current process descriptor
faster, the stack pointer is used. This is done by
a macro called “current”.
In order to benefit the performance and leave
the “current” mechanism untouched, a new alloca-
tion interface is introduced which allocates one
physical page and a contiguous virtual address
space that is aligned to the new stack size.
The new virtual area of the stack size can be
of any size. The thread_info structure is set to
the top of the highest virtual address minus the
thread_info structure size. The stack pointer starts
from beneath the thread_info. Additional physi-
cal pages will be allocated and populated in the
exceptions
The IA-32 architecture provides 4 protection
levels of code execution. Usually they are called
“rings” and numbered as 0,1,2,3 whereas 0 is the
most privileged ring and 3 is the least privileged.
Linux uses just ring 0 and 3. Ring 0 is used when
the kernel is executed, whereas 3 is used for non-
privileged user space applications.
When a process is executed and an exception
occurs, the ring is switched from 3 to 0. One of
the consequences of this switch is changing of the
stack. The process' user space stack is replaced
by the process' kernel mode stack while the CPU
pushes several registers to the new stack. When
the execution is completed, the CPU restores the
interrupted process user space stack using the
registers it pushed to the kernel stack.
If an exception occurs during a kernel execution
in the kernel mode stack, the stack is not replaced
because the task is already running in ring 0. The
CPU cannot push the registers to the kernel mode
stack, thus it generates a double fault exception.
This is called the stack starvation problem.
Search WWH ::




Custom Search