LINUX內(nèi)核地址空間的布局_第1頁
LINUX內(nèi)核地址空間的布局_第2頁
LINUX內(nèi)核地址空間的布局_第3頁
LINUX內(nèi)核地址空間的布局_第4頁
LINUX內(nèi)核地址空間的布局_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、linux內(nèi)核地址空間的布局1) linux將整個4g線性地址空間分為用戶空間和內(nèi)核空間兩部分,而內(nèi)核地址空間又被劃分為物理內(nèi)存區(qū), 虛擬內(nèi)存分配區(qū), 高端頁面映射區(qū),專用頁面映射區(qū), 系統(tǒng)保留映射區(qū)幾個區(qū)域. 2) 在標(biāo)準(zhǔn)配置下, 物理區(qū)最大長度為896m, 系統(tǒng)的物理內(nèi)存被順序映射在物理區(qū)中,在支持?jǐn)U展頁長(pse)和全局頁面(pge)的機器上, 物理區(qū)使用4m頁面并作為全局頁面來處理.當(dāng)系統(tǒng)物理內(nèi)存大于896m時, 超過物理區(qū)的那部分內(nèi)存稱為高端內(nèi)存,低端內(nèi)存和高端內(nèi)存用highmem_start_page變量來定界,內(nèi)核在存取高端內(nèi)存時必須將它們映射到高端頁面映射區(qū). 3) linux

2、保留內(nèi)核空間最頂部128k區(qū)域作為保留區(qū),緊接保留區(qū)以下的一段區(qū)域為專用頁面映射區(qū),它的總尺寸和每一頁的用途由fixed_address枚舉結(jié)構(gòu)在編繹時預(yù)定義,用_fix_to_virt(index)可獲取專用區(qū)內(nèi)預(yù)定義頁面的邏輯地址.在專用頁面區(qū)內(nèi)為每個cpu預(yù)定義了一張高端內(nèi)存映射頁, 用于在中斷處理中高端頁面的映射操作.4) 距離內(nèi)核空間頂部32m, 長度為4m的一段區(qū)域為高端內(nèi)存映射區(qū),它正好占用1個頁幀表所表示的物理內(nèi)存總量, 它可以緩沖1024個高端頁面的映射.在物理區(qū)和高端映射區(qū)之間為虛存內(nèi)存分配區(qū), 用于vmalloc()函數(shù),它的前部與物理區(qū)有8m隔離帶, 后部與高端映射區(qū)有

3、8k的隔離帶. 5) 當(dāng)系統(tǒng)物理內(nèi)存超過4g時,必須使用cpu的擴展分頁(pae)模式所提供的64位頁目錄項才能存取到4g以上的物理內(nèi)存.在pae模式下, 線性地址到物理地址的轉(zhuǎn)換使用3級頁表, 第1級頁目錄由線性地址的最高2位索引,每一目錄項對應(yīng)1g的尋址空間, 第2級頁目錄項以9位索引, 每一目錄項對應(yīng)2m的尋址空間,第3級頁目錄項以9位索引, 每一目錄項對應(yīng)4k的頁幀.除了頁目錄項所描述的物理地址擴展為36位外, 64位和32位頁目錄項結(jié)構(gòu)沒有什么區(qū)別.在pae模式下, 包含pse位的中級頁目錄項所對應(yīng)的頁面從4m減少為2m. /* just any arbitrary offset t

4、o the start of the vmalloc vm area: the * current 8mb value just means that there will be a 8mb hole after the * physical memory until the kernel virtual memory starts. that means that * any out-of-bounds memory accesses will hopefully be caught. * the vmalloc() routines leaves a hole of 4kb between

5、 each vmalloced * area for the same reason. ;) */#define vmalloc_offset(8*1024*1024) 虛擬區(qū)與物理區(qū)的隔離寬度#define vmalloc_start(unsigned long) high_memory + 2*vmalloc_offset-1) & (vmalloc_offset-1) 虛擬區(qū)的開始#define vmalloc_vmaddr(x) (unsigned long)(x)#if config_highmem# define vmalloc_end(pkmap_base-2*page_size

6、)#else# define vmalloc_end(fixaddr_start-2*page_size)#endif#define pkmap_base (0xfe000000ul) 高端映射區(qū)的開始#define fixaddr_top(0xffffe000ul) 專用映射區(qū)的頂部#define fixaddr_size(_end_of_fixed_addresses page_shift) 專用映射區(qū)尺寸#define fixaddr_start(fixaddr_top - fixaddr_size) 專用映射區(qū)開始#define _fix_to_virt(x)(fixaddr_top

7、- (x) page_shift) 取專用映射區(qū)頁面/* * on up currently we will have no trace of the fixmap mechanizm, * no page table allocations, etc. this might change in the * future, say framebuffers for the console driver(s) could be * fix-mapped? */enum fixed_addresses 專用區(qū)頁面的功能定義#ifdef config_x86_local_apicfix_apic_b

8、ase,/* local (cpu) apic) - required for smp or not */#endif#ifdef config_x86_io_apicfix_io_apic_base_0,fix_io_apic_base_end = fix_io_apic_base_0 + max_io_apics-1,#endif#ifdef config_x86_visws_apicfix_co_cpu,/* cobalt timer */fix_co_apic,/* cobalt apic redirection table */ fix_li_pcia,/* lithium pci

9、bridge a */fix_li_pcib,/* lithium pci bridge b */#endif#ifdef config_highmem 用于中斷處理內(nèi)映射高端頁面fix_kmap_begin,/* reserved ptes for temporary kernel mappings */fix_kmap_end = fix_kmap_begin+(km_type_nr*nr_cpus)-1,#endif_end_of_fixed_addresses;enum km_type km_bounce_read,km_bounce_write,km_type_nr; arch/i3

10、86/mm/init.c:static void _init pagetable_init (void) 建立內(nèi)核空間的頁表unsigned long vaddr, end;pgd_t *pgd, *pgd_base;int i, j, k;pmd_t *pmd;pte_t *pte, *pte_base;/* * this can be zero as well - no problem, in that case we exit * the loops anyway due to the ptrs_per_* conditions. */end = (unsigned long)_va(m

11、ax_low_pfn*page_size); 取內(nèi)核物理內(nèi)存區(qū)域終止邊界物理地址pgd_base = swapper_pg_dir; 取內(nèi)核基準(zhǔn)頁目錄表地址#if config_x86_pae 在pae模式下, 首級頁表只包含4個64位目錄項for (i = 0; i ptrs_per_pgd; i+) pgd = pgd_base + i;_pgd_clear(pgd);#endifi = _pgd_offset(page_offset); 取內(nèi)核空間起始邊界在首級頁表內(nèi)的地址偏移pgd = pgd_base + i; for (; i = end) 如果該映射區(qū)域起始邊界大于或等于內(nèi)核物理

12、內(nèi)存的終止邊界break; 退出掃描#if config_x86_paepmd = (pmd_t *) alloc_bootmem_low_pages(page_size); 分配中級頁表set_pgd(pgd, _pgd(_pa(pmd) + 0x1); 將中級頁表登記到首級頁表#elsepmd = (pmd_t *)pgd; #endifif (pmd != pmd_offset(pgd, 0)bug();for (j = 0; j = end)break;if (cpu_has_pse) 如果cpu具有擴展頁長功能unsigned long _pe;set_in_cr4(x86_cr4_

13、pse);boot_cpu_data.wp_works_ok = 1; _pe = _kernpg_table + _page_pse + _page_user + _pa(vaddr); 使用擴展頁長目錄項/* make it global too if supported */if (cpu_has_pge) set_in_cr4(x86_cr4_pge);_pe += _page_global; 設(shè)置全局頁目錄項標(biāo)志set_pmd(pmd, _pmd(_pe); 設(shè)置中級頁表continue; 繼續(xù)下一中級頁目錄項; 不使用擴展頁長pte_base = pte = (pte_t *) a

14、lloc_bootmem_low_pages(page_size); 分配頁幀表for (k = 0; k = end)break;*pte = mk_pte_phys(_pa(vaddr), page_kernel); 設(shè)置頁幀表set_pmd(pmd, _pmd(_kernpg_table + _pa(pte_base); 設(shè)置中級頁表if (pte_base != pte_offset(pmd, 0)bug();/* * fixed mappings, only the page table structure has to be * created - mappings will be

15、 set by set_fixmap(): */vaddr = _fix_to_virt(_end_of_fixed_addresses - 1) & pmd_mask;取專用區(qū)起始地址所在的中級頁目錄邊界地址fixrange_init(vaddr, 0, pgd_base); 建立專用區(qū)頁表#if config_highmem/* * permanent kmaps: */vaddr = pkmap_base; fixrange_init(vaddr, vaddr + page_size*last_pkmap, pgd_base); 建立高端映射區(qū)頁表pgd = swapper_pg_dir

16、 + _pgd_offset(vaddr);pmd = pmd_offset(pgd, vaddr);pte = pte_offset(pmd, vaddr);pkmap_page_table = pte; 設(shè)置高端映射區(qū)所在的頁幀目錄#endif#if config_x86_pae/* * add low memory identity-mappings - smp needs it when * starting up on an ap from real-mode. in the non-pae * case we already have these mappings through

17、head.s. * all user-space mappings are explicitly cleared after * smp startup. */pgd_base0 = pgd_baseuser_ptrs_per_pgd;#endifstatic void _init fixrange_init (unsigned long start, unsigned long end, pgd_t*pgd_base)pgd_t *pgd;pmd_t *pmd;pte_t *pte;int i, j;unsigned long vaddr;vaddr = start;i = _pgd_offset(vaddr);j = _pmd_offset(vaddr);pgd = pgd_base + i;for ( ; (i ptrs_per_pgd) & (vaddr != end); pgd+, i+) #if config_x86_paeif (pgd_none(*pgd) pmd = (pmd_t *) alloc_bootmem_low_pages(page_size);set_pgd(pgd, _pgd(_pa(pmd) + 0x1);if (pmd != pmd_offset(pgd, 0)printk(pae bug #02!n);

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論