实验三存储管理指导

上传人:大米 文档编号:460977181 上传时间:2023-07-17 格式:DOC 页数:10 大小:78.50KB
返回 下载 相关 举报
实验三存储管理指导_第1页
第1页 / 共10页
实验三存储管理指导_第2页
第2页 / 共10页
实验三存储管理指导_第3页
第3页 / 共10页
实验三存储管理指导_第4页
第4页 / 共10页
实验三存储管理指导_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《实验三存储管理指导》由会员分享,可在线阅读,更多相关《实验三存储管理指导(10页珍藏版)》请在金锄头文库上搜索。

1、实验三存储管理指导 实验内容 设计一个虚拟存储区和内存工作区, 并使用下列算法计算访问命中率.( 1)进先出的算法( FIFO)( 2)最近最少使用的算法(LRU)( 3)最佳淘汰算法 (OPT)( 4)最少访问页面算法 (LFU)( 5)最近最不经常使用算法(NUR)命中率 =(1- 页面失效次数 )/ 页地址流长度程序设计本实验的程序设计基本上按照实验内容进行。即首先用srand()和 rand() 函数定义和产生指令序列, 然后将指令序列变换成相应的页地址流,并针对不同的算法计算出相应的命中率。相关定义如下:1.数据结构(1) 页面类型typedef structint pn,pfn,c

2、ounter,time;pl-type;其中 pn 为页号 ,pfn为面号 , counter为一个周期内访问该页面的次数, time为访问时间 .(2) 页面控制结构pfc-structint pn,pfn;struct pfc_struct *next;typedefstruct pfc_struct pfc_type;pfc_type pfc_structtotal_vp,*freepf_head,*busypf_head;pfc_type *busypf_tail;其中 pfctotal_vp定义用户进程虚页控制结构,*freepf_head为空页面头的指针,*busypf_head为

3、忙页面头的指针,*busypf_tail为忙页面尾的指针.2函数定义( 1) Void initialize( ):初始化函数 , 给每个相关的页面赋值.( 2) Void FIFO( ): 计算使用 FIFO 算法时的命中率 .( 3) Void LRU( ): 计算使用 LRU算法时的命中率 .( 4) Void OPT( ): 计算使用 OPT算法时的命中率 .( 5) Void LFU( ): 计算使用 LFU算法时的命中率 .( 6) Void NUR( ): 计算使用 NUR算法时的命中率 .3. 变量定义(1)int atotal_instruction:(2)int paget

4、otal_instruction:(3)int offsettotal_instruction:指令流数据组.每条指令所属的页号.每页装入10 条指令后取模运算页号偏移值.(4)int total_pf:用户进程的内存页面数.(5)int disaffect:页面失效次数.4. 程序参考源码及结果#include #include #include #define TRUE 1#define FALSE 0#define INVALID -1#define NUL 0#define total_instruction 320 /*指令流长 */#define total_vp 32/*虚页长

5、*/#define clear_period 50/*清零周期 */typedef struct/*页面结构 */int pn,pfn,counter,time;pl_type;pl_type pltotal_vp; /*页面结构数组*/struct pfc_struct/*页面控制结构*/int pn,pfn;struct pfc_struct *next;typedef struct pfc_struct pfc_type;pfc_type pfctotal_vp,*freepf_head,*busypf_head,*busypf_tail; int diseffect,atotal_in

6、struction;int pagetotal_instruction, offsettotal_instruction;void initialize();void FIFO();void LRU();void OPT();void LFU();void NUR();int main()int S,i;srand(int)getpid();S=(int)rand()%390;for(i=0;itotal_instruction;i+=1)/*产生指令队列*/ai=S;ai+1=ai+1;ai+2=(int)rand()%390;ai+3=ai+2+1;/*/*/*/*任选一指令访问点顺序执行

7、一条指令执行前地址指令m */执行后地址指令*/*/*/S=(int)rand()%390;for(i=0;itotal_instruction;i+)/*将指令序列变换成页地址流*/pagei=ai/10;offseti=ai%10;for(i=4;i=32;i+)/*用户内存工作区从4 个页面到32 个页面 */printf(%2d page frames,i);FIFO(i);LRU(i);OPT(i);LFU(i);NUR(i);printf(n);return 0;void FIFO(total_pf)/*FIFO(Firstin First out)ALGORITHM*/int t

8、otal_pf;/*用户进程的内存页面数*/int i;pfc_type *p, *t;initialize(total_pf); /* busypf_head=busypf_tail=NUL;/*初始化相关页面控制用数据结构忙页面队列头,对列尾链接*/*/for(i=0;inext;plbusypf_head-pn.pfn=INVALID; /*释放忙页面队列中的第一个页面*/freepf_head=busypf_head;freepf_head-next=NUL;busypf_head=p;p=freepf_head-next; /*按方式调新页面入内存页面*/freepf_head-ne

9、xt=NUL;freepf_head-pn=pagei;plpagei.pfn=freepf_head-pfn;if(busypf_tail=NUL)busypf_head=busypf_tail=freepf_head;elsebusypf_tail-next=freepf_head;busypf_tail=freepf_head;freepf_head=p;printf(FIFO:%6.4F,1-(float)diseffect/320);void LRU(total_pf)int total_pf;int min,minj,i,j,present_time;initialize(tota

10、l_pf);present_time=0;for(i=0;itotal_instruction;i+)if(plpagei.pfn=INVALID)/*页面失效*/diseffect+;if(freepf_head=NUL) /*无空闲页面*/min=32767;for(j=0;jplj.time&plj.pfn!=INVALID)min=plj.time;minj=j;freepf_head=&pfcplminj.pfn;plminj.pfn=INVALID;plminj.time=-1;freepf_head-next=NUL;plpagei.pfn=freepf_head-pfn;plpagei.time=present_time;freepf_head=freepf_head-next;elseplpagei.time=present_time;present_time+;printf(LRU:%6.4f,1-(float)diseffect/320);void NUR(total_pf)int total_pf;int i,j,dp,cont_flag,old_dp;pfc_type *t;initialize(total_pf);dp=0;for(i=0;itotal_instruction;i+)if(plpagei.pfn=INVALID) /*

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 工作计划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号