1
mm_struct 结构体
描述了 text数据段(代码段)、初始数据段、BSS数据段、堆、栈和内存映射 等
struct mm_struct {
struct vm_area_struct * mmap; /* list of VMAs */ 用来描述内存映射
struct rb_root mm_rb;
struct vm_area_struct * mmap_cache; /* last find_vma result */
unsigned long (*get_unmapped_area) (struct file *filp,
使用 struct vm_area_struct * mmap 表示不同类型的虚拟内存区域
2
mmap 的作用
a 将文件内容映射到进程用户态的虚拟地址空间中
b 分配内存
mmap基本原理
a 普通文件的mmap基本原理
b 特殊文件
c 匿名映射的基本原理
参考:mmap原理及流程(kernel 4.1版本)
3 用户调用mmap流程
1 在进程的虚拟空间查找一块 VMA
2 将这个块 VMA 进行映射
3 如果设备驱动程序或者文件系统的 file_operations 定义了 mmap() 操作,则调用它。
4 将这个VMA 插入进程的 VMA链表中
file_operations 中 mmap 函数的第一个参数就是 步骤 1)找到的 VMA