欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    虚拟存储器管理方案实验报告.doc

    • 资源ID:3033570       资源大小:185.89KB        全文页数:22页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    虚拟存储器管理方案实验报告.doc

    淮海工学院计算机科学系实验报告书课程名: 操 作 系 统 题 目: 虚拟存储器管理 页面置换算法模拟实验 班 级: 学 号: 姓 名: 评语:成绩: 指导教师: 批阅时间: 年 月 日一、实验目的与要求1. 目的:请求页式虚存管理是常用的虚拟存储管理方案之一。通过请求页式虚存管理中对页面置换算法的模拟,有助于理解虚拟存储技术的特点,并加深对请求页式虚存管理的页面调度算法的理解。2. 要求:本实验要求使用C语言编程模拟一个拥有若干个虚页的进程在给定的若干个实页中运行、并在缺页中断发生时分别使用FIFO和LRU算法进行页面置换的情形。其中虚页的个数可以事先给定(例如10个),对这些虚页访问的页地址流(其长度可以事先给定,例如20次虚页访问)可以由程序随机产生,也可以事先保存在文件中。要求程序运行时屏幕能显示出置换过程中的状态信息并输出访问结束时的页面命中率。程序应允许通过为该进程分配不同的实页数,来比较两种置换算法的稳定性。二、实验说明1设计中虚页和实页的表示本设计利用C语言的结构体来描述虚页和实页的结构。pnpfntimepnpfnnext 虚页结构 实页结构在虚页结构中,pn代表虚页号,因为共10个虚页,所以pn的取值范围是09。pfn代表实页号,当一虚页未装入实页时,此项值为-1;当该虚页已装入某一实页时,此项值为所装入的实页的实页号pfn。time项在FIFO算法中不使用,在LRU中用来存放对该虚页的最近访问时间。在实页结构中中,pn代表虚页号,表示pn所代表的虚页目前正放在此实页中。pfn代表实页号,取值范围(0n-1)由动态指派的实页数n所决定。next是一个指向实页结构体的指针,用于多个实页以链表形式组织起来,关于实页链表的组织详见下面第4点。2关于缺页次数的统计为计算命中率,需要统计在20次的虚页访问中命中的次数。为此,程序应设置一个计数器count,来统计虚页命中发生的次数。每当所访问的虚页的pfn项值不为-1,表示此虚页已被装入某实页内,此虚页被命中,count加1。最终命中率=count/20*100%。3LRU算法中“最近最久未用”页面的确定为了能找到“最近最久未用”的虚页面,程序中可引入一个时间计数器countime,每当要访问一个虚页面时,countime的值加1,然后将所要访问的虚页的time项值设置为增值后的当前countime值,表示该虚页的最后一次被访问时间。当LRU算法需要置换时,从所有已分配实页的虚页中找出time值为最小的虚页就是“最近最久未用”的虚页面,应该将它置换出去。4算法中实页的组织因为能分配的实页数n是在程序运行时由用户动态指派的,所以应使用链表组织动态产生的多个实页。为了调度算法实现的方便,可以考虑引入free和busy两个链表:free链表用于组织未分配出去的实页,首指针为free_head,初始时n个实页都处于free链表中;busy链表用于组织已分配出去的实页,首指针为busy_head,尾指针为busy_tail,初始值都为null。当所要访问的一个虚页不在实页中时,将产生缺页中断。此时若free链表不为空,就取下链表首指针所指的实页,并分配给该虚页。若free链表为空,则说明n个实页已全部分配出去,此时应进行页面置换:对于FIFO算法要将busy_head 所指的实页从busy链表中取下,分配给该虚页,然后再将该实页插入到busy链表尾部;对于LRU算法则要从所有已分配实页的虚页中找出time值为最小的虚页,将该虚页从装载它的那个实页中置换出去,并在该实页中装入当前正要访问的虚页。三、程序流程图三个模块的流程图1登录模块开 始打开w_input窗口关闭w_main窗口2参数输入模块开 始打开w_accept窗口关闭w_input窗口输入当前磁头位置输入各磁道号位置开 始打开w_input窗口关闭w_accept窗口调用FCFS算法显示结果调用SSTF算法显示结果调用SCAN算法显示结果调用CSCAN算法 显示结果3算法实现模块四、主要程序清单模块之间的调用关系登录模块参数输入模块算法实现模块#include<stdio.h>#include<stdlib.h>#include<time.h>int producerand(int remainder);void initprocess();void chosedisplace();struct linknode * fifo(struct linknode *head,int randcount);void Optimal(struct linknode*head,int randprocess);struct linknode* LRU(struct linknode *head,int randprocess);struct linknode* initlink();void choicestey();int allotment(struct linknode *head);bool checkfifooptimal(struct linknode* head,int checkpage);void recover(struct linknode *head,int randprocess);void recovermemory(); int process1020;/数组的横坐标为进程序列,纵坐标为每个进程的页号 int processallotment6;/存储每个进程已经分配的块数 int finishp6;/标志进程是否完成(1完成0不完成) int finishprocess=0;/进程完成的个数 int findpage6;/每个进程命中的个数 struct linknode *plinkhead6;struct linknode *plink6;int memoryallotment6; int stey=0;struct linknodestruct linknode *linkper;/空链表的前驱指针 int page;int processpage;int used;int memorypage; struct linknode *linknext;/空链表的后继指针 struct linknode *processper;/进程的前去指针struct linknode *processnext;/进程的后继指针 ;int main()struct linknode *head=initlink(); initprocess(); choicestey(); int re=allotment(head); if(re=0)printf("内存分配出现问题。");system("pause");chosedisplace();recovermemory();system("pause");void recovermemory()int n=0;printf("是否回收全部已分配的内存空间?n回收输入 1,不回收输入2n");scanf("%d",&n);if(n=1)for(int i=1;i<=5;i+)recover(plinkheadi,i);if(n=2)printf("您这么做会浪费内存空间"); void recover(struct linknode *head,int randprocess)while(head!=0)head->used=0;head=head->processnext;void choicestey() printf("请选择置换算法n"); printf("1 表示FIFOn2 表示Optimaln3 表示LRUn"); bool flag=true;while(flag)scanf("%d",&stey); switch(stey)case 1:printf("您选择的是FIFO替换算法n");flag=false; break;case 2:printf("您选择的是Optimal替换算法n");flag=false;break;case 3:printf("您选择的是LRU替换算法n");flag=false;break;default :printf("输入错误,请重新输入n"); void chosedisplace()/选择置换算法struct linknode *head;int randcount;/进程序号 bool find;while(finishprocess<5) randcount=producerand(5);while(processallotmentrandcount<processrandcount0)find=false;head=plinkheadrandcount;if(stey=1|stey=2)find=checkfifooptimal(head,processrandcountprocessallotmentrandcount+1);if(find=true)findpagerandcount+;if(find=false)/如果在链表中没找到当前的页数 switch(stey)case 1:plinkheadrandcount=fifo(plinkheadrandcount,randcount);break;case 2: Optimal(plinkheadrandcount,randcount); break; case 3: plinkheadrandcount=LRU(plinkheadrandcount,randcount); break; processallotmentrandcount+; if(finishprandcount=0) finishprocess+;finishprandcount=1; struct linknode *p;printf("进程执行完后内存分配情况:n");for(int i=1;i<=5;i+) p=plinkheadi;while(p!=0)printf("内存块号:%dt进程号:%dt号:%dn",p->memorypage,p->processpage,p->page);p=p->processnext; for(int i=1;i<=5;i+) printf("进程序列 %d",i); printf("t进程总页数为%dt命中页为%dt",processi0,findpagei);printf("进程的命中率为%.0f%n",(float)findpagei)*100/processi0); bool checkfifooptimal(struct linknode* head,int checkpage)while(head!=0)/遍历链表查单当前页是否在链表中 if(head->page=checkpage) return true;elsehead=head->processnext;return false;struct linknode* LRU(struct linknode *head,int randprocess) struct linknode *bhead; bhead=head; while(head->processnext!=0) if(head->page=processrandprocessprocessallotmentrandprocess+1) break; else head=head->processnext; if(head->page!=processrandprocessprocessallotmentrandprocess+1)/没找到 bhead->page=processrandprocessprocessallotmentrandprocess+1; head->processnext=bhead; bhead->processper=head; bhead=bhead->processnext; bhead->processper=0; head=head->processnext; head->processnext=0; plinkrandprocess=plinkrandprocess->processnext; return bhead; else/找到了 if(head=bhead)/头 head->processper=plinkrandprocess; plinkrandprocess->processnext=head; plinkrandprocess=plinkrandprocess->processnext; head=head->processnext; head->processper=0; plinkrandprocess->processnext=0; findpagerandprocess+; return head; else if(head->processnext=0)/尾 findpagerandprocess+; return bhead; else/中间 head->processnext->processper=head->processper; head->processper->processnext=head->processnext; head->processnext=0; head->processper=plinkrandprocess; plinkrandprocess->processnext=head; plinkrandprocess=plinkrandprocess->processnext; findpagerandprocess+; return bhead; void Optimal(struct linknode*head,int randprocess)struct linknode *maxp;maxp=head;int max=1,i;while(head!=0)for(i=processallotmentrandprocess+1;i<=processrandprocess0;i+)if(processrandprocessi=head->page)break;if(i>max)max=i;maxp=head;head=head->processnext;maxp->page=processrandprocessprocessallotmentrandprocess+1;struct linknode* fifo(struct linknode*head,int randprocess)struct linknode*phead;/改变后的头指针phead=head; head->page=processrandprocessprocessallotmentrandprocess+1;while(head->processnext!=0)head=head->processnext;head->processnext=phead;phead->processper=head;phead=phead->processnext;head=head->processnext;head->processnext=0;phead->processper=0;return phead;int allotment(struct linknode *head)/为进程分配内存 int allotsum=0;/已经分配完进程的个数 int randprocess;/当前要分配内存的进程标号 bool boolallot6;for(int i=1;i<6;i+)processallotmenti=0;boolalloti=false;memoryallotmenti=0;while(allotsum<=4)/判断是否全部进程都分配完 randprocess=producerand(5);/随即生成进程标号 if(boolallotrandprocess=false)/判断进程是否分配完 if(head->used=0)if(processallotmentrandprocess=0)plinkheadrandprocess=head;plinkrandprocess=head;plinkrandprocess->processper=0;plinkrandprocess->processnext=0;head->processpage=randprocess;plinkrandprocess->page=processrandprocess1;head->used=1;printf("内存块号:%dt进程号:%dt页号:%dn",head->memorypage,head->processpage,head->page);head=head-> linknext;memoryallotmentrandprocess+;findpagerandprocess+; elsebool checksame=checkfifooptimal(plinkheadrandprocess,processrandprocessprocessallotmentrandprocess+1);if(checksame=false)head->used=1; head->processnext=0; head->processper=plinkrandprocess; plinkrandprocess-> processnext=head; head->processpage=randprocess; head->page=processrandprocessprocessallotmentrandprocess+1;plinkrandprocess=plinkrandprocess->processnext;printf("内存块号:%dt进程号:%dt页号:%dn",head->memorypage,head->processpage,head->page);head=head->linknext;memoryallotmentrandprocess+;findpagerandprocess+; else if(stey=3) plinkheadrandprocess=LRU(plinkheadrandprocess,randprocess); else findpagerandprocess+; processallotmentrandprocess+;elseprintf("进程%d分配失败n",randprocess);return 0; if(head=0)printf("进程%d分配失败n",randprocess);return 0; if(processallotmentrandprocess=processrandprocess0)printf("进程%d分配成功n",randprocess);allotsum+;boolallotrandprocess=true;finishprocess+;finishprandprocess=1; else if(memoryallotmentrandprocess=4)allotsum+;boolallotrandprocess=true;printf("进程%d分配成功n",randprocess); struct linknode *p; printf("初始内存分配情况:n"); for(int i=1;i<=5;i+) p=plinkheadi;while(p!=0)printf("内存块号:%dt进程号:%dt号:%dn",p->memorypage,p->processpage,p->page);p=p->processnext; return 1;void initprocess()int perrandcount;for(int i=1;i<=5;i+)/假设有5个进程 perrandcount=producerand(10);/每个进程产生的页面个数 processi0=perrandcount;for(int j=1;j<=perrandcount;j+)processij=producerand(20);/为第i个进程产生0到19之间的页面顺序 for(int i=1;i<=5;i+)printf("进程序列 %d",i);printf("该进程的调用页号顺序"); for(int j=1;j<=processi0;j+)printf("%d ",processij);printf("n");for(int i=1;i<=5;i+) findpagei=0;/为进程是否完成做初始化finishpi=0; /为每一个进程的命中数初始化 struct linknode* initlink()/初始化内存链表 struct linknode *p,*q,*head; p=new linknode; head=q=p; p->used=0; p->processnext=NULL; p->processper=NULL; p->linkper=q; p->linknext=NULL; p->memorypage=1; p->page=-1; for(int i=1;i<=20;i+)/假设内存有20个大小相等的空闲块 p=new linknode;p->used=0;p->processnext=NULL; p->processper=NULL; p->linkper=q; q->linknext=p; p->linknext=NULL; p->page=-1; p->memorypage=i+1; q=q->linknext; return head;int producerand(int remainder)/产生随机数 int randcount;randcount=(rand()+(unsigned)time(NULL)%remainder+1;return randcount;五、程序运行结果六、实验体会这次的实验,我们了解到了请求页式虚存管理是常用的虚拟存储管理方案之一。通过请求页式虚存管理中对页面置换算法的模拟,有助于理解虚拟存储技术的特点,并加深对请求页式虚存管理的页面调度算法的理解。这次实验让我们对计算机操作系统的学习更进一步,我受益匪浅。

    注意事项

    本文(虚拟存储器管理方案实验报告.doc)为本站会员(小**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开