页描述符 页框状态:inc1ude/1inux/page-f1ags.h enum pageflags PG_locked.Page is locked.Don't touch."/ PG_error. PG_referenced, PG_uptodate. PG_dirty. PG_Irv, PG_active. PG_8lab. PGowner_priv_I.Omer use.If pagecache.fs nay use"/ PG_arch_1. PG reserved. PG_private.If pagecache,has fa-prisate data " PG_writeback,Page is under writeback"/ #ifdef CONFIG_PAGEFLAGS_EXTEXDED PG_head./A bead page PG_tail./A tail page " #e18 PG_compoumd./A compound page/ Hendif PG_suapcache./Ssap page:smp_entry_t in private PG_mappedtodisk.Has blocks allocated on-disk PG_reclaim.To be reclained asap"/ PG_buddy./Page is free.on buddy lists " #ifdef CONFIG IA64_UINCACHED_ALLOCATOR PG_uncached.Page has been mapped as uncached " Hendif _NR_PAGEFLAGS 可4四是42刀00 陈香兰(x1 anchenoustc,edu.cn)(计界丸应【inx操作系统分折Chapter8内存管理 0 ctober31.20149/47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 页描述符 . .页框状态:include/linux/page-flags.h . . enum pageflags { PG_locked, /* Page is locked. Don’t touch. */ PG_error, PG_referenced, PG_uptodate, PG_dirty, PG_lru, PG_active, PG_slab, PG_owner_priv_1, /* Owner use. If pagecache, fs may use*/ PG_arch_1, PG_reserved, PG_private, /* If pagecache, has fs-private data */ PG_writeback, /* Page is under writeback */ #ifdef CONFIG_PAGEFLAGS_EXTENDED PG_head, /* A head page */ PG_tail, /* A tail page */ #else PG_compound, /* A compound page */ #endif PG_swapcache, /* Swap page: swp_entry_t in private */ PG_mappedtodisk, /* Has blocks allocated on-disk */ PG_reclaim, /* To be reclaimed asap */ PG_buddy, /* Page is free, on buddy lists */ #ifdef CONFIG_IA64_UNCACHED_ALLOCATOR PG_uncached, /* Page has been mapped as uncached */ #endif __NR_PAGEFLAGS }; 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 8 内存管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) October 31, 2014 9 / 47
页描述符 。页描述符将会占用很大的一段空间 。由于每个struct page结构小于64个字节,因此1MB的内存需要使用 约4个页而来存放mem mapa数组 1MB 64B每页 =4页 4KB每页人4KB每页 ●假若系统中存在512MB的内存,那么大约需要?? 1口+4四是4P在刀00 陈香兰(x1 anchenoustc,edu,cn)(计算丸应Linux操作系统分新Chapter8内存管理 0 ctober31.20149/47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 页描述符 . 页描述符将会占用很大的一段空间 由于每个struct page结构小于64个字节,因此1MB的内存需要使用 约4个页面来存放mem_map数组 1MB 4KB每页 × 64B每页 4KB每页 = 4页 假若系统中存在512MB的内存,那么大约需要?? 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 8 内存管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) October 31, 2014 9 / 47
关于NUMA ●本课程不考虑NUMA ●物理内存被划分为若千个node 。存取时间不等 。考虑CPU局部性 。Node使用数据结构pg data_t描述 ●每个node被划分成若千个zone 1口+4四1是4P在刀0C 陈香兰(x1 anchenoustc,edu,cn)(计算丸应Linx操作系统分新Chapter8内存管理 0 ctober31,201410/47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 关于NUMA 本课程不考虑NUMA 物理内存被划分为若干个node 存取时间不等 考虑CPU局部性 Node使用数据结构pg_data_t描述 每个node被划分成若干个zone 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 8 内存管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) October 31, 2014 10 / 47
Outline 页框管理:页面级分配器 。页框和页描述祠 ●存储区(Memory Zones) 。页面级分配器接口 。页框管理算法:伙伴算法 @内存区管理(memory area) 。slab分配器 非连续存储区管理 @ 小结和作业 1口t4四1是42刀00 陈香兰(x1 anchenoustc,edu,cn)(计算丸应【inux操作系统分斯Chapter8内存管理 0 ctober31,201411/47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. 页框管理:页面级分配器 页框和页描述符 存储区(Memory Zones) 页面级分配器接口 页框管理算法:伙伴算法 .2 内存区管理(memory area) slab分配器 .3 非连续存储区管理 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 8 内存管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) October 31, 2014 11 / 47
存储区(Memory Zones) ·在一个理想的体系结构中,一个页框就是一个物理存储单元, 可以用于任何事情,例如 。存放内核数据/用户数据/缓存磁盘数据等 ©实际上存在硬件制约:一些页框由于自身的物理地址的原因 不能被一些任务所使用,例如 。ISA总线的DMA控制器只能对ram的前16M寻址 ·在一些具有大容量ram的32位计算机中,CPU不能直接访问 所有的物理存储器,因为线性地址空间不够 ●为了应付这种限制,Liux把具有同样性质的物理内存 划分成一一区(zones)】 1口140是4200 陈香兰(xlanchenoustc,edu,cn)(升算丸应Linux操件丢统分新Chapter8内存管理 0 ctober31,201412/47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 存储区(Memory Zones) 在一个理想的体系结构中,一个页框就是一个物理存储单元, 可以用于任何事情,例如 存放内核数据/用户数据/缓存磁盘数据等 实际上存在硬件制约:一些页框由于自身的物理地址的原因 不能被一些任务所使用,例如 ISA总线的DMA控制器只能对ram的前16M寻址 在一些具有大容量ram的32位计算机中,CPU不能直接访问 所有的物理存储器,因为线性地址空间不够 为了应付这种限制,Linux把具有同样性质的物理内存 划分成——区(zones) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 8 内存管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) October 31, 2014 12 / 47