亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1021 | 回復: 0
打印 上一主題 下一主題

linux內(nèi)核學習筆記-struct vm_area_struct [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2008-02-29 20:10 |只看該作者 |倒序瀏覽

                    Linux內(nèi)核中,關于虛存管理的最基本的管理單元應該是struct vm_area_struct了,它描述的是一段連續(xù)的、具有相同訪問屬性的虛存空間,該虛存空間的大小為物理內(nèi)存頁面的整數(shù)倍。
    下面是struct vm_area_struct結構體的定義:
/*
* This struct defines a memory VMM memory area. There is one of these
* per VM-area/task.  A VM area is any part of the process virtual memory
* space that has a special rule for the page-fault handlers (ie a shared
* library, the executable area etc).
*/
struct vm_area_struct {
        struct mm_struct * vm_mm;       /* VM area parameters */
        unsigned long vm_start;
        unsigned long vm_end;
        /* linked list of VM areas per task, sorted by address */
        struct vm_area_struct *vm_next;
        pgprot_t vm_page_prot;
        unsigned long vm_flags;
        /* AVL tree of VM areas per task, sorted by address */
        short vm_avl_height;
        struct vm_area_struct * vm_avl_left;
        struct vm_area_struct * vm_avl_right;
        /* For areas with an address space and backing store,
         * one of the address_space->i_mmap{,shared} lists,
         * for shm areas, the list of attaches, otherwise unused.
         */
        struct vm_area_struct *vm_next_share;
        struct vm_area_struct **vm_pprev_share;
        struct vm_operations_struct * vm_ops;
        unsigned long vm_pgoff;         /* offset in PAGE_SIZE units, *not* PAGE_CACHE_SIZE */
        struct file * vm_file;
        unsigned long vm_raend;
        void * vm_private_data;         /* was vm_pte (shared mem) */
};
    vm_area_struct結構所描述的虛存空間以vm_start、vm_end成員表示,它們分別保存了該虛存空間的首地址和末地址后第一個字節(jié)的地址,以字節(jié)為單位,所以虛存空間范圍可以用[vm_start, vm_end)表示。
    通常,進程所使用到的虛存空間不連續(xù),且各部分虛存空間的訪問屬性也可能不同。所以一個進程的虛存空間需要多個vm_area_struct結構來描述。在vm_area_struct結構的數(shù)目較少的時候,各個vm_area_struct按照升序排序,以單鏈表的形式組織數(shù)據(jù)(通過vm_next指針指向下一個vm_area_struct結構)。但是當vm_area_struct結構的數(shù)據(jù)較多的時候,仍然采用鏈表組織的化,勢必會影響到它的搜索速度。針對這個問題,vm_area_struct還添加了vm_avl_hight(樹高)、vm_avl_left(左子節(jié)點)、vm_avl_right(右子節(jié)點)三個成員來實現(xiàn)AVL樹,以提高vm_area_struct的搜索速度。
    假如該vm_area_struct描述的是一個文件映射的虛存空間,成員vm_file便指向被映射的文件的file結構,vm_pgoff是該虛存空間起始地址在vm_file文件里面的文件偏移,單位為物理頁面。
    一個程序可以選擇MAP_SHARED或MAP_PRIVATE共享模式將一個文件的某部分數(shù)據(jù)映射到自己的虛存空間里面。這兩種映射方式的區(qū)別在于:MAP_SHARED映射后在內(nèi)存中對該虛存空間的數(shù)據(jù)進行修改會影響到其他以同樣方式映射該部分數(shù)據(jù)的進程,并且該修改還會被寫回文件里面去,也就是這些進程實際上是在共用這些數(shù)據(jù)。而MAP_PRIVATE映射后對該虛存空間的數(shù)據(jù)進行修改不會影響到其他進程,也不會被寫入文件中。
    來自不同進程,所有映射同一個文件的vm_area_struct結構都會根據(jù)其共享模式分別組織成兩個鏈表。鏈表的鏈頭分別是:vm_file->f_dentry->d_inode->i_mapping->i_mmap_shared, vm_file->f_dentry->d_inode->i_mapping->i_mmap。而vm_area_struct結構中的vm_next_share指向鏈表中的下一個節(jié)點;vm_pprev_share是一個指針的指針,它的值是鏈表中上一個節(jié)點(頭節(jié)點)結構的vm_next_share(i_mmap_shared或i_mmap)的地址。
    進程建立vm_area_struct結構后,只是說明進程可以訪問這個虛存空間,但有可能還沒有分配相應的物理頁面并建立好頁面映射。在這種情況下,若是進程執(zhí)行中有指令需要訪問該虛存空間中的內(nèi)存,便會產(chǎn)生一次缺頁異常。這時候,就需要通過vm_area_struct結構里面的vm_ops->nopage所指向的函數(shù)來將產(chǎn)生缺頁異常的地址對應的文件數(shù)據(jù)讀取出來。
    vm_flags主要保存了進程對該虛存空間的訪問權限,然后還有一些其他的屬性。vm_page_prot是新映射的物理頁面的頁表項pgprot的默認值。


本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u1/35101/showart_487122.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP