ULK --- Chap3 Processes: Process Descriptor Handling

Processes are dynamic entities whose lifetimes range from a few milliseconds to months. Thus, the

kernel must be able to handle many processes at the same time, and process descriptors are stored

in dynamic memory rather than in the memory area permanently assigned to the kernel. For each

process, Linux packs two different data structures in a single per-process memory area: a small data

structure linked to the process descriptor, namely the thread_info structure, and the Kernel Mode

process stack. The length of this memory area is usually 8192 bytes (two page frames). For reasons

of efficiency the kernel stores the 8-KB memory area in two consecutive page frames with the first

page frame aligned to a multiple of 8KB; this may turn out to be a problem when little dynamic memory

is available, because the free memory may become highly fragmented. Therefore, in the 80x86 architecture

the kernel can be configured at compilation time so that the memory area including stack and thread_info

structure spans a single page frame (4096 bytes).

In the section "Segmentation in Linux" in Chapter 2, we learned that a process in Kernel Mode accesses

a stack contained in the kernel data segment, which is different from the stack used by the process in User

Mode. Because kernel control paths make little use of the stack, only a few thousands bytes of kernel

stack are required. Therefore, 8KB is ample space for the stack and the therad_info structure. However,

when stack and thread_info structure are contained in a single page frame, the kernel uses a few additional

stacks to avoid the overflows caused by deeply nested intertupts and exceptions.

Fig 3-2 in textbook shows how the two data structures are stored in the 2-page (8KB) memory area. The

thread_info structure resides at the beginning of the memory area, and the stack grows downward from

the end. The figure also shows that the thread_info structure and the task_struct structure are mutually

linked by means of the fields taks and thrad_info, repectively.

The esp register is the CPU stack pointer, which is used to address the stack‘s top location. On 80x86

systems, the stack starts at the end and grows toward the beginning of the memory area. Right after

switching from User Mode to Kernel Mode, the kernel stack of a process is always empty, and therefore

the esp register points to the byte immediately following the stack.

The value of the esp register is decreased as soon as data is written into the stack.

时间: 2024-10-05 17:20:36

ULK --- Chap3 Processes: Process Descriptor Handling的相关文章

ULK --- Chap3 Processes: Identifying a Process

As a general rule, each execution context that can be independently scheduled must have its own process descriptor; therefore, even lightweight processes, which share a large portion of their kernel data structures, have their own task_struct structu

ULK --- Chap3 Processes: Doubly linked lists

Before moving to and describing how the kernel keeps track of the various processes in the system, we would like to emphasize the role of special data structures that implement doubly linked lists. For each list, a set of primitives operations must b

ULK --- Chap3 Processes: Lists of Tasking_Running processes

When looking for a new process to run on a CPU, the kernel has to consider only the runnable processes (that is, the processes in the TASK_RUNNING state). Earlier Linux version put all runnable processes in the same list called runqueue. Because it w

ULK --- Chap3 Processes: Relationships Among Processes

Processes created by a  program have a parent/child relationship. When a process creates multiple children, these children have sibling relationships. Several fields must be introduced in a process descriptor to represent these relationships; Process

ULK --- Chap3 Processes: How Processes Are Organized

The runqueue lists group all processes in a  TASK_RUNNING state. When it comes to grouping processes in other states, the various states call for different types of treatment, with Linux opting for one of choices shown in the following list. Processe

ULK --- Chap3 Processes

The concept of a process is fundamental to any multiprogramming operating system. A process is usually defined as an instance of a program in execution; thus, if 16 users are running vi at once, there are 16 separate processes (although they can shar

USB组合设备 Interface Association Descriptor (IAD)

Communication Device Class,简称CDCUSB Compound Device,USB复合设备USB Composite Device,USB组合设备 摘要USB复合设备 Compound Device内嵌Hub和多个Function,每个Function都相当于一个独立的USB外设,有自己的PID/VID.USB组合设备Composite Device内只有一个Function,只有一套PID/VID,通过将不同的interface定义为不同的类来实现多个功能的组合.

ULK --- Chap 4: Softirqs and Tasklets (Note)

We mentioned earlier in the section "Interrupt Handling" that several tasks among those executed by the kernel are not critical: they can be deferred for along period of time, if necessary. Remember that the interrupt service routines of an inte

Erlang 设计原则 process port io

Erlang原理 (转载自ITEYE cryolite博客 ps:精彩)by Robert Virding This is a description of some of the basic properties and features of Erlang and an attempt to describe the rationale behind them. Erlang grew as we better understood the original problem we were