红联Linux门户
Linux帮助

Linux内存描述符mm_struct初窥

发布时间:2014-11-25 15:45:33来源:linux网站作者:hongchangfirst

上次讲了Linux进程描述符,这次我们在讲讲内存描述符,Linux的内存描述符也用一个结构体来表示,具体是mm_struct结构体,在linux/mm_types.h里定义。Linux操作系统就是用这个结构体实现内存的管理,我们先看一下具体的字段情况。


struct mm_struct { 
//拥有该结构体的进程的虚拟地址空间的大小 
unsigned long task_size;   
/* if non-zero, the largest hole below free_area_cache */ 
unsigned long cached_hole_size;  
     
/* first hole of size cached_hole_size or larger */ 
unsigned long free_area_cache;  
     
//在用户空间下有多少用户使用该内存 
     
atomic_t mm_users;   /* How many users with user space? */ 
     
//该结构体的引用计数值 
atomic_t mm_count;   
      
/*又出现了list_head,详情请参考,简单来讲,list_head和list_for_each、list_entry共同实现了其“包含体”的链表。*/ 
     
struct list_head mmlist;   
     
/*以下是关于代码段、数据段,栈、环境变量、参数的起始地址或结束地址等*/ 
unsigned long total_vm, locked_vm, shared_vm, exec_vm; 
unsigned long stack_vm, reserved_vm, def_flags, nr_ptes; 
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; 
/* 
* Last value of global fault stamp as seen by this process. 
* In other words, this value gives an indication of how long 
* it has been since this task got the token. 
* Look at mm/thrash.c 
*/ 
unsigned int faultstamp; 
unsigned int token_priority; 
unsigned int last_interval; 
};


该结构体可以通过进程描述符来得到,比如current是当前进程的描述符,则current->mm是指向内存的指针。mm是指向struct mm_struct的指针。若还想对Linux的进程描述符有一定了解,可以参考task_struct。