免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1285 | 回复: 0

Memory Addressing (十六) [复制链接]

论坛徽章:
0
发表于 2008-04-08 22:16 |显示全部楼层

Paging in Linux
Linux adopts a common paging model that fits both 32-bit and 64-bit architectures. As explained in the earlier section "Paging for 64-bit Architectures," two paging levels are sufficient for 32-bit architectures, while 64-bit architectures require a higher number of paging levels. Up to version 2.6.10, the Linux paging model consisted of three paging levels. Starting with version 2.6.11, a four-level paging model has been adopted.

  • The four types of page tables illustrated in Figure 2-12 are called:
  • This change has been made to fully support the linear address bit splitting used by the x86_64 platform (see Table 2-4).
    ·         Page Global Directory
    ·         Page Upper Directory
    ·         Page Middle Directory
    ·         Page Table
    Linux采用了一种通用的分页模型,适用于32bit和64bit架构。两层分页结构对32bit来说足够了,而64bit要求更高层次的结构。在Linux2.6.10之前,Linux分页模型由3层组成,从2.6.11以后发展到了4层结构(这种改变完全支持x86_64平台的线性地址划分)。四种页表分别是:
          PGD(页全局目录)、PUD(高级页目录)、PMD(页中间目录)、PT(页表)。
    The Page Global Directory includes the addresses of several Page Upper Directories, which in turn include the addresses of several Page Middle Directories, which in turn include the addresses of several Page Tables. Each Page Table entry points to a page frame. Thus the linear address can be split into up to five parts. Figure 2-12 does not show the bit numbers, because the size of each part depends on the computer architecture.
    PGD包含若干PUD的地址,PUD包含若干PMD的地址,PMD包含若干PT的地址(这里的地址都是物理地址)。每个页表项指向一个页帧。因此线性地址被划分成了5部分。图中没有显示bit位置,是因为各段的长度取决于不计算机架构。
    For 32-bit architectures with no Physical Address Extension, two paging levels are sufficient. Linux essentially eliminates the Page Upper Directory and the Page Middle Directory fields by saying that they contain zero bits. However, the positions of the Page Upper Directory and the Page Middle Directory in the sequence of pointers are kept so that the same code can work on 32-bit and 64-bit architectures. The kernel keeps a position for the Page Upper Directory and the Page Middle Directory by setting the number of entries in them to 1 and mapping these two entries into the proper entry of the Page Global Directory.
    对于没有启用PAE扩展的32位架构,两层页结构就足够了。Linux将PUD和PMD字段设为0去掉了PUD和PMD这两层。然而PUD和PMD的位置依然保留使得32bit和64bit兼容。内核通过将PUD和PMD的容量设为1为它们保留了位置。
    Figure 2-12. The Linux paging model
    For 32-bit architectures with the Physical Address Extension enabled, three paging levels are used. The Linux's Page Global Directory corresponds to the 80x86's Page Directory Pointer Table, the Page Upper Directory is eliminated, the Page Middle Directory corresponds to the 80x86's Page Directory, and the Linux's Page Table corresponds to the 80x86's Page Table.
    对于启用PAE扩展的32bit架构,则使用三层结构。Linux的PGD对应x86的PDPT,PUD没有用,PMD对应x86的页目录,Linux的PT对应x86的页表。
    Finally, for 64-bit architectures three or four levels of paging are used depending on the linear address bit splitting performed by the hardware (see Table 2-2).
    对于64bit架构,三层或四层结构都可以使用,取决于硬件怎样划分线性地址。
    Linux's handling of processes relies heavily on paging. In fact, the automatic translation of linear addresses into physical ones makes the following design objectives feasible:
    ·         Assign a different physical address space to each process, ensuring an efficient protection against addressing errors.
    ·         Distinguish pages (groups of data) from page frames (physical addresses in main memory). This allows the same page to be stored in a page frame, then saved to disk and later reloaded in a different page frame. This is the basic ingredient of the virtual memory mechanism (see Chapter 17).
    Linux处理进程时对页的依赖很高。事实上,线性地址到物理地址的自动转换有如下好处:
          分配不同的物理地址空间给每个进程,确保了有效的保护以避免地址错误。
          将页面(一组数据)和页帧(主存的物理地址空间)区分开。这样允许同一页保存在一个页帧,在保存到磁盘后,重新冲磁盘装载到内存时可以放入另一个不同的页帧。这是实现虚拟存储机制的基本要素。
    In the remaining part of this chapter, we will refer for the sake of concreteness to the paging circuitry used by the 80 x 86 processors.
    As we will see in Chapter 9, each process has its own Page Global Directory and its own set of Page Tables. When a process switch occurs (see the section "Process Switch" in Chapter 3), Linux saves the cr3 control register in the descriptor of the process previously in execution and then loads cr3 with the value stored in the descriptor of the process to be executed next. Thus, when the new process resumes its execution on the CPU, the paging unit refers to the correct set of Page Tables.
    第九章我们会看到,每个进程都有自己的PGD和自己很多PT。当发生进程切换时,Linux将CR3的内容保存在切换出去的那个进程的描述符中,然后将对应值从即将运行的进程的描述符中加载到CR3中。这样,当那个新的进程在CPU中运行时,分页部件使用的是该进程正确的页表。
    Mapping linear to physical addresses now becomes a mechanical task, although it is still somewhat complex. The next few sections of this chapter are a rather tedious list of functions and macros that retrieve information the kernel needs to find addresses and manage the tables; most of the functions are one or two lines long. You may want to only skim these sections now, but it is useful to know the role of these functions and macros, because you'll see them often in discussions throughout this book.
    现在,将线性地址映射到物理地址变成了体力活,尽管它还是有点复杂。下面将会介绍一些函数和宏,通过这些代码我们将看到内核如何找到地址和管理那些表的。

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/65228/showart_522699.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP