您的位置:首页 > 运维架构 > Linux

Linux 的 Virtual Memory Areas(VMA)

2013-08-09 07:55 423 查看
jollen 發表於 January 5, 2007 2:08 PM

由 user process 角度來說明的話,VMA 是 user process 裡一段 virtual address space 區塊;virtual address space 是連續的記憶體空間,當然 VMA 也會是連續的空間。VMA 對 Linux 的主要好處是,可以記憶體的使用更有效率,並且更容易管理 user process address space。

從另一個觀念來看,VMA 可以讓 Linux kernel 以 process 的角度來管理 virtual address space。Process 的 VMA 對映,可以由
/proc/<pid>/maps 檔案查詢;例如 pid 1(init)的 VMA mapping 為:

$ cat /proc/1/maps
08048000-0804e000 r-xp 00000000 08:01 12118      /sbin/init
0804e000-08050000 rw-p 00005000 08:01 12118      /sbin/init
08050000-08054000 rwxp 00000000 00:00 0
40000000-40016000 r-xp 00000000 08:01 52297      /lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 08:01 52297      /lib/ld-2.2.4.so
40024000-40025000 rw-p 00000000 00:00 0
40025000-40157000 r-xp 00000000 08:01 58241      /lib/i686/libc-2.2.4.so
40157000-4015c000 rw-p 00131000 08:01 58241      /lib/i686/libc-2.2.4.so
4015c000-40160000 rw-p 00000000 00:00 0
bfffe000-c0000000 rwxp fffff000 00:00 0 


列表中的欄位格式如下:

start-end perm offset major:minor inode image


Linux 以 struct vm_area_struct 資料結構來紀錄每一「區塊」的 VMA 資訊(include/linux/mm.h):

struct vm_area_struct {
struct mm_struct * vm_mm;
unsigned long vm_start;
unsigned long vm_end;

struct vm_area_struct *vm_next;

pgprot_t vm_page_prot;
unsigned long vm_flags;

rb_node_t vm_rb;

struct vm_area_struct *vm_next_share;
struct vm_area_struct **vm_pprev_share;

struct vm_operations_struct * vm_ops;

unsigned long vm_pgoff;

struct file * vm_file;
unsigned long vm_raend;
void * vm_private_data;
};


struct vm_area_struct 裡有 3 個欄位,用來來維護 VMA 資料結構:

˙ unsigned long vm_start:記錄此 VMA 區塊的開始位址(start address)。

˙ unsigned long vm_end:記錄此 VMA 區塊的結束位址(end address)。

˙ struct vm_area_struct *vm_next:指向下一個 VMA 區塊結構的指標(Linux 以 linked list 資料結構維護每一個 VMA 區塊)。

VMA 的實作主要是為了能更有效率地管理記憶體,並且是基於 paging 系統之上所發展出的;VMA 是比原始 paging 理論更高階的記憶體管理方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: