实 验 报 告
学生姓名 黄东 学号 16281255 指导老师 何永忠
一、 实验名称:
实验五:页面置换算法
二、 实验环境
Windows 7 旗舰版,VC 6.0
三、 实验内容:
- 实验设计
1.1 概要设计
1.2 详细设计 - 实验实现
2.1 生成随机访问序列
2.2 最佳置换算法
2.3 先进先出置换算法
2.4 最近最久未使用置换算法
2.5 改进型clock置换算法
2.6 页面缓冲置换算法 - 实验分析
四、 实验过程: - 实验设计
1.1 概要设计
由于分区式管理尽管实现方式较为简单,但存在着严重的碎片问题使得内存的利用率不高。再者,分区式管理时,由于各作业或进程对应于不同的分区以及在分区内各作业或进程连续存放,进程的大小或内存可用空间的限制。而且分区式管理也不利于程序段和数据段的共享。页式管理正是为了减少碎片以及为了只在内存存放那些反复执行或即将执行的程序段与数据部分,而把那些不经常执行的程序段和数据存放于外存待执行时调入,以提高内存利用率而提出来的页式管理有动态页式管理和静态页式管理之分,动态页式管理是在静态页式管理的基础上发展起来的。请求页式管理属于动态页式管理中的一种,它的地址变换过程与静态页式管理时的相同,也是通过页表查出相应的页面号,由页面号与页内相对地址相加而得到实际物理地址。有关的地址变换部分是由硬件自动完成的。当硬件变换机构发现所要求的页不在内存时,产生缺页中断信号,由中断处理程序做出相应的处理。中断处理程序是由软件实现的。除了在没有空闲页面时要按照置换算法选择出被淘汰页面之外,还要从外存读入所需要的虚页。这个过程要启动相应的外存和涉及到文件系统。因此,请求页式管理是一个十分复杂的过程,内存利用率的提高是以牺牲系统开销的代价换来的。这里用到了置换算法。它是在内存中没有空闲页面时被调用。目的是选出一个被淘汰的页面。如果内存中有足够的空闲页面存放所调入的页,则不必使用置换算法。把内存和外存统一管理的真正目的是把那些被访问概率非常高的页存放在内存中。因此,置换算法应该置换那些被访问概率低的页,将它们移出内存。
1.2 详细设计
图1.2 整体结果图 - 实验实现
2.1 生成随机访问序列
图2.1.1 生成序列函数
图2.1.2 生成随机序列
2.2 最佳置换算法
图2.2.1 最佳置换算法
图2.2.2 OPT演示结果
2.3 先进先出置换算法
图2.3.1 FIFO算法
图2.3.2 FIFO演示结果
2.4 最近最久未使用置换算法
图2.4.1 LRU算法
图2.4.2 LRU演示结果
2.5 改进型clock置换算法
图2.5.1 CLOCK算法
图2.5.2 CLOCK演示结果
2.6 页面缓冲置换算法
图2.6.1 PBA算法
图2.6.2 PBA演示结果
3. 实验分析
通过设置不同的访问序列、不同的虚拟内存尺寸可以发现,在这五种页面置换算法中,opt最佳置换算法确实是最好的,在大多数情况下其缺页率都是最少的,但从时间开销上而言,opt的时间开销比较大,不出意外,先进先出算法是时间开销最小的,但也因此,其缺页率也比较高。lru算法同opt差不多,一个是往前看,一个是往后看,因此lru也是缺页率低时间开销大。而对于改进clock置换算法,由于他要对内存页面进行多次扫描,因此开销比较大。对于页面缓冲算法pab,由于其可以一起将所有已修改页面写回磁盘,因此显著减少了磁盘I/O操作次数,降低了开销。
五、 总结反思:
这次操作系统课程设计,让我们对操作系统有了更深的认识,首先操作系统是一管理电脑硬件与软件资源的程序,同时也是计算机系统内核与基石。操作系统是一个庞大的管理控制程序,大致包括5个方面的管理功能:进程与处理机管理、作业管理、存储管理、设备管理、文件管理。我们这次课程设计的题目是页面置换算法,是属于存储器管理。
在进程运行过程中,若其访问的页面不在内存而需把它们调入内存,但内存以无空闲空间时,为了保证该进程能正常的运行,系统必须从内存中调出一页程序或数据送磁盘的兑换区中,但应将哪个页面调出,需根据一定的算法来确定。通常,把选择换成页面的算法称为页面置换算法。但是在编写代码进行实际完成仍有较大不理解地方,需要参照学习其他材料。
本博客若由于排版不当,不便于观看,请下载Word报告查看:
GitHub:https://github.com/16281255/Operating-system-Lab/tree/master/实验五
参考文章:
【1】https://blog.csdn.net/AaricYang/article/details/72861566
【2】https://blog.csdn.net/qq_40743144/article/details/90578302