• linux内存描述符mm_struct


    struct mm_struct
    {
    struct vm_area_struct *mmap; //list of VMA
    rb_root_t mm_rb; //指向vma段红黑树的指针
    struct vm_area_struct *mmap_cache; //last find_vma result 存储上一次查询的操作的结果
    pgd_t *pgd; //进程页目录的起始地址
    atomic_t mm_users; //how many users with user space
    atomic_t mm_count; //how many reference to "struct mm_struct"
    int map_count; //Number of VMA
    struct rw_semaphore mmap_sem; //对mmap操作的互赤信号量
    spinlock_t page_table_lock; //Protects task page tables and mm->rss
    struct list_head mmlist; //list of all active mm's. These are globally together off init_mm.mmlist,and are protected by mmlist_lock
    unsigned long start_code,end_code,start_data,end_data;
    unsigned long start_brk,brk,start_stack;
    unsigned long arg_start,arg_end,env_start,env_end;
    unsigned long rss,total_vm,locked_vm; //rss进程内容驻留在物理内存的页面地址
    unsigned long def_flags;
    unsigned long cpu_vm_mask;
    unsigned long swap_address; //页面换出过程用到交换空间地址

    unsigned dumpable:1;
    //Architecture-specific MM context
    mm_context_t context; //存放着当前进程使用的段起始地址
    };


    struct vm_area_struct
    {
    struct mm_struct *vm_mm; //The address space we belong to
    unsigned long vm_start; //our start address within vm_mm
    unsigned long vm_end;

    struct vm_area_struct *vm_next;

    pgprot_t vm_page_prot; //Access permission of this VMA
    unsigned long vm_flags;

    rb_node_t vm_rb; //rb Tree

    struct vm_area_struct *vm_next_share;
    struct vm_area_struct *vm_pprev_share;

    struct vm_operations_struct *vm_ops; //Function pointer to deal with this struct

    unsigned long vm_pgoff;

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


    struct vm_operations_struct
    {
    void (*open)(struct vm_area_struct *area);
    void (*close)(struct vm_area_struct *area);
    struct page *(*nopage)(struct vm_area_struct *area,unsigned long address,int unused);
    };


    typedef struct rb_node_s
    {
    struct rb_node_s *rb_parent;
    int rb_color;
    #define RB_RED 0
    #define RB_BLACK 1
    struct rb_node_s *rb_right;
    struct rb_node_s *rb_left;
    }rb_node_t;

    typedef struct rb_root_s
    {
    struct rb_node_s *rb_node;
    }rb_root_t;

    //在树中,所有的vm_area_struct虚存段都作为树的一个节点,节点中vm_rb的左指针rbleft指向相邻的低地址虚存段,右指针rbright指向相邻的高地址虚存段
    //用于调整红黑树的平衡
    static void __rb_rotate_left(rb_node_t *node,rb_root_t *root);
    static void __rb_rotate_right(rb_node_t *node,rb_root_t *root);

    //插入一个新节点
    void rb_insert_color(rb_node_t *node,rb_root_t *root);
    //删除一个节点
    static void __rb_erase_color(rb_node_t *node,rb_node *parent,rb_root_t *root);
    //删除后对剩余颜色的调整
    void rb_erase(rb_node_t *node,rb_root_t *root);


    //对给定的内存地址找到属于哪一个内存区域
    struct vm_area_struct *find_vma(struct mm_struct *mm,unsigned long addr)
    {
    struct vm_area_struct *vma=NULL;

    if(mm)
    {
    vma=mm->mmap_cache;
    if(!(vma&&vma->vm_end>addr&&vma->start<=addr))
    {
    struct rb_node *rb_node;
    rb_node=mm->mm_rb.rb_node;
    vma=NULL;
    while(rb_node)
    {
    struct vm_area_struct *vma_tmp;

    vma_tmp=rb_entry(rb_node,struct vm_area_struct,vm_rb);

    if(vma_tmp->vm_end>addr)
    {
    vma=vma_tmp;
    if(vma_tmp->vm_start<=addr)
    break;
    rb_node=rb_node->rb_left;
    }
    else
    rb_node=rb_node->rb_right;
    }
    if(vma)
    mm->mmap_cache=vma;
    }
    }
    return vma;
    }
    Live together,or Die alone!
  • 相关阅读:
    Java8新特性Stream详细教程
    自定义注解!绝对是程序员装逼的利器!!
    如何处理重复请求/并发请求的
    C#字符处理
    mysql 索引
    mysql事件【定时器】
    JS日期,金钱处理
    Controller中使用@Value无法获取属性值
    druid连接池的配置
    mybatiste报错java.lang.ClassCastException
  • 原文地址:https://www.cnblogs.com/hzhida/p/2395650.html
Copyright © 2020-2023  润新知