目录

内存管理

目录

内存的基础知识

什么是内存,有何作用

https://gitee.com/lienhui68/picStore/raw/master/null/20200712234520.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200712234623.png

进程运行的基本原理

指令的工作原理

https://gitee.com/lienhui68/picStore/raw/master/null/20200712235221.png

逻辑地址 vs 物理地址

https://gitee.com/lienhui68/picStore/raw/master/null/20200712235415.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200712235608.png

如何实现地址转换

装入模块装入内存

https://gitee.com/lienhui68/picStore/raw/master/null/20200712235901.png

绝对装入

https://gitee.com/lienhui68/picStore/raw/master/null/20200713000417.png

静态重定位

https://gitee.com/lienhui68/picStore/raw/master/null/20200713000520.png

动态重定位

https://gitee.com/lienhui68/picStore/raw/master/null/20200713001018.png

从写程序到程序运行的过程

https://gitee.com/lienhui68/picStore/raw/master/null/20200712235608.png

静态链接

https://gitee.com/lienhui68/picStore/raw/master/null/20200713001648.png

装入时动态链接

https://gitee.com/lienhui68/picStore/raw/master/null/20200713001725.png

运行时动态链接

https://gitee.com/lienhui68/picStore/raw/master/null/20200713001747.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713001920.png

内存管理的概念

内存空间的分配与回收

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003001.png

内存空间的扩充

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003035.png

地址转换

https://gitee.com/lienhui68/picStore/raw/master/null/image-20200713003147472.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003201.png

内存保护

操作系统需要提供 内存保护 功能。保证各进程在各自存储空间内运行,互不干扰

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003308.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003337.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713003404.png

覆盖与交换

覆盖与交换是内存空间扩充的两种工作

覆盖工作

https://gitee.com/lienhui68/picStore/raw/master/null/20200713004809.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713004835.png

交换工作

https://gitee.com/lienhui68/picStore/raw/master/null/20200713004923.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713004938.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713005017.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713005038.png

连续分配

https://gitee.com/lienhui68/picStore/raw/master/null/20200713005342.png

单一连续分配

https://gitee.com/lienhui68/picStore/raw/master/null/20200713011716.png

固定分区分配

https://gitee.com/lienhui68/picStore/raw/master/null/20200713011809.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713011842.png

动态分区分配

动态分区分配又称为可变分区分配。这种分配方式不会预先划分内存分区,而是在进程装入内存时根据进程的大小动态地建立分区,并使分区的大小正好适合进程的需要。因此系统分区的大小和数目是可变的。(eg:假设某计算机内存大小为 64MB,系统区 8MB,用户区共 56 MB…)

系统要用什么样的数据结构记录内存的使用情况?

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012212.png

当很多个空闲分区都能满足需求时, 应该选择哪个分区进行分配?

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012255.png

如何进行分区的分配与回收操作?

分配

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012452.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012518.png

回收

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012554.png

情况二:回收区的前面有一个相邻的空闲分区

两个相邻的空闲分区合并为一个

情况三:回收区的前、后各有一个相邻的空闲分区

三个相邻的空闲分区合并为一个

情况四:回收区的前、后都没有相邻的空闲分区

新增一个表项

注:各表项的顺序不一定按照地址递增顺序排列,具体的排列方式需要依据动态分区分配算法来确定。

https://gitee.com/lienhui68/picStore/raw/master/null/20200713012921.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713013011.png

动态分区分配算法

在动态分区分配方式中, 当很多个空闲分区都能满足需求时,应该选择哪个分区进行分配?

首次适应算法(First Fit)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713014741.png

最佳适应算法(Best Fit)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713014757.png

最坏适应算法(Worst Fit)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713014820.png

邻近适应算法(Next Fit)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713014837.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713014919.png

非连续分配管理方式

连续分配方式的缺点

https://gitee.com/lienhui68/picStore/raw/master/null/20200713022806.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713022428.png

基本分页存储管理

把“固定分区分配”改造为“非连续分配版本”

https://gitee.com/lienhui68/picStore/raw/master/null/20200713023157.png

分页存储管理的基本概念

https://gitee.com/lienhui68/picStore/raw/master/null/20200713023558.png

如何实现地址的转换

连续存放时动态重定位思想

https://gitee.com/lienhui68/picStore/raw/master/null/20200713023923.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713024542.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713024720.png

计算机是如何快速计算页号和页内偏移量

https://gitee.com/lienhui68/picStore/raw/master/null/20200713161211.png

黑色位的最大范围刚好就是页面大小

https://gitee.com/lienhui68/picStore/raw/master/null/20200713161607.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713161814.png

页表

https://gitee.com/lienhui68/picStore/raw/master/null/20200713162205.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713163258.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713163520.png

基本地址变换机构

https://gitee.com/lienhui68/picStore/raw/master/null/20200713171049.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713171654.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713171725.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713172026.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713172224.png

对页表项大小的进一步探讨

https://gitee.com/lienhui68/picStore/raw/master/null/20200713172426.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713172459.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713172525.png

具有快表的地址变换机构

基本地址变换机构的改进版本,快表相当于缓存。

局部性原理

https://gitee.com/lienhui68/picStore/raw/master/null/20200713182945.png

什么是快表(TLB)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713183021.png

引入快表后,地址的变换过程

https://gitee.com/lienhui68/picStore/raw/master/null/20200713183117.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713183251.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713183452.png

两级页表

单级页表存在什么问题?如何解决?

问题一:页表必须连续存放,因此当页表很大时,需要占用很多个连续的页框。

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190135.png

问题二:没有必要让整个页表常驻内存,因为进程在一段时间内可能只需要访问某几个特定的页面。

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190220.png

如何解决

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190305.png

两级页表的原理,逻辑地址结构

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190405.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190554.png

如何实现地址变换

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190644.png

如何解决问题2

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190733.png

两级页表问题需要注意的几个细节

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190810.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713190839.png

基本分段存储管理

与“分页”最大的区别就是——离散分配时所分配地址空间的基本单位不同。

什么是分段(类似于分页管理中的分页)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713193713.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713193959.png

什么是段表(类似于分页管理中的页表)

https://gitee.com/lienhui68/picStore/raw/master/null/20200713194324.png

如何实现地址转换

https://gitee.com/lienhui68/picStore/raw/master/null/20200713194830.png

分段、分页管理的对比

https://gitee.com/lienhui68/picStore/raw/master/null/20200713195212.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713195523.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713195647.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713195746.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713195927.png

段页式管理方式

分页、分段管理方式中最大的优缺点

https://gitee.com/lienhui68/picStore/raw/master/null/20200713201638.png

分段+分页的结合——段页式管理方式

https://gitee.com/lienhui68/picStore/raw/master/null/20200713201707.png

https://gitee.com/lienhui68/picStore/raw/master/null/20200713201830.png

段表、页表

https://gitee.com/lienhui68/picStore/raw/master/null/20200713201953.png

如何实现地址转换

https://gitee.com/lienhui68/picStore/raw/master/null/20200713202152.png

小结

https://gitee.com/lienhui68/picStore/raw/master/null/20200713202303.png