文章目录
- 一、vm_area_struct 结构体成员分析
- 二、vm_area_struct 结构体完整源码
一、vm_area_struct 结构体成员分析
vm_area_struct
结构体中相关成员解析 :
unsigned long vm_start
成员 : 虚拟内存空间 起始地址 ;
unsigned long vm_start; /* Our start address within vm_mm. */
unsigned long vm_end
成员 : 虚拟内存空间 终止地址 后的 第一个字节 ;
unsigned long vm_end; /* The first byte after our end address
within vm_mm. */
struct vm_area_struct *vm_next
成员 : 是vm_area_struct
链表中 , 本元素之后的链表元素 ;struct vm_area_struct *vm_prev
成员 : 是vm_area_struct
链表中 , 本元素之前的链表元素 ;
/* linked list of VM areas per task, sorted by address */
struct vm_area_struct *vm_next, *vm_prev;
struct rb_node vm_rb
成员 : 红黑树 数据结构 , 将vm_area_struct
作为叶子节点 插入到 红黑树 中 , 能 提高 搜索效率 ; 每个进程对应的 " 虚拟内存空间 "mm_struct
都会创建一个 红黑树 数据结构 , 该结构中的元素就是vm_area_struct
结构体 ;
struct rb_node vm_rb;
二、vm_area_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 {
/* The first cache line has the info for VMA tree walking. */
unsigned long vm_start; /* Our start address within vm_mm. */
unsigned long vm_end; /* The first byte after our end address
within vm_mm. */
/* linked list of VM areas per task, sorted by address */
struct vm_area_struct *vm_next, *vm_prev;
struct rb_node vm_rb;
/*
* Largest free memory gap in bytes to the left of this VMA.
* Either between this VMA and vma->vm_prev, or between one of the
* VMAs below us in the VMA rbtree and its ->vm_prev. This helps
* get_unmapped_area find a free area of the right size.
*/
unsigned long rb_subtree_gap;
/* Second cache line starts here. */
struct mm_struct *vm_mm; /* The address space we belong to. */
pgprot_t vm_page_prot; /* Access permissions of this VMA. */
unsigned long vm_flags; /* Flags, see mm.h. */
/*
* For areas with an address space and backing store,
* linkage into the address_space->i_mmap interval tree.
*/
struct {
struct rb_node rb;
unsigned long rb_subtree_last;
} shared;
/*
* A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
* list, after a COW of one of the file pages. A MAP_SHARED vma
* can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
* or brk vma (with NULL file) can only be in an anon_vma list.
*/
struct list_head anon_vma_chain; /* Serialized by mmap_sem &
* page_table_lock */
struct anon_vma *anon_vma; /* Serialized by page_table_lock */
/* Function pointers to deal with this struct. */
const struct vm_operations_struct *vm_ops;
/* Information about our backing store: */
unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
units */
struct file * vm_file; /* File we map to (can be NULL). */
void * vm_private_data; /* was vm_pte (shared mem) */
#ifndef CONFIG_MMU
struct vm_region *vm_region; /* NOMMU mapping region */
#endif
#ifdef CONFIG_NUMA
struct mempolicy *vm_policy; /* NUMA policy for the VMA */
#endif
struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
};