Linux 內存映射

 

The linear address space of a process is divided into two parts(Figure7.13):

·         Linear addresses from 0x00000000 to 0xbfffffff can be addressed when the process runs in either User or Kernel Mode.

·         Linear addresses from 0xc0000000 to 0xffffffff can be addressed only when the process runs in Kernel Mode.

 

 

 

Figure 8-7 shows how the fourth gigabyte linear addresses(starting from PAGE_OFFSET ,usually 0xc0000000) are used:

·         The initial part of the fourth gigabyte of kernel linear addresses maps the physical memory of the system. The beginning of the area includes the linear addresses that map the first 896 MB of RAM; the linear address that corresponds to the end of the directly mapped physical memory is stored in the high_memory variable.

·         The end of the area contains the fix-mapped linear addresses. Basically, a fix-mapped linear address is a constant linear address like 0xffffc000 whose corresponding physical address does not have to be the linear address minus 0xc000000, but rather a physical address set in an arbitrary way. Thus, each fix-mapped linear address maps one page frame of the physical memory. As we'll see in later chapters, the kernel uses fix-mapped linear addresses instead of pointer variables that never change their value.

就是說內核是常駐內存的,內核的每一頁物理地址都被固定的映射爲線性地址中的一頁,不會像用戶程序一樣被頁管理機制換入換出,內核不會再被重定位,開發內核的人員自己知道內核運行時的線性地址,所以可以直接使用線性地址而無需使用變量。而開發用戶程序的人員站在用戶層的角度,不知道自己程序即將分配的線性地址,所以使用變量,由鏈接器爲其分配運行時線性地址,並由加載器loader載入內存。

·         Starting from PKMAP_BASE we find the linear addresses used for the persistent kernel mapping of high-memory page frames.Permanent kernel mappings allow the kernel to establish long-lasting mappings of high-memory page frames into the kernel address space. They use a dedicated Page Table in the master kernel page tables . The pkmap_page_table variable stores the address of this Page Table, while the LAST_PKMAP macro yields the number of entries. As usual, the Page Table includes either 512 or 1,024 entries, according to whether PAE is enabled or disabled (see the section "The Physical Address Extension (PAE) Paging Mechanism" in Chapter 2); thus, the kernel can access at most 2 or 4 MB of high memory at once.The Page Table maps the linear addresses starting from PKMAP_BASE.

·         The remaining linear addresses can be used for noncontiguous memory areas. A safety interval of size 8 MB (macro VMALLOC_OFFSET) is inserted between the end of the physical memory mapping and the first memory area; its purpose is to "capture" out-of-bounds memory accesses. For the same reason, additional safety intervals of size 4 KB are inserted to separate noncontiguous memory areas.

 

The VMALLOC_START macro defines the starting address of the linear space reserved for noncontiguous memory areas, while VMALLOC_END defines its ending address.

References:

       understanding computer system

       understanding linux kernel

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章