【Linux 内核 内存管理】内存映射相关数据结构 ② ( vm_area_struct 结构体成员分析 | vm_mm 成员 | vm_page_prot 成员 | vm_flags 成员 )
2023-06-13 09:18:05 时间
文章目录
在之前的博客 【Linux 内核 内存管理】虚拟地址空间布局架构 ⑦ ( vm_area_struct 结构体成员分析 | vm_start | vm_end | vm_next | vm_prev |vm_rb) 中 , 分析了 vm_start
vm_end
vm_next
vm_prev
vm_rb
这
个结构体成员的含义 , 下面继续分析剩余结构体成员的含义 ;
一、vm_area_struct 结构体成员分析
1、vm_mm 成员
struct mm_struct *vm_mm
成员的作用是 指向 " 内存描述符 " mm_struct
结构体 , 这是该 " 虚拟内存区域 " vm_area_struct
所属的 " 进程的用户虚拟地址空间 " mm_struct
内存描述符结构体 ;
vm_area_struct
结构体 是 " 虚拟内存区域 " ;
mm_struct
结构体 是 " 进程的用户虚拟地址空间 " , 又称为 " 内存描述符 " ;
struct mm_struct *vm_mm; /* The address space we belong to. */
2、vm_page_prot 成员
pgprot_t vm_page_prot
成员是 控制访问权限 的 " 保护位 " ,
pgprot_t vm_page_prot; /* Access permissions of this VMA. */
3、vm_flags 成员
unsigned long vm_flags
表示 虚拟内存 的 标志 ;
unsigned long vm_flags; /* Flags, see mm.h. */
虚拟内存 相关的标志位定义在 linux-4.12\include\linux\mm.h#159 位置
上述 unsigned long vm_flags
可设置的标志位有 VM_READ
VM_WRITE
VM_EXEC
VM_SHARED
等 ;
/*
* vm_flags in vm_area_struct, see mm_types.h.
* When changing, update also include/trace/events/mmflags.h
*/
#define VM_NONE 0x00000000
#define VM_READ 0x00000001 /* currently active flags */
#define VM_WRITE 0x00000002
#define VM_EXEC 0x00000004
#define VM_SHARED 0x00000008
二、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;
};
相关文章
- 【Linux 内核 内存管理】虚拟地址空间布局架构 ④ ( 内存描述符 mm_struct 结构体成员分析 | hiwater_rss | start_code | start_brk )
- 版本Linux查看CPU内核版本的方法(linux查看cpu内核)
- Linux内存回收:掌握释放命令(linux内存回收命令)
- Linux进程内存管理之分配学习(linux进程内存分配)
- 动态管理Linux服务器空间自动调度优化(linux服务器空间)
- 探索Linux内核内存布局之旅(linux内核内存布局)
- 探索Linux开源软件新时代(linux软件项目)
- 重装之路:在VM上安装Linux(vm装linux)
- 搭建静态网站搭建静态网站:Linux解决方案(用linux系统)
- 挑战!将Linux系统安装到U盘上(安装linux系统到u盘)
- 发行版最轻巧的Linux发行版:只有256MB内存也能轻松运行(最轻巧的linux)
- Linux异步线程:极限扩展实现(linux异步线程)
- Linux内存泄露: 探究如何检测与预防(linux内存泄露检测)
- Linux如何自动识别网卡驱动程序(linux识别网卡驱动)
- Linux内核邮件列表:揭示开源世界的核心(linux内核邮件列表)
- Linux查询端口: 一种快速便捷的方式(linux查询端口程序)
- Linux系统下如何调整主机名(linux怎么修改主机名)
- 定时任务管理:Linux 上的解决方案(linux定时任务管理)
- 模型Linux的分支模型:探索基础与深度(linux的分支)
- Linux系统的分支变化与发展(linux的分支)
- 设置Linux 内核优化:修改参数提升性能(linux的内核参数)
- 更新Linux系统 安装最新内核(更新linux内核)
- 学习Linux内核修改:一步一步深入(linux修改内核)
- 和发行版Linux的分支与发行版:来自开源社区的传奇(linux的分支)
- Linux内核文件系统简介(linux内核文件系统)
- Linux中如何进行日期转换?——轻松Get转换技巧(linux日期转换)
- Exploring the Power of Linux’s Read and Write Functions: A Comprehensive Guide(linux读写函数)
- Linux 内核转发:探索数据传输的新途径(linux 内核转发)
- 提升系统性能:Linux内核参数调优之道(linux 内核参数调优)
- Linux系统下如何查看内存使用情况(linux 内存查看)
- Linux内核技术视频教程(linux 内核视频教程)
- Linux如何快速删除指定文件(linux 删除指定文件)
- Linux编译完美内核,助力智慧未来(linux编译好的内核)