操作系统lab4

页面替换算法

学生姓名:王昊飞

学号:16281269

  1. 算法原理及过程:
    1. 最佳置换算法(OPT):
      1. 原理:所选择的被淘汰的页面将是以后永不使用的,或是在将来最长时间内不再被访问的页面。在这样理想的情况下,OPT算法能够达到最低的缺页率,但是其条件是理想的无法实现的,一般用该算法评价其他算法。
      2. 过程:当发生页面置换时,检查页面是否包含在内存中,是的话直接显示,否则检查内存是否满,在满的情况下淘汰引用串和。
    2. 随机置换算法(PRA):
      1. 原理:所选择的被淘汰的页面将是内存里随机的一个页面。
      2. 过程:当发生页面置换时,查询页面是否在内存中,在的话直接显示页面,否则检验内存是否满,在满的情况下随机淘汰一个内存中页面,不满的情况下直接插入内存空位。
    3. 先进先出置换算法(FIFO):
      1. 原理:所选择的被淘汰页面是最先进入内存的页面。
      2. 过程:当发生页面置换时,查询页面是否在内存中,在的话直接显示页面,否则查询内存是否满,在满的情况下淘汰一个内存中最早进入的页面,不满的情况下直接插入内存空位。
    4. 最近最久未使用置换算法(LRU):
      1. 原理:所选择的被淘汰的页面是最近最久未使用的页面。
      2. 过程:当发生页面置换时,查询页面是否在内存中,在的话直接显示页面,否则查询内存是否满,在满的情况下淘汰一个内存中最近最久未使用的页面,不满的情况下直接插入内存空位。
    5. 简单时钟置换算法(First-Clock):
      1. 原理:所选择的被淘汰的页面是访问位为0的页面。
      2. 过程:当发生页面置换时,查询页面是否在内存中,在的话直接显示页面,否则查询内存是否满,在满的情况下,依次访问内存中的页面访问位,为1则置为0访问下一位;为0则淘汰页面,将新插入的页面访问位置为1,指针指向下一位。在不满的情况下直接插入内存空位,且页面访问位置为1,指针指向内存下一位.
    6. 改进型时钟置换算法(Second-Clock):
      1. 原理:所选择的最佳被淘汰页面是访问位为0,修改位也为0的页面。
      2. 过程:当发生页面置换时,首先判断是否为修改程序:如果是则修改插入页面的修改位为1否则为0,接着查询页面是否在内存中,在的话直接显示页面,否则查询内存是否满,在满的情况下,
          1. 依次访问内存页面的修改位和访问位,如果修改位与访问位同时为0则淘汰该页面,同时将新插入的页面访问位置为1,指针指向下一位;
          2. 遍历后不存在同时为0的情况,那么重新依次查找访问位为0修改位为1的页面,如果指针位置的访问位为1,则将其置为0,为0则淘汰该页面,并且将新插入的页面访问位置为1,指针指向下一位.
          3. 这时遍历如果还未找到,则再次重新遍历,按1)与2)的过程就能找到合适页面,淘汰该页面并且将新插入的页面访问位置为1。
    7. 用于测试的引用串
      1. 原理:引用串的关键在于如何模拟程序的局部性。
      2. 过程:
        1. 确定虚拟内存的尺寸P,工作面的起始位置p,工作面中包含的页数e,工作面移动率m,以及一个范围在0和1之间的值t
        2. 生成m个取值范围在p和p+e间的随机数,并记录到引用串中
        3. 生成一个随机数r,0 ≤ r ≤ 1, 如果r < t,则为p生成一个新值,否则p=(p+1)modP
        4. 如果想继续加大引用串的长度,请返回第二步,否则结束
  2. 算法流程图

  3. 结果分析
    1. FIFO算法是否比随机替换算法优越?LRU算法比FIFO 算法优越 多少?
  4. FIFO算法在总体上比随机替换算法优先,但是在某些特定的引用串的情况下,随即替换算法比FIFO算法更加优越,LRU算法的置换次数是FIFO置换算法低一些,所以效率提升不是很明显,但是在具体实现的过程中,却需要付出很大的代价,即为每页配置的寄存器,或者一个栈,这样计算下来,LRU置换算法在现实中的应用价值很低,其只存在理论上的在置换次数方面的优越性。

    1. LRU算法和最优算法有何差距?
  5. LRU算法与最优算法的差距体现在两个方面,一个是磁环效率方面的差距,最优置换算法的置换次数大概是LRU置换算法低较多,但是在某些引用串时,LRU的置换效率与OPT的差别不大;另一个方面是在其具体实现的时候,需要付出的硬件代价比较大。

    1. Clock算法和LRU算法有何差距?
  6. Clock置换算法与LRU置换算法的差距主要体现在置换效率方面,其置换次数比LRU略多,差距并不大;而在具体实现方面,Clock实现的硬件代价比LRU小,因为Clock只需要一位标志位,而LRU需要配置一个和页面数相等的n位寄存器。

     

  7. 实验问题
  8. 主要解决页面替换算法的逻辑和相关数据结构的适配。

  9. 心得体会
  10. 本次实验完成了对页面替换算法的实现,分别用了不同的数据结构诸如链表和队列实现相关的模拟,程序流程相互比较类似,实现思路比较清楚。

  11. GitHub链接:https://github.com/waguyu/waguyu/blob/master/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9Flab4%E6%BA%90%E7%A0%81%E5%8F%8A%E6%88%AA%E5%9B%BE.docx

Y86 Tools (Student Distribution) Copyright (c) 2002, R. Bryant and D. O Hallaron, All rights reserved. May not be used, modified, or copied without permission. This directory contains the student distribution of the Y86 tools. It is a proper subset of the master distribution, minus the solution files found in the master distribution. yas Y86 assembler yis Y86 instruction (ISA) simulator hcl2c HCL to C translator ssim SEQ simulator ssim+ SEQ+ simulator psim PIPE simulator y86-code/ Examples programs and and benchmark testing scripts ptest/ Scripts for detailed automated regression testing 1. Building the Y86 tools The Y86 simulators can be configured to support TTY and GUI interfaces. A simulator running in TTY mode prints all information about its run-time behavior on the terminal. Hard to understand what s going on, but useful for automated testing, and doesn t require any special installation features. A simulator running in GUI mode uses a fancy graphical user interface. Nice for visualizing and debugging, but requires installation of Tcl/Tk on your system. To build the Y86 tools, perform the following steps: NOTE: If your instructor prepared this distribution for you, then you can skip Step 1 and proceed directly to Step 2. The Makefile will already have the proper values for GUIMODE, TKLIBS, and TKINC for your system. Step 1. Decide whether you want the TTY or GUI form of the simulators, and then modify ./Makefile in this directory accordingly. (The changes you make to the variables in this Makefile will override the values already assigned in the Makefiles in the seq and pipe directories.) Building the GUI simulators: If you have Tcl/Tk installed on your system, then you can build the GUI form by initializing the GUIMODE, TKLIBS, and TKINC variables, as appropriate for your system. (The default values work for Linux systems.) Assigning GUIMODE=-DHAS_GUI causes the necessary GUI support code in the simulator sources to be included. The TKLIBS variable tells gcc where to look for the libtcl.so and libtk.so libraries. And the TKINC variable tells gcc where to find the tcl.h and tk.h header files. Building the TTY simulators: If you don t have Tcl/Tk installed on your system, then build the TTY form by commenting out all three of these variables (GUIMODE, TKLIBS, and TKINC) in the Makefile. Step 2: Once you ve modified the Makefile to build either the GUI or TTY form, then you can construct the entire set of Y86 tools by typing unix> make clean; make 2. Files Makefile Builds the Y86 tools README This file misc/ Source files for the Y86 assembler yas, the Y86 instruction simulator yis, and the isa.c file that is used by the -t option of the processor simulators to check the results against the ISA simulation. seq/ Code for the SEQ and SEQ+ simulators. Contains HCL files for labs and homework problems that involve modifying SEQ. pipe/ Code for the PIPE simulator. Contains HCL files for labs and homework problems that involve modifying PIPE. y86-code/ Example .ys files from CS:APP and scripts for conducting automated benchmark teseting of the new processor designs. ptest/ Automated regression testing scripts for testing processor designs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值