zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例
    玩转Asp.net MVC 的八个扩展点
    float实例讲解
    C#高性能TCP服务的多种实现方式
    如何把SQLServer数据库从高版本降级到低版本?
    ASP.NET MVC Area使用-将Area设置成独立项目
    如何使用ping和tracert命令测试网站访问速度
    ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
    MVC Action Filter
    c#中单元测试
  • 原文地址:https://www.cnblogs.com/miaoyong/p/4938274.html
Copyright © 2011-2022 走看看