事實上,大部份的分頁處理動作是靠硬體來執行的
以 x86為例,定址到 32bits的記憶體(即4GB),有以下幾種機制:
80x86 paging with PAE disabled
2-level paging, 4KB/page, 32-bit linear address to 32-bit physical address
80x86 paging with PAE disabled
1-level paging, 4MB/page, 32-bit linear address to 32-bit physical address
若啟用 PAE(Physical Address Extension) 功能,則可使用 36bits的記憶體空間(即64GB):
80x86 paging with PAE enabled
3-level paging, 4KB/page, 32-bit linear address to 36-bit physical address
80x86 paging with PAE enabled
2-level paging, 2MB/page, 32-bit linear address to 36-bit physical address
Linux 在 2.6.11 之後的核心使用 4-level 的 Paging
此記憶體分頁的模型可以套用在各種處理器上,四層分別為:
• Page Global Directory
• Page Upper Directory
• Page Middle Directory
• Page Table
當記憶體定址空間是 32bits 時,不使用 PUD 及 PMD
如此,便可同時支援 32 及 64 位元的記憶體架構
2.6 Linux paging model
4-level paging, 32/64-bit linear address to 32/64-bit physical address
2.6 Linux paging with PAE disabled
2-level paging, 4KB/page, 32-bit linear address to 32-bit physical address
2.6 Linux paging with PAE enabled
3-level paging, 4KB/page, 32-bit linear address to 36-bit physical address
2.6 Linux paging with PAE enabled
2-level paging, 2MB/page, 32-bit linear address to 36-bit physical address
在 Kernel Source Code 中,Page-Directory 及 Page-Table 是用相同的結構
分別名命為 pgd_t 及 pte_t,定義於 include/asm-i386/page.h
若未使用 PAE,則其大小為 32bits,否則為 64bits
Page-Directory Entry with PAE disabled
4KB/page-table, 32-bit physical address
32bits 的 pgd_t 的欄位格式如下:
//2.6 Linux : Page Global Directory
typedef struct { unsigned long pgd; } pgd_t;
Page-Table Entry with PAE disabled
4KB/page, 32-bit physical address
32bits 的 pte_t 的欄位格式如下:
//2.6 Linux : Page Table Entry
typedef struct { unsigned long pte_low; } pte_t;
Page-Directory Entry with PAE enabled
2MB/page, 32-bit physical address
此時的型態為 64bits 的資料,定義如下:
//2.6 Linux : Page Table Entry
typedef struct { unsigned long pte_low, pte_high; } pte_t;
//2.6 Linux : Page Middle Directory
typedef struct { unsigned long pmd; } pmd_t;
//2.6 Linux : Page Global Directory
typedef struct { unsigned long pgd; } pgd_t;
結論:
Linux 使用 4-level paging 機制來套用到不同的硬體平台,而且可相容於 32/64-bit 的架構
但是,若硬體的 Paging Unit 其分頁方式大於 4-level,Linux 就無法支援
沒有留言:
張貼留言