请求调页存储管理方式的模拟

合集下载

请求分页存储管理(虚拟存储)

请求分页存储管理(虚拟存储)

任务四、请求分页存储管理(虚拟存储)一、实验目的通过请求分页存储管理的设计,让学生了解虚拟存储器的概念和实现方法。

进行运行时不需要将所有的页面都调入内存,只需将部分调入内存,即可运行,在运行的过程中若要访问的页面不在内存时,则需求有请求调入的功能将其调入。

假如此时若内存没有空白物理块,则通过页面置换的功能将一个老的不用的页面淘汰出来,其中淘汰的算法有多种。

二、实验内容模拟仿真请求分页调度算法,其中淘汰的算法可选下列其一1、先进先出算法2、最近最久算法3、CLOCK算法三、实验代码#include<iostream>#include<vector>using namespace std;int n;typedef struct Queue{int time;int data;struct Queue *next;}Queue,*QueuePtr;typedef struct {QueuePtr front;QueuePtr rear;}LinkQueue;//fifo=======================================void InitQueue(LinkQueue &Q);void FiFoEnQueueRear(LinkQueue &Q,int e,vector<int> &v);void FiFoDeQueueFront(LinkQueue &Q);inline void PrintQueue(LinkQueue &Q);void FiFoFiFoDoQueueEarly(LinkQueue &Q,int a,vector<int> &v);void FiFoDoQueue(LinkQueue &Q,int a,vector<int> &v);inline int PanDuan(LinkQueue &Q,int a);inline int YeMianCount(LinkQueue &Q);void fifo();//lru=============================================void InitQueue(LinkQueue &Q);void EnQueueMid(LinkQueue &Q,int e,QueuePtr p,vector<int> &v);void EnQueueTheFist(LinkQueue &Q,int e);void PrintQueue(LinkQueue &Q);//void ZhiZhenInit(int n);void DoQueueEarly(LinkQueue &Q,int e,vector<int> &v);void EnQueueRear(LinkQueue &Q,int e,QueuePtr p,vector<int> &v);//void DeQueueFront(LinkQueue &Q);QueuePtr ZhiZhen(LinkQueue &Q,int e);void EnQueue(LinkQueue &Q,int e,vector<int> &v);//void DeQueue(LinkQueue &Q,QueuePtr p);int PanDuan(LinkQueue &Q,int a);int YeMianCount(LinkQueue &Q);void lru();QueuePtr OptimalZhiZhen(LinkQueue &Q,int e);//求出需要置换的页面的上一个页面的位置void EnQueue(LinkQueue &Q,int e,vector<int> &v,int i,vector<int> &vc);inline int YeMianCount(LinkQueue &Q);//使用内敛函数,提高性能inline int Destance(vector<int> &v,int i);inline void SubbDestance(LinkQueue &Q);//=================================================int main(){int k;for(;;){cout<<"请选择!"<<endl;cout<<"1——FiFo算法"<<endl;cout<<"2——LRU算法"<<endl;cout<<"0——退出"<<endl;cin>>k;if(k==0)break;else{switch(k){case 1:fifo();break;case 2:lru();break;default:cout<<" 请从以上的选择中选择一个选项!!"<<endl;}}}}//fifo========================================void InitQueue(LinkQueue &Q){Q.front=Q.rear=(QueuePtr)malloc(sizeof(Queue));if(!Q.front)cout<<"initqueue worng!"<<endl;Q.front->next=NULL;//return OK;}void FiFoEnQueueRear(LinkQueue &Q,int e,vector<int> &v){ QueuePtr p;p=(QueuePtr)malloc(sizeof(Queue));if(!p)cout<<"cannot malloc EnQueue of the p"<<endl;p->data=e;p->next=NULL;Q.rear->next=p;Q.rear=p;v.push_back(e);//cout<<p->data;//return OK;}void FiFoDeQueueFront(LinkQueue &Q){QueuePtr p;if(Q.front==Q.rear)cout<<"the Queue is empty,cannot delete !!"<<endl;p=Q.front->next;Q.front->next=p->next;free(p);if(Q.rear==p)Q.rear=Q.front;//return OK}void PrintQueue(LinkQueue &Q){QueuePtr p;if(Q.front==Q.rear)cout<<"the Queue is empty,cannot print!"<<endl;p=Q.front;for(p=Q.front;p->next!=NULL;p=p->next){cout<<p->next->data<<" ";}cout<<endl;//retrun OK;}void FiFoFiFoDoQueueEarly(LinkQueue &Q,int a,vector<int> &v){ QueuePtr p;int count=0;//设置标志位,记录重复的个数。

模拟请求页式存储管理中硬件的地址转换和缺页中断处理

模拟请求页式存储管理中硬件的地址转换和缺页中断处理

一.实验内容模拟请求页式存储管理中硬件的地址转换和缺页中断处理 二.实验原理装入新页置换旧页时,若旧页在执行中没有被修改过,则不必将该页重写磁盘。

因此,页表中增加是否修改过的标志,执行“存”指令和“写”指令时将对应的修改标志置成“1”三.要求及方法:① 设计一个地址转换程序来模拟硬件的地址转换和缺页中断。

当访问的页在主存时则形成绝对地址,但不去模拟指令的执行,可以输出转换后的绝对地址来表示一条指令已执行完成。

当访问的页不在主存中时,则输出“*页号”来表示硬件产生了一次缺页中断。

模拟地址转换流程见图1。

② 编制一个FIFO 页面调度程序;FIFO 页面调度算法总是先调出作业中最先进入主存中的哪一页。

因此可以用一个数组来表示(或构成)页号队列。

数组中每个元素是该作业已在主存中的页面号,假定分配给作业的页架数为m ,且该作业开始的m 页已装入主存,则数组可由m 个元素构成。

P[0],P[1],P[2],…,P[m-1]它们的初值为P[0]:=0,P[1]:=1,P[2]:=2,…,P[m-1]:=m-1用一指针K 指示当要调入新页时应调出的页在数组中的位置,K 的初值为“0”,当产生缺页中断后,操作系统总是选择P[K]所指出的页面调出,然后执行:P[K]:=要装入的新页页号 K :=(k+1)mod m在实验中不必实际地启动磁盘执行调出一页和装入一页的工作,而用输出“OUT 调出的页号”和“IN 要装入的新页页号”来模拟一次调出和装入过程,模拟程序的流程图见附图1。

按流程控制过程如下:提示:输入指令的页号和页内偏移和是否存指令⎩⎨⎧ 0 1非存指令存指令,若d 为-1则结束,否则进入流程控制过程,得P1和d,查表在主存时,绝对地址=P1×1024+d③假定主存中页架大小为1024个字节,现有一个共7页的作业,其副本已在磁盘上。

系统为该作业分配了4个页架,且该作业的第0页至第3页已装入内存,其余3页未装入主四.主要代码及其说明#include <stdio.h>#include <string.h>#include <stdlib.h>#define M 1024#define R 4typedef struct _PTable{int Number; //页号int Flag; //标志int Fnum; //页架号int Mflag; //修改标志int Position; //该页存放在磁盘上的位置}PTable;//初始化PTable ptable[]={{0, 1, 5, 0, 11},{1, 1, 8, 0, 12},{2, 1, 9, 0, 13},{3, 1, 1, 0, 21},{4, 0, -1, 0, 22},{5, 0, -1, 0, 23},{6, 0, -1, 0, 121},};void menu();int change(char op,int number,int add);void display();int p[]={0,1,2,3},k=0;void main(void){int number,add,n;char op;while(n){display();fflush( stdin );printf("输入:操作页号页内地址(存指令用\"c\"代表)\n");scanf("%c %d %d",&op,&number,&add);change(op,number,add);printf("\"是否继续! (按1 继续按任意键结束)\"\n");scanf("%d",&n);system( "cls ");if(n==1)continue;elsebreak;}}void menu(){printf("操作码\t页号\t页内地址页架标志修改标志出入状态绝对地址(L)\n");}int change(char op,int number,int add){bool flag1=false;bool flag2=false;int i,address,cout,temp;;for(i=0;i<7;i++){if(op=='c'){ptable[number].Mflag=1;}if(ptable[i].Number==number && ptable[i].Flag==1){address=ptable[i].Fnum*M+add;flag1=true;}if(ptable[i].Number==number && ptable[i].Flag==0){cout=i;temp = p[k]; //将要出的页if(ptable[temp].Mflag==1){flag2=true;}//修改页表ptable[number].Flag=1; //修改新页标志ptable[number].Fnum=ptable[temp].Fnum; //修改新页页架address=ptable[number].Fnum*M+add;ptable[temp].Flag=0; //修改旧页ptable[temp].Fnum=-1; //修改页架ptable[temp].Mflag=0; //修改修改标志p[k]=number; //新页k=(k+1)%R;}}menu();if(flag1)printf("%c\t %d\t %d\t %d\t %d\t %d\t 无出入\t%d\n",op,number,add,ptable[number].Fnum,ptable[number].Flag,ptable[number].Mflag,address);else if(flag2)printf("%c\t *%d\t %d\t %d\t %d\t%d OUT:%d,IN:%d %d\n",op,number,add,number,ptable[number].Fnum,ptable[number].Flag,ptable[number].Mflag,temp,number,address);elseprintf("%c\t *%d\t %d\t %d\t %d\t %d\t IN%d\t %d\n",op,number,add,ptable[number].Fnum,ptable[number].Flag,ptable[number].Mflag,number,address);return 0;}void display(){int i;printf("********当前页表中的状态*********\n");printf("页号标志页架修标志\n");for(i=0;i<7;i++){printf("%d\t%d\t%d\t%d\n",ptable[i].Number,ptable[i].Flag,ptable[i].Fnum,ptable[i]. Mflag);}printf("当前主存中的页号为: ");for(i=0;i<4;i++){printf("%d ",p[i]);}printf("\n*********************************\n");}五,实验截图。

模拟请求页式存储管理中硬件的地址转换和缺页中断,并用先进先出调度算法(FIFO)处理缺页中断

模拟请求页式存储管理中硬件的地址转换和缺页中断,并用先进先出调度算法(FIFO)处理缺页中断

实验报告课程名称操作系统原理实验名称虚拟页式管理姓名学号专业班级网络实验日期成绩指导教师赵安科(①实验目的②实验原理③主要仪器设备④实验内容与步骤⑤实验数据记录与处理⑥实验结果与分析⑦问题建议)实验二模拟请求页式存储管理中硬件的地址转换和缺页中断,并用先进先出调度算法(FIFO)处理缺页中断1.内容:模拟请求页式存储管理中硬件的地址转换和缺页中断处理2.思想:装入新页置换旧页时,若旧页在执行中没有被修改过,则不必将该页重写磁盘。

因此,页表中增加是否修改过的标志,执行“存”指令和“写”指令时将对应的修改标志置成“1”3.要求及方法:①设计一个地址转换程序来模拟硬件的地址转换和缺页中断。

当访问的页在主存时则形成绝对地址,但不去模拟指令的执行,可以输出转换后的绝对地址来表示一条指令已执行完成。

当访问的页不在主存中时,则输出“*页号”来表示硬件产生了一次缺页中断。

模拟地址转换流程见图1。

②编制一个FIFO页面调度程序;FIFO页面调度算法总是先调出作业中最先进入主存中的哪一页。

因此可以用一个数组来表示(或构成)页号队列。

数组中每个元素是该作业已在主存中的页面号,假定分配给作业的页架数为m,且该作业开始的m页已装入主存,则数组可由m个元素构成。

P[0],P[1],P[2],…,P[m-1]它们的初值为P[0]:=0,P[1]:=1,P[2]:=2,…,P[m-1]:=m-1用一指针K指示当要调入新页时应调出的页在数组中的位置,K的初值为“0”,当产生缺页中断后,操作系统总是选择P[K]所指出的页面调出,然后执行:P[K]:=要装入的新页页号 K :=(k+1)mod m在实验中不必实际地启动磁盘执行调出一页和装入一页的工作,而用输出“OUT 调出的页号”和“IN 要装入的新页页号”来模拟一次调出和装入过程,模拟程序的流程图见附图1。

按流程控制过程如下:提示:输入指令的页号和页内偏移和是否存指令⎩⎨⎧0 1非存指令存指令,若d 为-1则结束,否则进入流程控制过程,得P 1和d ,查表在主存时,绝对地址=P 1×1024+d③ 假定主存中页架大小为1024个字节,现有一个共7页的作业,其副本已在磁盘上。

模拟请求页式管理

模拟请求页式管理

目录一、设计目的1二、设计内容1三、设计原理2四、算法实现4五、流程图4六、源程序4七、运行示例及结果分析12八、心得体会12九、参考资料12模拟请求页式管理一、设计目的1.通过模拟实现请求页式存储管理的几种基本页面置换算法,了解虚拟存储技术的特点.2。

通过对页面、页表、地址转换和页面置换过程的模拟,加深对请求调页系统的原理和是实验过程的理解。

3.掌握虚拟存储请求页式存储管理中几种基本页面置换算法的基本思想和实现过程,并比较它们的效率.二、设计内容通过随机数产生一个指令序列,共320条指令.指令的地址按下述原则生成:① 50% 的指令是顺序执行的;② 25%的指令是均匀分布在前地址部分;③ 25% 的指令是均匀分布在后地址部分。

具体的实施方法是:①在[0,319] 的指令地址之间随机选取一起点 m;②顺序执行一条指令;③在前地址[0,m+1]中随机选取一条指令并执行,该指令的地址为 m′;④顺序执行一条指令,其地址为 m′+1;⑤在后地址[m′+2,319] 中随机选取一条指令并执行;⑥重复上述步骤②~⑤,直到执行 320 次指令。

将指令序列变换成为页地址流设:①页面大小为 1K;②用户内存容量为 4 页到 32 页;③用户虚存容量为 32K 。

在用户虚存中,按每 K 存放 10 条指令排列虚存地址,即 320 条指令在虚存中的存放方式为:第 0 条 ~ 第 9 条指令为第 0 页 ( 对应虚存地址为[0,9]);第 10 条~第 19 条指令为第 1 页 ( 对应虚存地址为[10,19] );┇┇第 310 条~第 319 条指令为第 31 页(对应虚存地址为 [310,319])。

按以上方式,用户指令可组成 32 页。

计算并输出下述各种算法在不同内存容量下的命中率.先进先出的算法 (FIFO);最近最久未使用算法(LRU);最佳访问算法(OPT);三、设计原理㈠FIFO页面置换算法⑴原理简述①在分配内存页面数(AP)小于进程页面数(PP)时,当然是最先运行的AP个页面放入内存.②这时有需要处理新的页面,则将原来内存中的AP个页面最先进入的调出(是以称为FIFO),然后将新页面放入.③以后如果再有新页面需要调入,则都按⑵的规则进行.算法特点:所使用的内存页面构成一个队列。

操作系统实验4-请求分页存储管理模拟实验

操作系统实验4-请求分页存储管理模拟实验

实验四请求分页存储管理模拟实验一:实验目得通过对页面、页表、地址转换与页面置换过程得模拟,加深对请求分页存储管理系统得原理与实现技术得理解.二:实验内容假设每个页面可以存放10条指令,分配给进程得存储块数为4。

用C语言或Pascal语言模拟一进程得执行过程。

设该进程共有320条指令,地址空间为32个页面,运行前所有页面均没有调入内存。

模拟运行时,如果所访问得指令已经在内存,则显示其物理地址,并转下一条指令;如果所访问得指令还未装入内存,则发生缺页,此时需要记录缺页产生次数,并将相应页面调入内存,如果4个内存块已满,则需要进行页面置换。

最后显示其物理地址,并转下一条指令。

在所有指令执行完毕后,显示进程运行过程中得缺页次数与缺页率.页面置换算法:分别采用OPT、FIFO、LRU三种算法。

进程中得指令访问次序按如下原则生成:50%得指令就是顺序执行得。

25%得指令就是均匀分布在低地址部分.25%得指令就是均匀分布在高地址部分.三:实验类别分页存储管理四:实验类型模拟实验五:主要仪器计算机六:结果OPT:LRU:FIFO:七:程序# i nclude 〈stdio 、h 〉# incl ude 〈stdlib 、h 〉# include 〈conio 、h># def ine blockn um 4//页面尺寸大小int m; //程序计数器,用来记录按次序执行得指令对应得页号s ta ti c in t num [320]; //用来存储320条指令typedef s truct BLOCK //声明一种新类型—-物理块类型{ﻩint pagenum; //页号ﻩint acces sed; //访问量,其值表示多久未被访问}BLOCK ;BLOCK bl ock [bl ocknum ]; //定义一大小为8得物理块数组void init () //程序初始化函数,对bl ock 初始化{for (int i=0;i <blo cknum;i++)block[i]、pagenum=—1;block[i]、accessed=0;ﻩm=0;}}int pageExist(int curpage)//查找物理块中页面就是否存在,寻找该页面curpage就是否在内存块block中,若在,返回块号{ﻩfor(int i=0;i<blocknum; i++)ﻩ{ﻩﻩif(block[i]、pagenum == curpage )ﻩﻩreturn i; //在内存块block中,返回块号ﻩ}return -1;}int findSpace()//查找就是否有空闲物理块,寻找空闲块block,返回其块号{for(int i=0;i<blocknum;i++)ﻩ{if(block[i]、pagenum==-1)ﻩreturn i;//找到了空闲得block,返回块号}ﻩreturn -1;}int findReplace()//查找应予置换得页面{ﻩint pos = 0;ﻩfor(int i=0;i〈blocknum;i++){if(block[i]、accessed 〉block[pos]、accessed)ﻩpos = i; //找到应该置换页面,返回BLOCK中位置ﻩ}return pos;}void display()//显示物理块中得页面号{ﻩﻩfor(int i=0; i〈blocknum; i++)ﻩ{ﻩif(block[i]、pagenum != -1)ﻩ{ﻩﻩprintf(” %02d ",block[i]、pagenum);ﻩﻩﻩprintf("%p |”,&block[i]、pagenum);ﻩﻩ}printf("\n");}void randam()//产生320条随机数,显示并存储到num[320]{int flag=0;printf(”请为一进程输入起始执行指令得序号(0~320):\n”);ﻩscanf("%d",&m);//用户决定得起始执行指令printf("******进程中指令访问次序如下:(由随机数产生)*******\n");for(int i=0;i〈320;i++){//进程中得320条指令访问次序得生成ﻩﻩnum[i]=m;//当前执行得指令数,ﻩﻩif(flag%2==0)ﻩm=++m%320;//顺序执行下一条指令ﻩﻩif(flag==1)ﻩﻩm=rand()%(m-1);//通过随机数,跳转到低地址部分[0,m—1]得一条指令处,设其序号为m1if(flag==3)ﻩﻩm=m+1+(rand()%(320-(m+1)));//通过随机数,跳转到高地址部分[m1+2,319]得一条指令处,设其序号为m2ﻩﻩflag=++flag%4;ﻩprintf(” %03d”,num[i]);//输出格式:3位数ﻩﻩif((i+1)%10==0)//控制换行,每个页面可以存放10条指令,共32个页面ﻩprintf(”\n”);}}void pagestring() //显示调用得页面序列,求出此进程按次序执行得各指令所在得页面号并显示输出{for(int i=0;i〈320;i++)ﻩ{printf(”%02d",num[i]/10);//输出格式:2位数if((i+1)%10==0)//控制换行,每个页面可以存放10条指令,共32个页面ﻩﻩprintf("\n”);}}void OPT() //最佳替换算法{ﻩint n=0;//记录缺页次数int exist,space,position;ﻩintcurpage;//当前指令得页面号ﻩfor(int i=0;i<320;i++)ﻩ{ﻩm=num[i];ﻩcurpage=m/10;ﻩﻩexist=pageExist(curpage);ﻩif(exist==-1)ﻩﻩ{ //当前指令得页面号不在物理块中space=findSpace();ﻩﻩif(space != -1)ﻩﻩ{//当前存在空闲得物理块ﻩﻩblock[space]、pagenum= curpage;//将此页面调入内存ﻩﻩﻩdisplay();//显示物理块中得页面号ﻩﻩn++;//缺页次数+1ﻩ}ﻩﻩelseﻩﻩ{ //当前不存在空闲得物理块,需要进行页面置换for(intk=0;k<blocknum;k++)ﻩﻩﻩﻩ{for(int j=i;j〈320;j++)ﻩ{//找到在最长(未来)时间内不再被访问得页面ﻩﻩﻩﻩif(block[k]、pagenum!= num[j]/10)ﻩﻩﻩ{ﻩﻩblock[k]、accessed = 1000;ﻩﻩﻩ} //将来不会被访问,设置为一个很大数ﻩﻩﻩelseﻩﻩﻩ{ //将来会被访问,访问量设为jﻩﻩﻩblock[k]、accessed = j;ﻩﻩﻩﻩﻩbreak;ﻩﻩﻩﻩ}ﻩﻩﻩ}ﻩ}ﻩposition = findReplace();//找到被置换得页面,淘汰ﻩblock[position]、pagenum = curpage;// 将新页面调入display();ﻩﻩn++; //缺页次数+1ﻩ}}ﻩ}ﻩprintf(”缺页次数:%d\n",n);printf("缺页率:%f%%\n",(n/320、0)*100);}void LRU() //最近最久未使用算法{int n=0;//记录缺页次数ﻩint exist,space,position ;ﻩint curpage;//当前指令得页面号ﻩfor(int i=0;i<320;i++)ﻩ{ﻩm=num[i];ﻩﻩcurpage=m/10;ﻩexist = pageExist(curpage);ﻩif(exist==-1)ﻩﻩ{ //当前指令得页面号不在物理块中space = findSpace();ﻩﻩif(space!= —1)ﻩ{ //当前存在空闲得物理块ﻩﻩblock[space]、pagenum = curpage;//将此页面调入内存ﻩﻩdisplay();//显示物理块中得页面号ﻩn++;//缺页次数+1ﻩﻩ}else{ //当前不存在空闲得物理块,需要进行页面置换ﻩﻩposition= findReplace();ﻩblock[position]、pagenum = curpage;ﻩﻩdisplay();ﻩn++;//缺页次数+1ﻩ}ﻩﻩ}elseﻩﻩblock[exist]、accessed = -1;//恢复存在得并刚访问过得BLOCK中页面accessed为-1for(int j=0; j<blocknum; j++)ﻩﻩ{//其余得accessed++ﻩﻩblock[j]、accessed++;}ﻩ}printf("缺页次数:%d\n”,n);ﻩprintf("缺页率:%f%%\n",(n/320、0)*100);}void FIFO(){int n=0;//记录缺页次数int exist,space,position ;ﻩ int curpage;//当前指令得页面号int blockpointer=-1;for(int i=0;i<320;i++)ﻩ{ﻩ m=num[i];curpage=m/10;ﻩexist = pageExist(curpage);ﻩ if(exist==-1){//当前指令得页面号不在物理块中ﻩ space = findSpace();ﻩﻩif(space !=-1)ﻩ { //当前存在空闲得物理块ﻩﻩ blockpointer++;ﻩﻩﻩblock[space]、pagenum=curpage; //将此页面调入内存ﻩ n++;//缺页次数+1ﻩﻩﻩ display();//显示物理块中得页面号ﻩ}ﻩ elseﻩ { //没有空闲物理块,进行置换ﻩﻩﻩﻩposition = (++blockpointer)%4;ﻩ block[position]、pagenum = curpage;//将此页面调入内存ﻩﻩn++;ﻩﻩ display();ﻩ}ﻩ }}printf("缺页次数:%d\n",n);printf("缺页率:%f%%\n",(n/320、0)*100);}void main(){ﻩint choice;ﻩprintf("************请求分页存储管理模拟系统*************\n");ﻩrandam();printf("************此进程得页面调用序列如下**************\n”);pagestring();ﻩwhile(choice!= 4){ﻩﻩprintf("********1:OPT 2:LRU 3:FIFO 4:退出*********\n”);ﻩprintf("请选择一种页面置换算法:”);ﻩscanf("%d",&choice);ﻩinit();ﻩswitch(choice)ﻩ{ﻩcase 1:ﻩﻩﻩprintf(”最佳置换算法OPT:\n");ﻩprintf("页面号物理地址页面号物理地址页面号物理地址页面号物理地址\n");ﻩﻩﻩOPT();ﻩbreak;ﻩcase 2:ﻩﻩprintf("最近最久未使用置换算法LRU:\n");ﻩprintf("页面号物理地址页面号物理地址页面号物理地址页面号物理地址\n");ﻩLRU();ﻩﻩﻩbreak;ﻩﻩcase 3:ﻩprintf("先进先出置换算法FIFO:\n");ﻩprintf("页面号物理地址页面号物理地址页面号物理地址页面号物理地址\n");FIFO();ﻩﻩbreak;ﻩ}}}。

请求页式存储管理中常用页面置换算法模拟

请求页式存储管理中常用页面置换算法模拟

计算机操作系统实验报告济南大学信息科学与技术学院2013年xx月xx日一、实验概述1. 实验名称请求页式存储管理中常用页面置换算法管理2. 实验目的(1)了解内存分页管理策略(2)掌握调页策略(3)掌握一般常用的调度算法(4)学会各种存储分配算法的实现方法。

(5)了解页面大小和内存实际容量对命中率的影响3. 实验内容(1)采用页式分配存储方案,通过分别计算不同算法的命中率来比较算法的优劣,同时也考虑页面大小及内存实际容量对命中率的影响;(2)实现OPT 算法(最优置换算法) 、LRU 算法(Least Recently) 、FIFO 算法(First IN First Out)的模拟;(3)使用某种编程语言模拟页面置换算法。

二、实验环境C语言三、实验过程1. 设计思路和流程图选择置换算法,先输入所有页面号,为系统分配物理块,依次进行置换2. 算法实现(1)OPT基本思想:是用一维数组page[pSIZE]存储页面号序列,memery[mSIZE]是存储装入物理块中的页面。

数组next[mSIZE]记录物理块中对应页面的最后访问时间。

每当发生缺页时,就从物理块中找出最后访问时间最大的页面,调出该页,换入所缺的页面。

(2)FIFO基本思想:是用队列存储内存中的页面,队列的特点是先进先出,与该算法是一致的,所以每当发生缺页时,就从队头删除一页,而从队尾加入缺页。

或者借助辅助数组time[mSIZE]记录物理块中对应页面的进入时间,每次需要置换时换出进入时间最小的页面。

(3)LRU基本思想:是用一维数组page[pSIZE]存储页面号序列,memery[mSIZE]是存储装入物理块中的页面。

数组flag[10]标记页面的访问时间。

每当使用页面时,刷新访问时间。

发生缺页时,就从物理块中页面标记最小的一页,调出该页,换入所缺的页面。

3.源程序并附上注释#include <stdio.h>#include <stdlib.h>/*全局变量*/int mSIZE; /*物理块数*/int pSIZE; /*页面号引用串个数*/static int memery[10]={0}; /*物理块中的页号*/static int page[100]={0}; /*页面号引用串*/static int temp[100][10]={0}; /*辅助数组*//*置换算法函数*/void FIFO();void LRU();void OPT();/*辅助函数*/void print(unsigned int t);void designBy();void download();void mDelay(unsigned int Delay);/*主函数*/void main(){int i,k,code;system("color 0A");designBy();printf("┃请按任意键进行初始化操作... ┃\n");printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");printf(" >>>");getch();system("cls");system("color 0B");printf("请输入物理块的个数(M<=10):");scanf("%d",&mSIZE);printf("请输入页面号引用串的个数(P<=100):");scanf("%d",&pSIZE);puts("请依次输入页面号引用串(连续输入,无需隔开):");for(i=0;i<pSIZE;i++)scanf("%1d",&page[i]);download();system("cls");system("color 0E");do{puts("输入的页面号引用串为:");for(k=0;k<=(pSIZE-1)/20;k++){for(i=20*k;(i<pSIZE)&&(i<20*(k+1));i++){if(((i+1)%20==0)||(((i+1)%20)&&(i==pSIZE-1)))printf("%d\n",page[i]);elseprintf("%d ",page[i]);}}printf("* * * * * * * * * * * * * * * * * * * * * * *\n");printf("* 请选择页面置换算法:\t\t\t *\n");printf("* ----------------------------------------- *\n");printf("* 1.先进先出(FIFO) 2.最近最久未使用(LRU) *\n");printf("* 3.最佳(OPT) 4.退出*\n");printf("* * * * * * * * * * * * * * * * * * * * * * *\n");printf("请选择操作:[ ]\b\b");scanf("%d",&code);switch(code){case 1:FIFO();break;case 2:LRU();break;case 3:OPT();break;case 4:system("cls");system("color 0A");designBy(); /*显示设计者信息后退出*/printf("┃谢谢使用页面置换算法演示器! 正版授权㊣┃\n");printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");exit(0);default:printf("输入错误,请重新输入:");}printf("按任意键重新选择置换算法:>>>");getch();system("cls");}while (code!=4);getch();}/*载入数据*/void download(){int i;system("color 0D");printf("╔════════════╗\n");printf("║正在载入数据,请稍候!!!║\n");printf("╚════════════╝\n");printf("Loading...\n");printf(" O");for(i=0;i<51;i++)printf("\b");for(i=0;i<50;i++){mDelay((pSIZE+mSIZE)/2);printf(">");}printf("\nFinish.\n载入成功,按任意键进入置换算法选择界面:>>>");getch();}/*设置延迟*/void mDelay(unsigned int Delay){unsigned int i;for(;Delay>0;Delay--){for(i=0;i<124;i++){printf(" \b");}}}/*显示设计者信息*/void designBy(){printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");printf("┃课题三:页面置换算法┃\n");printf("┃学号:20111214034 ┃\n");printf("┃姓名:韩瑶┃\n");printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━┫\n"); }void print(unsigned int t){int i,j,k,l;int flag;for(k=0;k<=(pSIZE-1)/20;k++){for(i=20*k;(i<pSIZE)&&(i<20*(k+1));i++){if(((i+1)%20==0)||(((i+1)%20)&&(i==pSIZE-1)))printf("%d\n",page[i]);elseprintf("%d ",page[i]);}for(j=0;j<mSIZE;j++){for(i=20*k;(i<mSIZE+20*k)&&(i<pSIZE);i++){if(i>=j)printf(" |%d|",temp[i][j]);elseprintf(" | |");}for(i=mSIZE+20*k;(i<pSIZE)&&(i<20*(k+1));i++){for(flag=0,l=0;l<mSIZE;l++)if(temp[i][l]==temp[i-1][l])flag++;if(flag==mSIZE)/*页面在物理块中*/printf(" ");elseprintf(" |%d|",temp[i][j]);}/*每行显示20个*/if(i%20==0)continue;printf("\n");}}printf("----------------------------------------\n");printf("缺页次数:%d\t\t",t+mSIZE);printf("缺页率:%d/%d\n",t+mSIZE,pSIZE);printf("置换次数:%d\t\t",t);printf("访问命中率:%d%%\n",(pSIZE-(t+mSIZE))*100/pSIZE);printf("----------------------------------------\n");}/*计算过程延迟*/void compute(){int i;printf("正在进行相关计算,请稍候");for(i=1;i<20;i++){mDelay(15);if(i%4==0)printf("\b\b\b\b\b\b \b\b\b\b\b\b");elseprintf("Θ");}for(i=0;i++<30;printf("\b"));for(i=0;i++<30;printf(" "));for(i=0;i++<30;printf("\b"));}/*先进先出页面置换算法*/void FIFO(){int memery[10]={0};int time[10]={0}; /*记录进入物理块的时间*/int i,j,k,m;int max=0; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];time[i]=i;for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;}if(k==mSIZE) /*如果不在物理块中*/{count++;/*计算换出页*/max=time[0]<time[1]?0:1;for(m=2;m<mSIZE;m++)if(time[m]<time[max])max=m;memery[max]=page[i];time[max]=i; /*记录该页进入物理块的时间*/for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else{for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}/*最近最久未使用置换算法*/void LRU(){int memery[10]={0};int flag[10]={0}; /*记录页面的访问时间*/int i,j,k,m;int max=0; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];flag[i]=i;for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;elseflag[j]=i; /*刷新该页的访问时间*/ }if(k==mSIZE) /*如果不在物理块中*/{count++;/*计算换出页*/max=flag[0]<flag[1]?0:1;for(m=2;m<mSIZE;m++)if(flag[m]<flag[max])max=m;memery[max]=page[i];flag[max]=i; /*记录该页的访问时间*/for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else{for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}/*最佳置换算法*/void OPT(){int memery[10]={0};int next[10]={0}; /*记录下一次访问时间*/int i,j,k,l,m;int max; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;}if(k==mSIZE) /*如果不在物理块中*/{count++;/*得到物理快中各页下一次访问时间*/for(m=0;m<mSIZE;m++){for(l=i+1;l<pSIZE;l++)if(memery[m]==page[l])break;next[m]=l;}/*计算换出页*/max=next[0]>=next[1]?0:1;for(m=2;m<mSIZE;m++)if(next[m]>next[max])max=m;/*下一次访问时间都为pSIZE,则置换物理块中第一个*/memery[max]=page[i];for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else {for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}6. 程序运行时的初值和运行结果1. 按任意键进行初始化:2. 载入数据:3. 进入置换算法选择界面:4.运算中延迟操作5.三种算法演示结果:四、实验体会掌握了一般的调度算法,了解了页面大小和内存实际容量对命中率的影响(英文版)Two regulations promulgated for implementation is in the party in power for a long time and the rule of law conditions, the implementation of comprehensive strictly strategic plan, implementation in accordance with the rules and discipline to manage the party, strengthen inner-party supervision of major initiatives. The two regulations supporting each other, the < code > adhere to a positive advocate, focusing on morality is of Party members and Party leading cadres can see, enough to get a high standard; < rule > around the party discipline, disciplinary ruler requirements, listed as "negative list, focusing on vertical gauge, draw the party organizations and Party members do not touch the" bottom line ". Here, the main from four square face two party rules of interpretation: the first part introduces two party Revised regulations the necessity and the revision process; the second part is the interpretation of the two fundamental principles of the revision of laws and regulations in the party; the third part introduces two party regulations modified the main changes and needs to grasp several key problems; the fourth part on how to grasp the implementation of the two regulations of the party. < code > and < Regulations > revised the necessity and revisedhistory of the CPC Central Committee the amendment to the Chinese Communist Party members and leading cadres honest politics several guidelines > and < Chinese Communist Party discipline and Punishment Regulations > column 1 by 2015 to strengthen party laws and regulations focus. Two party regulations revision work lasted a Years, pooling the wisdom of the whole party, ideological consensus, draw historical experience, respect for the wisdom of our predecessors, which reflects the unity of inheritance and innovation; follow the correct direction, grasp the limited goals, adhere to the party's leadership, to solve the masses of the people reflect a focus on the problem. The new revision of the < code > and < rule >, reflects the party's 18 and the eighth session of the third, the spirit of the fourth plenary session, reflecting the experience of studying and implementing the General Secretary Xi Jinping series of important speech, reflects the party's eighteen years comprehensive strictly practice. (a) revised two regulations of the party need of < the ICAC guidelines > in < in 1997 Leaders as members of the Communist Party of China clean politics certain criteria (Trial) > based on revised, the promulgation and implementation of January 2010, to strengthen the construction of the contingent of leading cadres play animportant role. But with the party to manage the party strictly administering the deepening, has not been able to fully meet the actual needs. Content is too complicated, "eight prohibition, 52 are not allowed to" hard to remember, and also difficult to put into practice; the second is concisely positive advocated by the lack of prohibited provisions excessive, no autonomy requirements; the third is banned terms and discipline law, both with the party discipline, disciplinary regulations repeat and Criminal law and other laws and regulations repeat; the fourth is to "clean" the theme is not prominent, not for the existing problems, and is narrow, only needle of county-level leading cadres above. < rule > is in 1997 < Chinese Communist Party disciplinary cases (Trial) > based on revision, in December 2003 the promulgation and implementation, to strengthen the construction of the party play very important role. Along with the development of the situation, which many provisions have been unable to fully meet the comprehensive strictly administering the practice needs. One is Ji law, more than half of the provisions and criminal law and other countries laws and regulations Repetition; two is the political discipline regulations is not prominent, not specific, for violation of the party constitution, damage theauthority of Party Constitution of misconduct lack necessary and serious responsibility to pursue; third is the main discipline for the leading cadres, does not cover all Party members. Based on the above situation, need to < the criterion of a clean and honest administration > and < rule > the two is likely to be more relevant regulations first amendment. By revising, really put the authority of Party discipline, the seriousness in the party tree and call up the majority of Party members and cadres of the party constitution of party compasses party consciousness. (II) two party regulations revision process the Central Committee of the Communist Party of China attaches great importance to two regulations revision . Xi Jinping, general books recorded in the Fifth Plenary Session of the eighth session of the Central Commission for Discipline Inspection, on the revised regulations < > made clear instructions. According to the central deployment, the Central Commission for Discipline Inspection from 2014 under six months begin study two regulations revision. The Standing Committee of the Central Commission for Discipline Inspection 4 review revised. Comrade Wang Qishan 14 times held a special meeting to study two regulations revision, amendment clarifies the direction, major issues of principle, path and target,respectively held a forum will listen to part of the province (area) secretary of the Party committee, Secretary of the Discipline Inspection Commission, part of the central ministries and state organs DepartmentThe first party committee is mainly responsible for people, views of experts and scholars and grassroots party organizations and Party members. Approved by the Central Committee of the Communist Party of China, on 7 September 2015, the general office of the Central Committee of the Party issued a notice to solicit the provinces (autonomous regions, municipalities) Party, the central ministries and commissions, state ministries and commissions of the Party (party), the General Political Department of the military, every 3 people organization of Party of two regulations revision opinion. Central Commission for Discipline Inspection of extensive solicitation of opinions, careful study, attracting, formed a revised sent reviewers. In October 8 and October 12, Central Committee Political Bureau Standing Committee and the Political Bureau of the Central Committee After consideration of the two regulations revised draft. On October 18, the Central Committee of the Communist Party of China formally issued two regulations. Can say, two laws amendment concentrated thewisdom of the whole party, embodies the party. Second, < code > and < Regulations > revision of the basic principles of two party regulations revision work and implement the party's eighteen, ten eight plenary, the spirit of the Fourth Plenary Session of the Eleventh Central Committee and General Secretary Xi Jinping important instructions on the revised < low political criterion > and < Regulations >, highlighting the ruling party characteristics, serious discipline, the discipline quite in front of the law, based on the current, a long-term, advance as a whole, with Bu Xiuding independent < rule > and < rule >. Main principle is: first, adhere to the party constitution to follow. The constitution about discipline and self-discipline required specific, awaken the party constitution of party compasses party consciousness, maintaining the authority of the constitution. General Secretary Xi Jinping pointed out that "no rules, no side round. Party constitution is the fundamental law, the party must follow the general rules. In early 2015 held the eighth session of the Central Commission for Discipline Inspection Fifth Plenary Session of the 16th Central Committee, Xi Jinping again pointed out that constitution is the party must follow the general rules, but also the general rules." the revision of the< code > and < rule > is Method in adhere to the regulations established for the purpose of combining rule of virtue is to adhere to the party constitution as a fundamental to follow, the constitution authority set up, wake up the party constitution and party rules the sense of discipline, the party constitution about discipline and self-discipline specific requirements. 4 second is to adhere to in accordance with the regulations governing the party and the party. The Party of rule of virtue "de", mainly refers to the party's ideals and beliefs, excellent traditional style. The revised the < code > closely linked to the "self-discipline", insisting on the positive initiative, for all members, highlight the "vital few", emphasized self-discipline, focusing on the morality, and the majority of Party members and the ideological and moral standards. The revised < > Ji method separately, Ji, Ji Yan to Method, as a "negative list", emphasizing the heteronomy, focusing on vertical gauge. Is this one high and one low, a positive reaction, the strict party discipline and practice results transformation for the integration of the whole party to observe moral and discipline requirements, for the majority of Party members and cadres provides benchmarking and ruler. Third, insist on to. In view of the problems existing in theparty at the present stage, the main problems of Party members and cadres in the aspect of self-discipline and abide by the discipline to make clearly defined, especially the party's eighteen years strict political discipline and political rules, organization and discipline and to implement the central eight provisions of the spirit against the four winds and other requirements into Disciplinary provisions. Not one pace reachs the designated position, focusing on in line with reality, pragmatic and effective. After the revision of major changes, major changes in the < code > and < rule > modified and needs to grasp several key problems (a) < code > < code > adhere to according to regulations governing the party and party with morals in combination, for at the present stage, the leadership of the party members and cadres and Party members in existing main problems of self-discipline, put forward principles, requirements and specifications, showing Communists noble moral pursuit, reflected at all times and in all over the world ethics from high from low 5 common requirements. One is closely linked to the "self-discipline", removal and no direct relation to the provisions of . the second is adhere to a positive advocate, "eight prohibition" 52 are not allowed to "about the content of the" negative list moved into synchronizationamendment < cases >. Three is for all the party members, will apply object from the leadership of the party members and cadres to expand to all Party members, fully embodies the comprehensive strictly required. The fourth is prominent key minority, seize the leadership of the party members and cadres is the key, and put forward higher requirements than the ordinary Party members. Five is to simplify, and strive to achieve concise, easy to understand, easy to remember. The revised < code > is the ruling Party since the first insists on a positive advocate forAll Party members and the self-discipline norms, moral declaration issued to all members of the party and the National People's solemn commitment. > < criterion of a clean and honest administration consists of 4 parts, 18, more than 3600 words. After the revision of the < code >, a total of eight, 281 words, including lead, specification and Party member cadre clean fingered self-discipline norms, etc. Part 3 members low-cost clean and self-discipline, the main contents can be summarized as "four must" "eight code". Lead part, reiterated on ideal and faith, fundamental purpose, the fine traditions and work style, noble sentiments, such as "four must" the principle of requirements, strong tone of self-discipline, The higher request for 6 andsupervised tenet, the foothold in permanent Bao the party's advanced nature and purity, to reflect the revised standards requirements. Members of self-discipline norms around the party members how to correctly treat and deal with the "public and private", "cheap and rot" thrifty and extravagance "bitter music", put forward the "four norms". Party leader cadre clean fingered self-discipline norms for the leadership of the party members and cadres of the "vital few", around the "clean politics", from civil servant of the color, the exercise of power, moral integrity, a good family tradition and other aspects of the leadership of the party members and cadres of the "four norms" < > < norm norm. "The Party member's self-discipline norms" and "party members and leading cadre clean fingered self-discipline norms," a total of eight, collectively referred to as the "eight". "Four must" and "eight" of the content from the party constitution and Party's several generation of leaders, especially Xi Jinping, general secretary of the important discussion, refer to the "three discipline and eight points for attention" statements, and reference some embody the Chinese nation excellent traditional culture essence of epigrams. (2) the revised regulations, the main changes in the revised Regulations > to fully adapt to thestrictly requirements, reflects the according to the regulations governing the law of recognition of deepening, the realization of the discipline construction and Jin Ju. < rule > is party a ruler, members of the basic line and follow. And the majority of Party members and cadres of Party organizations at all levels should adhere to the bottom line of thinking, fear discipline, hold the bottom line, as a preventive measure, to keep the party's advanced nature and purity. 1, respect for the constitution, refinement and discipline. Revised < rule > from comprehensive comb physical constitution began, the party constitution and other regulations of the Party of Party organizations and Party discipline requirements refinement, clearly defined in violation of the party constitution will be in accordance with regulations to give the corresponding disciplinary action. The original 10 categories of misconduct, integration specification for political discipline, discipline, honesty and discipline masses Ji Law and discipline and discipline and other six categories, the content of < rule > real return to Party discipline, for the majority of Party members and listed a "negative list. 7 2, highlighting the political discipline and political rules. > < Regulations according to the stage of the discipline of outstandingperformance, emphasizing political discipline and political rules, organization and discipline, in opposition to the party's leadership and the party's basic theory, basic line, basic program and basic experience, the basic requirement of behavior made prescribed punishment, increase the cliques, against the organization such as violation of the provisions, to ensure that the central government decrees and the Party of centralized and unified. 3, adhere to strict discipline in the law and discipline In front, Ji separated. Revised < Regulations > adhere to the problem oriented, do Ji separated. Any national law existing content, will not repeat the provisions, the total removal of 79 and criminal law, repeat the content of the public security management punishment law, and other laws and regulations. In the general reiterated that party organizations and Party members must conscientiously accept the party's discipline, die van comply with national laws and regulations; at the same time, to investigate violations of Party members and even criminal behavior of Party discipline and responsibility, > < Regulations distinguish five different conditions, with special provisions were made provisions, so as to realize the connection of Party discipline and state law. 4, reflect Wind building and anti-corruptionstruggle of the latest achievements. < rule > the party's eighteen years implement the spirit of the central provisions of the eight, against the requirements of the "four winds" and transformation for disciplinary provisions, reflecting the style construction is always on the road, not a gust of wind. In the fight against corruption out of new problems, increase the trading rights, the use of authority relatives profit and other disciplinary terms. Prominent discipline of the masses, the new against the interests of the masses and ignore the demands of the masses and other disciplinary terms and make provisions of the disposition and the destruction of the party's close ties with the masses.Discipline to protect the party's purpose. 8 of these regulations, a total of three series, Chapter 15, 178, more than 24000 words, after the revision of the regulations a total of 3 series, Chapter 11, 133, 17000 words, divided into "general" and "special provisions" and "Supplementary Provisions" Part 3. Among them, add, delete, modify the provisions of the proportion of up to nearly 90%. 1, the general general is divided into five chapters. The first chapter to the regulations of the guiding ideology, principles and scope of application of the provisions, highlight the strengthening ofthe party constitution consciousness, maintenance the authority of Party Constitution, increase the party organizations and Party members must abide by the party constitution, Yan Centralized centralized, would examine at all levels of the amended provisions implementing and maintaining Party discipline, and consciously accept the party discipline, exemplary compliance with national laws and regulations. The second chapter of discipline concept, disciplinary action types and effects of the regulations, will be a serious warning from the original a year for a year and a half; increase the Party Congress representative, by leaving the party above (including leave probation) punishment, the party organization should be terminated its representative qualification provisions. The third chapter of the disciplinary rules of use prescribed in the discipline rectifying process, non convergence, not close hand classified as severely or heavier punishment. "Discipline straighten "At least eighteen years of five years, these five years is to pay close attention to the provisions of the central eight implementation and anti -" four winds ". The fourth chapter on suspicion of illegal party disciplinary distinguish five different conditions, with special provisions were madeprovisions, to achieve effective convergence of Party and country 9 method. < rule > the provisions of Article 27, Party organizations in the disciplinary review found that party members have committed embezzlement, bribery, dereliction of duty dereliction of duty and other criminal law act is suspected of committing a crime shall give cancel party posts, probation or expelled from the party. The second is < Regulations > Article 28 the provisions of Party organizations in the disciplinary review But found that party members are stipulated in the criminal law, although not involved in a crime shall be investigated for Party discipline and responsibility should be depending on the specific circumstances shall be given a warning until expelled punishment. This situation and a difference is that the former regulation behavior has been suspected of a crime, the feeling is quite strict, and the latter for the behavior not involving crime, only the objective performance of the provisions of the criminal code of behavior, but the plot is a crime to slightly. < Regulations > the 29 provisions, Party organizations in the discipline review found that party members and other illegal behavior, affect the party's image, the damage to the party, the state and the people's interests, we should depend on the situation。

请求页式存储管理中常用页面置换算法模拟

请求页式存储管理中常用页面置换算法模拟

信息工程学院实验报告课程名称:操作系统Array实验项目名称:请求页式存储管理中常用页面置换算法模拟实验时间:班级姓名:学号:一、实验目的:1.了解内存分页管理策略2.掌握调页策略3.掌握一般常用的调度算法4.学会各种存储分配算法的实现方法。

5.了解页面大小和内存实际容量对命中率的影响。

二、实验环境:PC机、windows2000 操作系统、VC++6.0三、实验要求:本实验要求4学时完成。

1.采用页式分配存储方案,通过分别计算不同算法的命中率来比较算法的优劣,同时也考虑页面大小及内存实际容量对命中率的影响;2.实现OPT 算法 (最优置换算法)、LRU 算法 (Least Recently)、 FIFO 算法 (First IN FirstOut)的模拟;3.会使用某种编程语言。

实验前应复习实验中所涉及的理论知识和算法,针对实验要求完成基本代码编写、实验中认真调试所编代码并进行必要的测试、记录并分析实验结果。

实验后认真书写符合规范格式的实验报告,按时上交。

四、实验内容和步骤:1.编写程序,实现请求页式存储管理中常用页面置换算法LRU算法的模拟。

要求屏幕显示LRU算法的性能分析表、缺页中断次数以及缺页率。

2.在上机环境中输入程序,调试,编译。

3.设计输入数据,写出程序的执行结果。

4.根据具体实验要求,填写好实验报告。

五、实验结果及分析:实验结果截图如下:利用一个特殊的栈来保存当前使用的各个页面的页面号。

当进程访问某页面时,便将该页面的页面号从栈中移出,将它压入栈顶。

因此,栈顶始终是最新被访问页面的编号,栈底是最近最久未被使用的页面号。

当访问第5个数据“5”时发生了缺页,此时1是最近最久未被访问的页,应将它置换出去。

同理可得,调入队列为:1 2 3 4 5 6 7 1 3 2 0 5,缺页次数为12次,缺页率为80%。

六、实验心得:本次实验实现了对请求页式存储管理中常用页面置换算法LRU算法的模拟。

请求页式虚拟存储管理(FIFO算法)

请求页式虚拟存储管理(FIFO算法)
if(page_table[j].state==0)
{
//内存有空闲
if(bno.Length()<5)
{
page_table[j].state=1;
page_table[j].block_no=i+10;
bno.InQueue(page_table[j].no);
bno.Traverse(Write);
{
a[0]=loc[i]/1024; //计算出的页号
a[1]=loc[i]%1024; //计算出的页内偏移量
//找到页表中的该页
for( j=0;j<64;j++)
{
if(page_table[j].no==a[0]) break;
}
//该页在内存
if(page_table[j].state==1)
{
bno.Traverse(Write); //输出队列里的页面
cout<<endl;
cout<<page_table[j].no<<' '<<page_table[j].state<<' '<<page_table[j].block_no<<endl<<endl; //输出页表信息
}
//该页不在内存,FIFO算法
cout<<endl;
cout<<page_table[j].no<<''<<page_table[j].state<<' '<<page_table[j].block_no<<endl<<endl;

请求页式存储管理的模拟实现_参考代码_

请求页式存储管理的模拟实现_参考代码_
break;
case REQUEST_EXECUTE:
ptr_pageTabIt->count++;
if(!(ptr_pageTabIt->proType&EXECUTABLE)){
do_error(ERROR_EXECUTE_DENY);
return ;
}
info.Format(_T("执行成功\n"));
out->SetSel(-1, -1);
out->ReplaceSel(info);
if(pageTable[page].modified){
info.Format(_T("有修改,写回至外存\n"));
out->SetSel(-1, -1);
out->ReplaceSel(info);
do_page_out(&pageTable[page]);
do_init(){
int i,j;
srand(time(NULL));
for(i=0;i<PAGE_SUM;i++){
pageTable[i].pageNum=i;
pageTable[i].effective=mFALSE;
pageTable[i].modified=mFALSE;
pageTable[i].count=0;
ptr_pageTabIt->blockNum=j;//修改调入页的页表项
ptr_pageTabIt->effective=TRUE;
ptr_pageTabIt->count=0;
info.Format(_T("页面替换成功\n"));

存储管理常用页面置换算法模拟实验

存储管理常用页面置换算法模拟实验

实验目地通过模拟实现请求页式存储管理地几种基本页面置换算法,了解虚拟存储技术地特点,掌握虚拟存储请求页式存储管理中几种基本页面置换算法地基本思想和实现过程,并比较它们地效率.文档收集自网络,仅用于个人学习实验内容设计一个虚拟存储区和内存工作区,并使用下述算法计算访问命中率.1、最佳淘汰算法(OPT)2、先进先出地算法(FIFO )3、最近最久未使用算法(LRU )4、最不经常使用算法(LFU )5、最近未使用算法(NUR )命中率=1-页面失效次数/页地址流长度实验准备本实验地程序设计基本上按照实验内容进行.即首先用srand()和rand()函数定义和产生指令序列,然后将指令序列变换成相应地页地址流,并针对不同地算法计算出相应地命中率.文档收集自网络,仅用于个人学习(1)通过随机数产生一个指令序列,共320 条指令.指令地地址按下述原则生成:A:50%地指令是顺序执行地B:25%地指令是均匀分布在前地址部分C:25%地指令是均匀分布在后地址部分具体地实施方法是:A:在[0,319]地指令地址之间随机选取一起点mB:顺序执行一条指令,即执行地址为m+1 地指令C:在前地址[0,m+1] 中随机选取一条指令并执行,该指令地地址为m'D:顺序执行一条指令,其地址为m'+1E:在后地址[m'+2,319]中随机选取一条指令并执行F:重复步骤A-E ,直到320 次指令(2)将指令序列变换为页地址流设:页面大小为1K ;用户内存容量 4 页到32 页;用户虚存容量为32K.在用户虚存中,按每K 存放10 条指令排列虚存地址,即320 条指令在虚存中地存放方式为:第0 条-第9 条指令为第0 页(对应虚存地址为[0,9])第10 条-第19 条指令为第1页(对应虚存地址为[10,19])第310 条-第319条指令为第31 页(对应虚存地址为[310,319])按以上方式,用户指令可组成32 页.实验指导一、虚拟存储系统UNIX 中,为了提高内存利用率,提供了内外存进程对换机制;内存空间地分配和回收均以页为单位进行;一个进程只需将其一部分(段或页)调入内存便可运行;还支持请求调页地存储管理方式.文档收集自网络,仅用于个人学习当进程在运行中需要访问某部分程序和数据时,发现其所在页面不在内存,就立即提出请求(向CPU 发出缺中断),由系统将其所需页面调入内存.这种页面调入方式叫请求调页.文档收集自网络,仅用于个人学习为实现请求调页,核心配置了四种数据结构:页表、页框号、访问位、修改位、有效位、保 护位等 .二、页面置换算法当 CPU 接收到缺页中断信号,中断处理程序先保存现场,分析中断原因,转入缺页中断处 理程序 .该程序通过查找页表,得到该页所在外存地物理块号 .如果此时内存未满,能容纳新 页,则启动磁盘 I/O 将所缺之页调入内存,然后修改页表 .如果内存已满,则须按某种置换 算法从内存中选出一页准备换出, 是否重新写盘由页表地修改位决定, 然后将缺页调入, 修 改页表 .利用修改后地页表,去形成所要访问数据地物理地址,再去访问内存数据 .整个页面地调入过程对用户是透明地 .文档收集自网络,仅用于个人学习 常用地页面置换算法有1、最佳置换算法( Optimal )2、先进先出法( Fisrt In First Out )3、最近最久未使用( Least Recently Used )4、最不经常使用法( Least Frequently Used )5、最近未使用法( No Used Recently )三、参考程序:view plaincopy to clipboardprint?50 ··60·· ··70·····80· ··90 ·100····110 ·· ·120·130 ···140 ····150 文档收集自网络,仅用于个人学习#define TRUE 1 #define FALSE 0 #define INV ALID -1#define NULL 0 #define total_instruction 320 #define total_vp 32 #define clear_period 50 typedef struct{int pn,pfn,counter,time;}pl_type;pl_type pl[total_vp]; struct pfc_struct{int pn,pfn;struct pfc_struct *next; };typedef struct pfc_struct pfc_type;pfc_type pfc[total_vp],*freepf_head,*busypf_head,*busypf_tail; int diseffect, a[total_instruction];int page[total_instruction], offset[total_instruction]; 文档收集自网络,仅用于个人学习int initialize(int);int FIFO(int); int LRU(int); int LFU(int);10· ····20·· ·30··· ·40/* 指令流长 */ /* 虚页长 */ /*清 0周期*/ /* 页面结构 *//* 页面结构数组 */ /* 页面控制结构 */文档收集自网络,仅用于个人学习int NUR(int);int OPT(int);int main( ){int s,i,j;srand(10*getpid()); /* 由于每次运行时进程号不同,故可用来作为初始化随机数队列地“种子” */ 文档收集自网络,仅用于个人学习s=(float)319*rand( )/32767/32767/2+1; // for(i=0;i<total_instruction;i+=4) /* 产生指令队列*/ { if(s<0||s>319){ printf("When i==%d,Error,s==%d\n",i,s); exit(0);}a[i]=s; /* 任选一指令访问点m*/a[i+1]=a[i]+1; /* 顺序执行一条指令*/ a[i+2]=(float)a[i]*rand( )/32767/32767/2; /* 执行前地址指令m' */ 文档收集自网络,仅用于个人学习a[i+3]=a[i+2]+1; /* 顺序执行一条指令*/s=(float)(318-a[i+2])*rand( )/32767/32767/2+a[i+2]+2; 文档收集自网络,仅用于个人学习if((a[i+2]>318)||(s>319)) printf("a[%d+2],a number which is :%d and s==%d\n",i,a[i+2],s); 文档收集自网络,仅用于个人学习}for (i=0;i<total_instruction;i++) /* 将指令序列变换成页地址流*/{page[i]=a[i]/10; offset[i]=a[i]%10;for(i=4;i<=32;i++) /*用户内存工作区从 4 个页面到32 个页面*/{printf("---%2d page frames---\n",i);FIFO(i);LRU(i);LFU(i);NUR(i);OPT(i);} return 0;}int initialize(total_pf) int total_pf;人学习/* 初始化相关数据结构*/ 文档收集自网络,仅用于个人学习/* 用户进程地内存页面数*/ 文档收集自网络,仅用于个for(i=0;i<total_instruction;i++){if(pl[page[i]].pfn==INV ALID){diseffect+=1; if(freepf_head==NULL){p=busypf_head->next;pl[busypf_head->pn].pfn=INVALID;freepf_head=busypf_head; /* 释放忙页面队列地第一个页面 */ freepf_head->next=NULL; busypf_head=p;}p=freepf_head->next;/* 按 FIFO 方式调新页面入内存页面 */freepf_head->next=NULL; freepf_head->pn=page[i];pl[page[i]].pfn=freepf_head->pfn; if(busypf_tail==NULL){int i; diseffect=0;for(i=0;i<total_vp;i++){pl[i].pn=i;pl[i].pfn=INV ALID; pl[i].counter=0; pl[i].time=-1;}/* 置页面控制结构中地页号,页面为空 */ /* 页面控制结构中地访问次数为 0,时间为 -1*/for(i=0;i<total_pf-1;i++){pfc[i].next=&pfc[i+1]; pfc[i].pfn=i; } /* 建立 pfc[i-1] 和 pfc[i] 之间地链接 */pfc[total_pf-1].next=NULL; pfc[total_pf-1].pfn=total_pf-1; freepf_head=&pfc[0]; return 0;}int FIFO(total_pf) int total_pf;{int i,j; pfc_type *p; initialize(total_pf);/* 空页面队列地头指针为 pfc[0]*//* 先进先出算法 *//* 用户进程地内存页面数 *//* 初始化相关页面控制用数据结构 */busypf_head=busypf_tail=NULL; /* 忙页面队列头,队列尾链接 */ /* 页面失效 *//* 失效次数 */ /* 无空闲页面*/busypf_head=busypf_tail=freepf_head; else {busypf_tail->next=freepf_head; busypf_tail=freepf_head;}freepf_head=p;}elsepl[page[i]].time=present_time;收集自网络,仅用于个人学习}}printf("FIFO:%6.4f\n",1-(float)diseffect/320); return 0;}int LRU (total_pf) int total_pf;{int min,minj,i,j,present_time; initialize(total_pf); present_time=0;for(i=0;i<total_instruction;i++){if(pl[page[i]].pfn==INV ALID){diseffect++;if(freepf_head==NULL){/*最近最久未使用算法*//* 页面失效 *//* 无空闲页面 */min=32767;for(j=0;j<total_vp;j++) if(min>pl[j].time&&pl[j].pfn!=INV {/* 找出 time 地最小值 */ALID) min=pl[j].time;minj=j;}freepf_head=&pfc[pl[minj].pfn];pl[minj].pfn=INV ALID; pl[minj].time=-1;freepf_head->next=NULL;//腾出一个单元}pl[page[i]].pfn=freepf_head->pfn;pl[page[i]].time=present_time; freepf_head=freepf_head->next;//有空闲页面 ,改为有效//减少一个 free 页面/*free 页面减少一个 *///命中则增加该单元地访问次数文档present_time++;}printf("LRU:%6.4f\n",1-(float)diseffect/320); return 0;}int 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;i<total_instruction;i++) { if (pl[page[i]].pfn==INV ALID) {diseffect++;if(freepf_head==NULL) { cont_flag=TRUE; old_dp=dp;while(cont_flag)if(pl[dp].counter==0&&pl[dp].pfn!=INV cont_flag=FALSE; else{dp++;if(dp==total_vp)dp=0; if(dp==old_dp)for(j=0;j<total_vp;j++)pl[j].counter=0;}freepf_head=&pfc[pl[dp].pfn]; pl[dp].pfn=INV ALID;freepf_head->next=NULL;}pl[page[i]].pfn=freepf_head->pfn; freepf_head=freepf_head->next;}else pl[page[i]].counter=1; if(i%clear_period==0) for(j=0;j<total_vp;j++) pl[j].counter=0;}printf("NUR:%6.4f\n",1-(float)diseffect/320); return 0;/* 最近未使用算法 *//* 页面失效 */ /* 无空闲页面 */ALID)}int OPT(total_pf) /* 最佳置换算法*/ int total_pf;{int i,j, max,maxpage,d,dist[total_vp];pfc_type *t;initialize(total_pf);for(i=0;i<total_instruction;i++){ //printf("In OPT for//i=86;i=176;206;250;220,221;192,193,194;258;274,275,276,277,278; 学习if(pl[page[i]].pfn==INV ALID) /* 页面失效*/{diseffect++;if(freepf_head==NULL) /* 无空闲页面*/{for(j=0;j<total_vp;j++)if(pl[j].pfn!=INV ALID) dist[j]=32767; /* 最大"距离" */ 习else dist[j]=0;d=1;for(j=i+1;j<total_instruction;j++){if(pl[page[j]].pfn!=INV ALID)dist[page[j]]=d;d++;}max=-1;for(j=0;j<total_vp;j++)if(max<dist[j]){max=dist[j];maxpage=j;}freepf_head=&pfc[pl[maxpage].pfn];freepf_head->next=NULL;pl[maxpage].pfn=INV ALID;}pl[page[i]].pfn=freepf_head->pfn;freepf_head=freepf_head->next;}}printf("OPT:%6.4f\n",1-(float)diseffect/320);return 0;}int LFU(total_pf) /* 最不经常使用置换法*/1,i=%d\n",i);文档收集自网络,仅用于个人文档收集自网络,仅用于个人学int total_pf;{int i,j,min,minpage; pfc_type *t;initialize(total_pf); for(i=0;i<total_instruction;i++) { if(pl[page[i]].pfn==INV ALID)/* 页面失效 */{ diseffect++; if(freepf_head==NULL) /* 无空闲页面 */ { min=32767; for(j=0;j<total_vp;j++) {if(min>pl[j].counter&&pl[j].pfn!=INV ALID){min=pl[j].counter; minpage=j; }pl[j].counter=0;}freepf_head=&pfc[pl[minpage].pfn];pl[minpage].pfn=INV ALID; freepf_head->next=NULL;}pl[page[i]].pfn=freepf_head->pfn; //有空闲页面 , 改为有效 pl[page[i]].counter++;freepf_head=freepf_head->next;// 减少一个 free 页面}else pl[page[i]].counter++;}printf("LFU:%6.4f\n",1-(float)diseffect/320); return 0;}#define TRUE 1#define FALSE 0 #define INV ALID -1#define NULL 0 #define total_instruction 320 #define total_vp 32 #define clear_period 50typedef struct { int pn,pfn,counter,time; }pl_type;pl_type pl[total_vp]; struct pfc_struct{/* 页面控制结构 */int pn,pfn;struct pfc_struct *next; };typedef struct pfc_struct pfc_type;pfc_type pfc[total_vp],*freepf_head,*busypf_head,*busypf_tail; 文档收集自网络,仅用于个人学习int diseffect,a[total_instruction];int page[total_instruction], offset[total_instruction]; 文档收集自网络,仅用于个人学习int initialize(int); int FIFO(int); int LRU(int);/* 指令流长 */ /* 虚页长 */ /*清0周期*/ /* 页面结构 *//* 页面结构数组 */int LFU(int);int NUR(int);int OPT(int);int main( ){int s,i,j;srand(10*getpid()); /* 由于每次运行时进程号不同,故可用来作为初始化随机数队列地“种子” */ 文档收集自网络,仅用于个人学习s=(float)319*rand( )/32767/32767/2+1; // for(i=0;i<total_instruction;i+=4) /* 产生指令队列*/ {if(s<0||s>319){ printf("When i==%d,Error,s==%d\n",i,s); exit(0);}a[i]=s; /* 任选一指令访问点m*/a[i+1]=a[i]+1; /* 顺序执行一条指令*/ a[i+2]=(float)a[i]*rand( )/32767/32767/2; /* 执行前地址指令m' */ 文档收集自网络,仅用于个人学习a[i+3]=a[i+2]+1; /* 顺序执行一条指令*/s=(float)(318-a[i+2])*rand( )/32767/32767/2+a[i+2]+2; 文档收集自网络,仅用于个人学习if((a[i+2]>318)||(s>319))printf("a[%d+2],a number which is :%d and s==%d\n",i,a[i+2],s); 文档收集自网络,仅用于个人学习}for (i=0;i<total_instruction;i++) /* 将指令序列变换成页地址流*/ {page[i]=a[i]/10; offset[i]=a[i]%10;for(i=4;i<=32;i++) /*用户内存工作区从4个页面到32个页面*/ { printf("---%2d page frames---\n",i);FIFO(i);LRU(i);LFU(i);NUR(i);OPT(i);}return 0;int initialize(total_pf) int total_pf; /*初始化相关数据结构*/ 文档收集自网络,仅用于个人学习/*用户进程地内存页面数*/ 文档收集自网络,仅用于个人学}习{int i;diseffect=0;for(i=0;i<total_vp;i++){pl[i].pn=i;pl[i].pfn=INV ALID; /* 置页面控制结构中地页号,页面为空*/ pl[i].counter=0;pl[i].time=-1; /* 页面控制结构中地访问次数为0,时间为-1*/ }for(i=0;i<total_pf-1;i++){pfc[i].next=&pfc[i+1];pfc[i].pfn=i;} /* 建立pfc[i-1] 和pfc[i] 之间地链接*/pfc[total_pf-1].next=NULL;pfc[total_pf-1].pfn=total_pf-1;freepf_head=&pfc[0]; return 0;}int FIFO(total_pf)int total_pf;{int i,j;pfc_type *p;initialize(total_pf); /* 空页面队列地头指针为pfc[0]*//* 先进先出算法*//* 用户进程地内存页面数*//* 初始化相关页面控制用数据结构*/busypf_head=busypf_tail=NULL; /* 忙页面队列头,队列尾链接*/ for(i=0;i<total_instruction;i++){/* 页面失效*/if(pl[page[i]].pfn==INV ALID){diseffect+=1; /* 失效次数*/if(freepf_head==NULL) /* 无空闲页面*/{p=busypf_head->next;pl[busypf_head->pn].pfn=INV ALID;freepf_head=busypf_head; /* 释放忙页面队列地第一个页面*/freepf_head->next=NULL;busypf_head=p;}p=freepf_head->next; /* 按FIFO 方式调新页面入内存页面*/freepf_head->next=NULL;freepf_head->pn=page[i]; pl[page[i]].pfn=freepf_head->pfn;if(busypf_tail==NULL)busypf_head=busypf_tail=freepf_head;else{ busypf_tail->next=freepf_head; /*free 页面减少一个*/ busypf_tail=freepf_head;} freepf_head=p;}} printf("FIFO:%6.4f\n",1-(float)diseffect/320);return 0;}int LRU (total_pf) /*最近最久未使用算法*/int total_pf;{int min,minj,i,j,present_time;initialize(total_pf);present_time=0;for(i=0;i<total_instruction;i++){if(pl[page[i]].pfn==INV ALID) {diseffect++;min=32767;/* 页面失效*/if(freepf_head==NULL){/* 无空闲页面*/for(j=0;j<total_vp;j++) /* 找出time 地最小值*/ if(min>pl[j].time&&pl[j].pfn!=INV ALID){min=pl[j].time;minj=j;} freepf_head=&pfc[pl[minj].pfn]; //腾出一个单元pl[minj].pfn=INV ALID;pl[minj].time=-1;freepf_head->next=NULL;}pl[page[i]].pfn=freepf_head->pfn;pl[page[i]].time=present_time;freepf_head=freepf_head->next; }else //有空闲页面,改为有效//减少一个free 页面pl[page[i]].time=present_time; 自网络,仅用于个人学习//命中则增加该单元地访问次数文档收集present_time++;}printf("LRU:%6.4f\n",1-(float)diseffect/320);return 0;}int 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;i<total_instruction;i++){ if (pl[page[i]].pfn==INV ALID) {diseffect++;if(freepf_head==NULL){ cont_flag=TRUE;old_dp=dp;while(cont_flag)if(pl[dp].counter==0&&pl[dp].pfn!=INV cont_flag=FALSE;else{dp++;if(dp==total_vp)dp=0; /* 最近未使用算法*//* 页面失效*//* 无空闲页面*/ ALID)if(dp==old_dp)for(j=0;j<total_vp;j++)pl[j].counter=0;}freepf_head=&pfc[pl[dp].pfn];pl[dp].pfn=INV ALID;freepf_head->next=NULL;}pl[page[i]].pfn=freepf_head->pfn;freepf_head=freepf_head->next;}elsepl[page[i]].counter=1;if(i%clear_period==0)for(j=0;j<total_vp;j++)pl[j].counter=0;}printf("NUR:%6.4f\n",1-(float)diseffect/320);return 0;}int OPT(total_pf) /* 最佳置换算法*/int total_pf;{int i,j, max,maxpage,d,dist[total_vp];pfc_type *t;initialize(total_pf);for(i=0;i<total_instruction;i++){ //printf("In OPT for 1,i=%d\n",i);//i=86;i=176;206;250;220,221;192,193,194;258;274,275,276,277,278; 文档收集自网络,仅用于个人学习if(pl[page[i]].pfn==INV ALID) /* 页面失效*/{diseffect++;if(freepf_head==NULL) /* 无空闲页面*/{for(j=0;j<total_vp;j++)if(pl[j].pfn!=INV ALID) dist[j]=32767; /* 最大"距离" */ 文档收集自网络,仅用于个人学习elsedist[j]=0;d=1;for(j=i+1;j<total_instruction;j++){if(pl[page[j]].pfn!=INV ALID)dist[page[j]]=d;d++;}max=-1;for(j=0;j<total_vp;j++)if(max<dist[j]){max=dist[j];maxpage=j;}freepf_head=&pfc[pl[maxpage].pfn];freepf_head->next=NULL; pl[maxpage].pfn=INVALID;}pl[page[i]].pfn=freepf_head->pfn;freepf_head=freepf_head->next;}}printf("OPT:%6.4f\n",1-(float)diseffect/320);return 0;}int LFU(total_pf) /* 最不经常使用置换法 */int total_pf;{int i,j,min,minpage;pfc_type *t;initialize(total_pf); for(i=0;i<total_instruction;i++){ if(pl[page[i]].pfn==INV ALID) /* 页面失效 */{ diseffect++;if(freepf_head==NULL) /* 无空闲页面 */{ min=32767; for(j=0;j<total_vp;j++){if(min>pl[j].counter&&pl[j].pfn!=INVALID){min=pl[j].counter;minpage=j;}pl[j].counter=0;}freepf_head=&pfc[pl[minpage].pfn];pl[minpage].pfn=INV ALID;freepf_head->next=NULL;}pl[page[i]].pfn=freepf_head->pfn; pl[page[i]].counter++; freepf_head=freepf_head->next;}else pl[page[i]].counter++;} printf("LFU:%6.4f\n",1-(float)diseffect/320);return 0;}五、分析1、从几种算法地命中率看, OPT 最高,其次为 NUR 相对较高,而 FIFO 与LRU 相差无几, 最低地是 LFU. 但每个页面执行结果会有所不同 .文档收集自网络,仅用于个人学习//有空闲页面 , 改为有效// 减少一个 free 页面2、OPT 算法在执行过程中可能会发生错误五、思考1、为什么OPT 在执行时会有错误产生?本文来自CSDN 博客,转载请标明出处:/followingturing/archive/2010/12/22/6091196.aspx 文档收集自网络,仅用于个人学习版权申明本文部分内容,包括文字、图片、以及设计等在网上搜集整理。

操作系统课程设计选题

操作系统课程设计选题

多道批处理系统的两级调度-1李旭欣李彩燕林广声
多道批处理系统的两级调度-2周理彬梁丹彤农思雯
多道批处理系统的两级调度-3王彬彬马少滨张楷豪
两道批处理系统的两级调度-1徐彬林泳林志聪
两道批处理系统的两级调度-2王南佳孙秦英谢德强
进程调度侯正之许树炯温景钊
多级文件系统-1魏如南曾志坤黄锦玲帕尔哈提·阿布都克力木多级文件系统-2丁越曾祥杰刘海峰
请求调页存储管理方式的模拟-1黄劲黄威豪张宇辰
请求调页存储管理方式的模拟-2张志泉张晓龙吕慧苍
请求调页存储管理方式的模拟-3
请求调页存储管理方式的模拟-4
银行家算法邹国琴杜径舟陈启伟
编程演示三种存储管理方式的地址换算过程马书鸿叶志锴余植荣
磁盘调度算法1陈晓聪陈俊豪李峥旭
磁盘空间管理-1陈兆龙何勇杰杜信杰
磁盘空间管理-2黄炜东张锦添曾志鹏
磁盘空间管理-3冼世勇
磁盘空间管理-4周东辉庄俊华
都克力木。

页面调度算法模拟

页面调度算法模拟

页⾯调度算法模拟模拟实现的算法:FIFO,Optimal(最佳置换),LRU,Clock,改进的Clock算法⼀、先⼊先出(FIFO):最简单的页⾯置换算法是先⼊先出(FIFO)法。

这种算法的实质是,总是选择在主存中停留时间最长(即最⽼)的⼀页置换,即先进⼊内存的页,先退出内存。

理由是:最早调⼊内存的页,其不再被使⽤的可能性⽐刚调⼊内存的可能性⼤。

建⽴⼀个FIFO队列,收容所有在内存中的页。

被置换页⾯总是在队列头上进⾏。

当⼀个页⾯被放⼊内存时,就把它插在队尾上。

这种算法只是在按线性顺序访问地址空间时才是理想的,否则效率不⾼。

因为那些常被访问的页,往往在主存中也停留得最久,结果它们因变“⽼”⽽不得不被置换出去。

FIFO的另⼀个缺点是,它会产⽣Belady现象,即在增加存储块的情况下,反⽽使缺页中断率增加了。

模拟算法如下:1package paging;23import java.util.LinkedList;45/**6 * FIFO(先进先出)页⾯置换算法7 *8 * @author wz9 * @date 15/11/30.10*/11public class FIFO {12private LinkedList<Integer> memoryBlock;1314void pageReplacement(int[] pageString, int memBlockNum) {15 memoryBlock = new LinkedList<>();16int pageFaultCount = 0, pageReplaceCount = 0;17for (int i = 0; i < pageString.length; i++) {18if (memoryBlock.contains(pageString[i]))19continue;20if (memoryBlock.size() >= memBlockNum) {21 memoryBlock.pollFirst();22// memoryBlock.set(0, pageString[i]);23 pageReplaceCount++;24 }25 memoryBlock.add(pageString[i]);26 pageFaultCount++;27 }28 System.out.println("缺页中断率: "+pageFaultCount/(double)pageString.length);29 System.out.println("页⾯置换次数: "+pageReplaceCount);30 }31 }⼆、Optimal(最佳置换)这是⼀种理想情况下的页⾯置换算法,但实际上是不可能实现的。

请求页式存储管理中常用页面置换算法模拟

请求页式存储管理中常用页面置换算法模拟

计算机操作系统实验报告济南大学信息科学与技术学院2013年xx月xx日一、实验概述1. 实验名称请求页式存储管理中常用页面置换算法管理2. 实验目的(1)了解内存分页管理策略(2)掌握调页策略(3)掌握一般常用的调度算法(4)学会各种存储分配算法的实现方法。

(5)了解页面大小和内存实际容量对命中率的影响3. 实验内容(1)采用页式分配存储方案,通过分别计算不同算法的命中率来比较算法的优劣,同时也考虑页面大小及内存实际容量对命中率的影响;(2)实现OPT 算法(最优置换算法) 、LRU 算法(Least Recently) 、FIFO 算法(First IN First Out)的模拟;(3)使用某种编程语言模拟页面置换算法。

二、实验环境C语言三、实验过程1. 设计思路和流程图选择置换算法,先输入所有页面号,为系统分配物理块,依次进行置换2. 算法实现(1)OPT基本思想:是用一维数组page[pSIZE]存储页面号序列,memery[mSIZE]是存储装入物理块中的页面。

数组next[mSIZE]记录物理块中对应页面的最后访问时间。

每当发生缺页时,就从物理块中找出最后访问时间最大的页面,调出该页,换入所缺的页面。

(2)FIFO基本思想:是用队列存储内存中的页面,队列的特点是先进先出,与该算法是一致的,所以每当发生缺页时,就从队头删除一页,而从队尾加入缺页。

或者借助辅助数组time[mSIZE]记录物理块中对应页面的进入时间,每次需要置换时换出进入时间最小的页面。

(3)LRU基本思想:是用一维数组page[pSIZE]存储页面号序列,memery[mSIZE]是存储装入物理块中的页面。

数组flag[10]标记页面的访问时间。

每当使用页面时,刷新访问时间。

发生缺页时,就从物理块中页面标记最小的一页,调出该页,换入所缺的页面。

3.源程序并附上注释#include <stdio.h>#include <stdlib.h>/*全局变量*/int mSIZE; /*物理块数*/int pSIZE; /*页面号引用串个数*/static int memery[10]={0}; /*物理块中的页号*/static int page[100]={0}; /*页面号引用串*/static int temp[100][10]={0}; /*辅助数组*//*置换算法函数*/void FIFO();void LRU();void OPT();/*辅助函数*/void print(unsigned int t);void designBy();void download();void mDelay(unsigned int Delay);/*主函数*/void main(){int i,k,code;system("color 0A");designBy();printf("┃请按任意键进行初始化操作... ┃\n");printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");printf(" >>>");getch();system("cls");system("color 0B");printf("请输入物理块的个数(M<=10):");scanf("%d",&mSIZE);printf("请输入页面号引用串的个数(P<=100):");scanf("%d",&pSIZE);puts("请依次输入页面号引用串(连续输入,无需隔开):");for(i=0;i<pSIZE;i++)scanf("%1d",&page[i]);download();system("cls");system("color 0E");do{puts("输入的页面号引用串为:");for(k=0;k<=(pSIZE-1)/20;k++){for(i=20*k;(i<pSIZE)&&(i<20*(k+1));i++){if(((i+1)%20==0)||(((i+1)%20)&&(i==pSIZE-1)))printf("%d\n",page[i]);elseprintf("%d ",page[i]);}}printf("* * * * * * * * * * * * * * * * * * * * * * *\n");printf("* 请选择页面置换算法:\t\t\t *\n");printf("* ----------------------------------------- *\n");printf("* 1.先进先出(FIFO) 2.最近最久未使用(LRU) *\n");printf("* 3.最佳(OPT) 4.退出*\n");printf("* * * * * * * * * * * * * * * * * * * * * * *\n");printf("请选择操作:[ ]\b\b");scanf("%d",&code);switch(code){case 1:FIFO();break;case 2:LRU();break;case 3:OPT();break;case 4:system("cls");system("color 0A");designBy(); /*显示设计者信息后退出*/printf("┃谢谢使用页面置换算法演示器! 正版授权㊣┃\n");printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");exit(0);default:printf("输入错误,请重新输入:");}printf("按任意键重新选择置换算法:>>>");getch();system("cls");}while (code!=4);getch();}/*载入数据*/void download(){int i;system("color 0D");printf("╔════════════╗\n");printf("║正在载入数据,请稍候!!!║\n");printf("╚════════════╝\n");printf("Loading...\n");printf(" O");for(i=0;i<51;i++)printf("\b");for(i=0;i<50;i++){mDelay((pSIZE+mSIZE)/2);printf(">");}printf("\nFinish.\n载入成功,按任意键进入置换算法选择界面:>>>");getch();}/*设置延迟*/void mDelay(unsigned int Delay){unsigned int i;for(;Delay>0;Delay--){for(i=0;i<124;i++){printf(" \b");}}}/*显示设计者信息*/void designBy(){printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");printf("┃课题三:页面置换算法┃\n");printf("┃学号:20111214034 ┃\n");printf("┃姓名:韩瑶┃\n");printf("┣━━━━━━━━━━━━━━━━━━━━━━━━━┫\n"); }void print(unsigned int t){int i,j,k,l;int flag;for(k=0;k<=(pSIZE-1)/20;k++){for(i=20*k;(i<pSIZE)&&(i<20*(k+1));i++){if(((i+1)%20==0)||(((i+1)%20)&&(i==pSIZE-1)))printf("%d\n",page[i]);elseprintf("%d ",page[i]);}for(j=0;j<mSIZE;j++){for(i=20*k;(i<mSIZE+20*k)&&(i<pSIZE);i++){if(i>=j)printf(" |%d|",temp[i][j]);elseprintf(" | |");}for(i=mSIZE+20*k;(i<pSIZE)&&(i<20*(k+1));i++){for(flag=0,l=0;l<mSIZE;l++)if(temp[i][l]==temp[i-1][l])flag++;if(flag==mSIZE)/*页面在物理块中*/printf(" ");elseprintf(" |%d|",temp[i][j]);}/*每行显示20个*/if(i%20==0)continue;printf("\n");}}printf("----------------------------------------\n");printf("缺页次数:%d\t\t",t+mSIZE);printf("缺页率:%d/%d\n",t+mSIZE,pSIZE);printf("置换次数:%d\t\t",t);printf("访问命中率:%d%%\n",(pSIZE-(t+mSIZE))*100/pSIZE);printf("----------------------------------------\n");}/*计算过程延迟*/void compute(){int i;printf("正在进行相关计算,请稍候");for(i=1;i<20;i++){mDelay(15);if(i%4==0)printf("\b\b\b\b\b\b \b\b\b\b\b\b");elseprintf("Θ");}for(i=0;i++<30;printf("\b"));for(i=0;i++<30;printf(" "));for(i=0;i++<30;printf("\b"));}/*先进先出页面置换算法*/void FIFO(){int memery[10]={0};int time[10]={0}; /*记录进入物理块的时间*/int i,j,k,m;int max=0; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];time[i]=i;for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;}if(k==mSIZE) /*如果不在物理块中*/{count++;/*计算换出页*/max=time[0]<time[1]?0:1;for(m=2;m<mSIZE;m++)if(time[m]<time[max])max=m;memery[max]=page[i];time[max]=i; /*记录该页进入物理块的时间*/for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else{for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}/*最近最久未使用置换算法*/void LRU(){int memery[10]={0};int flag[10]={0}; /*记录页面的访问时间*/int i,j,k,m;int max=0; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];flag[i]=i;for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;elseflag[j]=i; /*刷新该页的访问时间*/ }if(k==mSIZE) /*如果不在物理块中*/{count++;/*计算换出页*/max=flag[0]<flag[1]?0:1;for(m=2;m<mSIZE;m++)if(flag[m]<flag[max])max=m;memery[max]=page[i];flag[max]=i; /*记录该页的访问时间*/for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else{for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}/*最佳置换算法*/void OPT(){int memery[10]={0};int next[10]={0}; /*记录下一次访问时间*/int i,j,k,l,m;int max; /*记录换出页*/int count=0; /*记录置换次数*//*前mSIZE个数直接放入*/for(i=0;i<mSIZE;i++){memery[i]=page[i];for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}for(i=mSIZE;i<pSIZE;i++){/*判断新页面号是否在物理块中*/for(j=0,k=0;j<mSIZE;j++){if(memery[j]!=page[i])k++;}if(k==mSIZE) /*如果不在物理块中*/{count++;/*得到物理快中各页下一次访问时间*/for(m=0;m<mSIZE;m++){for(l=i+1;l<pSIZE;l++)if(memery[m]==page[l])break;next[m]=l;}/*计算换出页*/max=next[0]>=next[1]?0:1;for(m=2;m<mSIZE;m++)if(next[m]>next[max])max=m;/*下一次访问时间都为pSIZE,则置换物理块中第一个*/memery[max]=page[i];for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}else {for(j=0;j<mSIZE;j++)temp[i][j]=memery[j];}}compute();print(count);}6. 程序运行时的初值和运行结果1. 按任意键进行初始化:2. 载入数据:3. 进入置换算法选择界面:4.运算中延迟操作5.三种算法演示结果:四、实验体会掌握了一般的调度算法,了解了页面大小和内存实际容量对命中率的影响(英文版)Two regulations promulgated for implementation is in the party in power for a long time and the rule of law conditions, the implementation of comprehensive strictly strategic plan, implementation in accordance with the rules and discipline to manage the party, strengthen inner-party supervision of major initiatives. The two regulations supporting each other, the < code > adhere to a positive advocate, focusing on morality is of Party members and Party leading cadres can see, enough to get a high standard; < rule > around the party discipline, disciplinary ruler requirements, listed as "negative list, focusing on vertical gauge, draw the party organizations and Party members do not touch the" bottom line ". Here, the main from four square face two party rules of interpretation: the first part introduces two party Revised regulations the necessity and the revision process; the second part is the interpretation of the two fundamental principles of the revision of laws and regulations in the party; the third part introduces two party regulations modified the main changes and needs to grasp several key problems; the fourth part on how to grasp the implementation of the two regulations of the party. < code > and < Regulations > revised the necessity and revisedhistory of the CPC Central Committee the amendment to the Chinese Communist Party members and leading cadres honest politics several guidelines > and < Chinese Communist Party discipline and Punishment Regulations > column 1 by 2015 to strengthen party laws and regulations focus. Two party regulations revision work lasted a Years, pooling the wisdom of the whole party, ideological consensus, draw historical experience, respect for the wisdom of our predecessors, which reflects the unity of inheritance and innovation; follow the correct direction, grasp the limited goals, adhere to the party's leadership, to solve the masses of the people reflect a focus on the problem. The new revision of the < code > and < rule >, reflects the party's 18 and the eighth session of the third, the spirit of the fourth plenary session, reflecting the experience of studying and implementing the General Secretary Xi Jinping series of important speech, reflects the party's eighteen years comprehensive strictly practice. (a) revised two regulations of the party need of < the ICAC guidelines > in < in 1997 Leaders as members of the Communist Party of China clean politics certain criteria (Trial) > based on revised, the promulgation and implementation of January 2010, to strengthen the construction of the contingent of leading cadres play animportant role. But with the party to manage the party strictly administering the deepening, has not been able to fully meet the actual needs. Content is too complicated, "eight prohibition, 52 are not allowed to" hard to remember, and also difficult to put into practice; the second is concisely positive advocated by the lack of prohibited provisions excessive, no autonomy requirements; the third is banned terms and discipline law, both with the party discipline, disciplinary regulations repeat and Criminal law and other laws and regulations repeat; the fourth is to "clean" the theme is not prominent, not for the existing problems, and is narrow, only needle of county-level leading cadres above. < rule > is in 1997 < Chinese Communist Party disciplinary cases (Trial) > based on revision, in December 2003 the promulgation and implementation, to strengthen the construction of the party play very important role. Along with the development of the situation, which many provisions have been unable to fully meet the comprehensive strictly administering the practice needs. One is Ji law, more than half of the provisions and criminal law and other countries laws and regulations Repetition; two is the political discipline regulations is not prominent, not specific, for violation of the party constitution, damage theauthority of Party Constitution of misconduct lack necessary and serious responsibility to pursue; third is the main discipline for the leading cadres, does not cover all Party members. Based on the above situation, need to < the criterion of a clean and honest administration > and < rule > the two is likely to be more relevant regulations first amendment. By revising, really put the authority of Party discipline, the seriousness in the party tree and call up the majority of Party members and cadres of the party constitution of party compasses party consciousness. (II) two party regulations revision process the Central Committee of the Communist Party of China attaches great importance to two regulations revision . Xi Jinping, general books recorded in the Fifth Plenary Session of the eighth session of the Central Commission for Discipline Inspection, on the revised regulations < > made clear instructions. According to the central deployment, the Central Commission for Discipline Inspection from 2014 under six months begin study two regulations revision. The Standing Committee of the Central Commission for Discipline Inspection 4 review revised. Comrade Wang Qishan 14 times held a special meeting to study two regulations revision, amendment clarifies the direction, major issues of principle, path and target,respectively held a forum will listen to part of the province (area) secretary of the Party committee, Secretary of the Discipline Inspection Commission, part of the central ministries and state organs DepartmentThe first party committee is mainly responsible for people, views of experts and scholars and grassroots party organizations and Party members. Approved by the Central Committee of the Communist Party of China, on 7 September 2015, the general office of the Central Committee of the Party issued a notice to solicit the provinces (autonomous regions, municipalities) Party, the central ministries and commissions, state ministries and commissions of the Party (party), the General Political Department of the military, every 3 people organization of Party of two regulations revision opinion. Central Commission for Discipline Inspection of extensive solicitation of opinions, careful study, attracting, formed a revised sent reviewers. In October 8 and October 12, Central Committee Political Bureau Standing Committee and the Political Bureau of the Central Committee After consideration of the two regulations revised draft. On October 18, the Central Committee of the Communist Party of China formally issued two regulations. Can say, two laws amendment concentrated thewisdom of the whole party, embodies the party. Second, < code > and < Regulations > revision of the basic principles of two party regulations revision work and implement the party's eighteen, ten eight plenary, the spirit of the Fourth Plenary Session of the Eleventh Central Committee and General Secretary Xi Jinping important instructions on the revised < low political criterion > and < Regulations >, highlighting the ruling party characteristics, serious discipline, the discipline quite in front of the law, based on the current, a long-term, advance as a whole, with Bu Xiuding independent < rule > and < rule >. Main principle is: first, adhere to the party constitution to follow. The constitution about discipline and self-discipline required specific, awaken the party constitution of party compasses party consciousness, maintaining the authority of the constitution. General Secretary Xi Jinping pointed out that "no rules, no side round. Party constitution is the fundamental law, the party must follow the general rules. In early 2015 held the eighth session of the Central Commission for Discipline Inspection Fifth Plenary Session of the 16th Central Committee, Xi Jinping again pointed out that constitution is the party must follow the general rules, but also the general rules." the revision of the< code > and < rule > is Method in adhere to the regulations established for the purpose of combining rule of virtue is to adhere to the party constitution as a fundamental to follow, the constitution authority set up, wake up the party constitution and party rules the sense of discipline, the party constitution about discipline and self-discipline specific requirements. 4 second is to adhere to in accordance with the regulations governing the party and the party. The Party of rule of virtue "de", mainly refers to the party's ideals and beliefs, excellent traditional style. The revised the < code > closely linked to the "self-discipline", insisting on the positive initiative, for all members, highlight the "vital few", emphasized self-discipline, focusing on the morality, and the majority of Party members and the ideological and moral standards. The revised < > Ji method separately, Ji, Ji Yan to Method, as a "negative list", emphasizing the heteronomy, focusing on vertical gauge. Is this one high and one low, a positive reaction, the strict party discipline and practice results transformation for the integration of the whole party to observe moral and discipline requirements, for the majority of Party members and cadres provides benchmarking and ruler. Third, insist on to. In view of the problems existing in theparty at the present stage, the main problems of Party members and cadres in the aspect of self-discipline and abide by the discipline to make clearly defined, especially the party's eighteen years strict political discipline and political rules, organization and discipline and to implement the central eight provisions of the spirit against the four winds and other requirements into Disciplinary provisions. Not one pace reachs the designated position, focusing on in line with reality, pragmatic and effective. After the revision of major changes, major changes in the < code > and < rule > modified and needs to grasp several key problems (a) < code > < code > adhere to according to regulations governing the party and party with morals in combination, for at the present stage, the leadership of the party members and cadres and Party members in existing main problems of self-discipline, put forward principles, requirements and specifications, showing Communists noble moral pursuit, reflected at all times and in all over the world ethics from high from low 5 common requirements. One is closely linked to the "self-discipline", removal and no direct relation to the provisions of . the second is adhere to a positive advocate, "eight prohibition" 52 are not allowed to "about the content of the" negative list moved into synchronizationamendment < cases >. Three is for all the party members, will apply object from the leadership of the party members and cadres to expand to all Party members, fully embodies the comprehensive strictly required. The fourth is prominent key minority, seize the leadership of the party members and cadres is the key, and put forward higher requirements than the ordinary Party members. Five is to simplify, and strive to achieve concise, easy to understand, easy to remember. The revised < code > is the ruling Party since the first insists on a positive advocate forAll Party members and the self-discipline norms, moral declaration issued to all members of the party and the National People's solemn commitment. > < criterion of a clean and honest administration consists of 4 parts, 18, more than 3600 words. After the revision of the < code >, a total of eight, 281 words, including lead, specification and Party member cadre clean fingered self-discipline norms, etc. Part 3 members low-cost clean and self-discipline, the main contents can be summarized as "four must" "eight code". Lead part, reiterated on ideal and faith, fundamental purpose, the fine traditions and work style, noble sentiments, such as "four must" the principle of requirements, strong tone of self-discipline, The higher request for 6 andsupervised tenet, the foothold in permanent Bao the party's advanced nature and purity, to reflect the revised standards requirements. Members of self-discipline norms around the party members how to correctly treat and deal with the "public and private", "cheap and rot" thrifty and extravagance "bitter music", put forward the "four norms". Party leader cadre clean fingered self-discipline norms for the leadership of the party members and cadres of the "vital few", around the "clean politics", from civil servant of the color, the exercise of power, moral integrity, a good family tradition and other aspects of the leadership of the party members and cadres of the "four norms" < > < norm norm. "The Party member's self-discipline norms" and "party members and leading cadre clean fingered self-discipline norms," a total of eight, collectively referred to as the "eight". "Four must" and "eight" of the content from the party constitution and Party's several generation of leaders, especially Xi Jinping, general secretary of the important discussion, refer to the "three discipline and eight points for attention" statements, and reference some embody the Chinese nation excellent traditional culture essence of epigrams. (2) the revised regulations, the main changes in the revised Regulations > to fully adapt to thestrictly requirements, reflects the according to the regulations governing the law of recognition of deepening, the realization of the discipline construction and Jin Ju. < rule > is party a ruler, members of the basic line and follow. And the majority of Party members and cadres of Party organizations at all levels should adhere to the bottom line of thinking, fear discipline, hold the bottom line, as a preventive measure, to keep the party's advanced nature and purity. 1, respect for the constitution, refinement and discipline. Revised < rule > from comprehensive comb physical constitution began, the party constitution and other regulations of the Party of Party organizations and Party discipline requirements refinement, clearly defined in violation of the party constitution will be in accordance with regulations to give the corresponding disciplinary action. The original 10 categories of misconduct, integration specification for political discipline, discipline, honesty and discipline masses Ji Law and discipline and discipline and other six categories, the content of < rule > real return to Party discipline, for the majority of Party members and listed a "negative list. 7 2, highlighting the political discipline and political rules. > < Regulations according to the stage of the discipline of outstandingperformance, emphasizing political discipline and political rules, organization and discipline, in opposition to the party's leadership and the party's basic theory, basic line, basic program and basic experience, the basic requirement of behavior made prescribed punishment, increase the cliques, against the organization such as violation of the provisions, to ensure that the central government decrees and the Party of centralized and unified. 3, adhere to strict discipline in the law and discipline In front, Ji separated. Revised < Regulations > adhere to the problem oriented, do Ji separated. Any national law existing content, will not repeat the provisions, the total removal of 79 and criminal law, repeat the content of the public security management punishment law, and other laws and regulations. In the general reiterated that party organizations and Party members must conscientiously accept the party's discipline, die van comply with national laws and regulations; at the same time, to investigate violations of Party members and even criminal behavior of Party discipline and responsibility, > < Regulations distinguish five different conditions, with special provisions were made provisions, so as to realize the connection of Party discipline and state law. 4, reflect Wind building and anti-corruptionstruggle of the latest achievements. < rule > the party's eighteen years implement the spirit of the central provisions of the eight, against the requirements of the "four winds" and transformation for disciplinary provisions, reflecting the style construction is always on the road, not a gust of wind. In the fight against corruption out of new problems, increase the trading rights, the use of authority relatives profit and other disciplinary terms. Prominent discipline of the masses, the new against the interests of the masses and ignore the demands of the masses and other disciplinary terms and make provisions of the disposition and the destruction of the party's close ties with the masses.Discipline to protect the party's purpose. 8 of these regulations, a total of three series, Chapter 15, 178, more than 24000 words, after the revision of the regulations a total of 3 series, Chapter 11, 133, 17000 words, divided into "general" and "special provisions" and "Supplementary Provisions" Part 3. Among them, add, delete, modify the provisions of the proportion of up to nearly 90%. 1, the general general is divided into five chapters. The first chapter to the regulations of the guiding ideology, principles and scope of application of the provisions, highlight the strengthening ofthe party constitution consciousness, maintenance the authority of Party Constitution, increase the party organizations and Party members must abide by the party constitution, Yan Centralized centralized, would examine at all levels of the amended provisions implementing and maintaining Party discipline, and consciously accept the party discipline, exemplary compliance with national laws and regulations. The second chapter of discipline concept, disciplinary action types and effects of the regulations, will be a serious warning from the original a year for a year and a half; increase the Party Congress representative, by leaving the party above (including leave probation) punishment, the party organization should be terminated its representative qualification provisions. The third chapter of the disciplinary rules of use prescribed in the discipline rectifying process, non convergence, not close hand classified as severely or heavier punishment. "Discipline straighten "At least eighteen years of five years, these five years is to pay close attention to the provisions of the central eight implementation and anti -" four winds ". The fourth chapter on suspicion of illegal party disciplinary distinguish five different conditions, with special provisions were madeprovisions, to achieve effective convergence of Party and country 9 method. < rule > the provisions of Article 27, Party organizations in the disciplinary review found that party members have committed embezzlement, bribery, dereliction of duty dereliction of duty and other criminal law act is suspected of committing a crime shall give cancel party posts, probation or expelled from the party. The second is < Regulations > Article 28 the provisions of Party organizations in the disciplinary review But found that party members are stipulated in the criminal law, although not involved in a crime shall be investigated for Party discipline and responsibility should be depending on the specific circumstances shall be given a warning until expelled punishment. This situation and a difference is that the former regulation behavior has been suspected of a crime, the feeling is quite strict, and the latter for the behavior not involving crime, only the objective performance of the provisions of the criminal code of behavior, but the plot is a crime to slightly. < Regulations > the 29 provisions, Party organizations in the discipline review found that party members and other illegal behavior, affect the party's image, the damage to the party, the state and the people's interests, we should depend on the situation。

请求分页存储管理模拟实验

请求分页存储管理模拟实验

操作系统模拟实验实验名称:请求分页存储管理模拟实验实验目的:通过实验了解windows系统中的线程同步如何使用,进一步了解操作系统的同步机制。

实验内容:调用Windows API,模拟解决生产者-消费者问题;思考在两个线程函数中哪些是临界资源?哪些代码是临界区?哪些代码是进入临界区?哪些代码是退出临界区?进入临界区和退出临界区的代码是否成对出现?学习Windows API中的如何创建线程,互斥,临界区等。

程序运行结果:源程序:#include "stdAfx.h"//包含头文件以支持多线程#include "windows.h"#include "stdio.h"//用于标志所有的子线程是否结束//每次子线程结束后,此值便加1。

static long ThreadCompleted = 0;//互斥量HANDLE mutex;//信号量,用于生产者通知消费者HANDLE full;//信号量,用于消费者通知生产者HANDLE empty;//信号量,当所有的子线程结束后,通知主线程,可以结束。

HANDLE evtTerminate;//生产标志#define p_item 1//消费标志#define c_item 0//哨兵#define END 10//缓冲区最大长度const int max_buf_size=11;const int cur_size=10;//缓冲区定义int BUFFER[max_buf_size];//放消息指针int in=0;//取消息指针int out=0;int front=0;int tail=0;int sleep_time=1000;bool flag=true;//线程函数的标准格式unsigned long __stdcall p_Thread(void *theBuf);unsigned long __stdcall c_Thread(void *theBuf);//打印缓冲区内容void PrintBuf(int buf[],int buf_size);int main(int argc, char* argv[]){//初始化缓冲区unsigned long TID1, TID2;for(int i=0;i<cur_size;i++)BUFFER[i]=0;//互斥量和信号量的创建,函数用法可查看MSDNmutex=CreateMutex(NULL,false,"mutex");full=CreateSemaphore(NULL,0,1,"full");empty=CreateSemaphore(NULL,max_buf_size,max_buf_size,"empty");evtTerminate = CreateEvent(NULL, FALSE, FALSE, "Terminate");//创建一个生产者线程和消费者线程。

请求调页存储管理方式的模拟

请求调页存储管理方式的模拟

实验3请求调页存储管理方式的模拟1实验目的通过对页面、页表、地址转换和页面置换过程的模拟,加深对请求调页系统的原理和实现过程的理解。

2实验内容(1)假设每个页面中可存放10条指令,分配给一作业的内存块数为4。

(2)模拟一作业的执行过程。

该作业共有320条指令,即它的地址空间为32页,目前它的所有页都还未调入内存。

在模拟过程中,如果所访问的指令已经在内存中,则显示其物理地址,并转下一条指令。

如果所访问的指令还未装入内存,则发生缺页,此时需记录缺页的次数,并将相应页调入内存。

如果4个内存块中均已装入该作业,则需进行页面置换。

最后显示其物理地址,并转下一条指令。

在所有320条指令执行完毕后,请计算并显示作业运行过程中发生的缺页率。

(3)置换算法:请分别考虑OPT、FIFO和LRU算法。

(4)作业中指令的访问次序按下述原则生成:•50%的指令是顺序执行的。

•25%的指令是均匀分布在前地址部分。

•25%的指令时均匀分布在后地址部分。

代码:package mainDart;import java.util.ArrayList;import java.util.List;import java.util.Random;public class FIFO {private static int times=0;//记录置换内存页面的次数/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 先进先出算法* 总是淘汰最先进入内存的页面* 在实现的时候,记录上一次所替换的页面在内存的下标,则本次要替换的位置就是上次下标+1的位置,并且下标是0~3循环的* @param memoryNum* @param page*/public static void FIFOChangePage(List<Integer> memoryNum,int page){int index = FIFOChangePage(memoryNum,page,++times);memoryNum.remove(index);memoryNum.add(index, page);}/*** 返回本次替换的页面在内存中的位置* @param memoryNum* @param page* @param times记录替换页面的次数,第一次替换的是内存第0个单元* @return*/public static int FIFOChangePage(List<Integer> memoryNum,int page,int times) {if(times==1){return 0;}int index = (FIFOChangePage(memoryNum,page,times-1)+1)%4;return index;}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}List<Integer> memoryNum= new ArrayList<Integer>(4);//内存块存储的页面int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存,输出该页面所在内存块的号{}else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{memoryNum.add(page);}else//内存存满,需要调用页面置换算法,进行页面置换{FIFOChangePage(memoryNum,page);//先进先出算法}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}}package mainDart;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Random;public class LRU {/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 最近最久未使用算法* @param order*/public static void LRUChangePage(int [] order){List<Integer> memoryNum = new ArrayList<Integer>(4);//内存块int[] timeFlag =new int[]{-1,-1,-1,-1}; //用来记录内存当中各单元未被访问的时间值int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存{int index = memoryNum.indexOf(page);timeFlag[index]=0;//将时间变为0 }else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{//将没有命中的所有页面的时间加一for(int in=0;in<4;in++){if(timeFlag[in]!=-1){timeFlag[in]+=1;}}//将page加入内存并将时间置为0memoryNum.add(page);timeFlag[memoryNum.indexOf(page)]=0;}else//内存存满,需要调用页面置换算法,进行页面置换{int maxIn=-1;//记录拥有最大时间值的标记的下标int maxT=-1;//记录最大的时间值for(int in=0;in<4;in++)//找出内存中时间值最大的进行替换{if(timeFlag[in]>maxT){maxT=timeFlag[in];maxIn=in;}}memoryNum.remove(maxIn);memoryNum.add(maxIn,page);timeFlag[maxIn]=0;//将没有命中的所有页面的时间加一for(int in=0;in<4;in++){if(in!=maxIn){timeFlag[in]+=1;}}}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}LRUChangePage(order);}}package mainDart;import java.util.ArrayList;import java.util.List;import java.util.Random;public class Optimal {/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/**** @param order320条指令数组* @return 返回一个链表,依次保存着320条指令每条指令所在的页面*/public static List<Integer> pageSeq(int[] order){List<Integer> pageSeq = new ArrayList<Integer>();for(int temp:order){pageSeq.add(temp/10);}return pageSeq;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 最佳置换算法* 根据当前已经在内存中的页面在之后被需要的先后进行置换** @param pageSeq 整个320条指令,从头到尾所需要的页面* @param memoryNum 已满的内存空间* @param page等待被调入内存的页面*/public static void OptimalChangePage(List<Integer> pageSeq,int start,List<Integer> memoryNum,int page){int maxSeq=-1,index=0;for(int pageNum:memoryNum) //遍历内存{for(int i=start;i<pageSeq.size();i++){if(pageNum==pageSeq.get(i)){if(i>maxSeq){maxSeq=i;}break;}}}if(maxSeq>-1)//maxSeq==-1说明内存当中的四个页面在将来都不会再被使用,这时默认将内存块中的第一个页面置换出{index = memoryNum.indexOf(pageSeq.get(maxSeq));//记录将要被置换的那个页面所在内存位置}memoryNum.remove(index);//将内存中将来最久被使用的页面删除memoryNum.add(index, page);//将需要调入的页面加入内存}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}List<Integer> pageSeq = pageSeq(order); //依次存放着指令所在的页面号List<Integer> memoryNum= new ArrayList<Integer>(4);//内存块存储的页面int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存,输出该页面所在内存块的号{}else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{memoryNum.add(page);}else//内存存满,需要调用页面置换算法,进行页面置换{OptimalChangePage(pageSeq,i+1,memoryNum,page);//最佳置换算法}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}}package mainDart;import java.util.ArrayList;import java.util.List;public class TestAPP {public static void main(String[] args) {List<Integer> list = new ArrayList<Integer>();list.add(1);list.add(3);list.add(45);System.out.println(list);list.remove(1);list.add(1, -1);System.out.println(list);}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验3请求调页存储管理方式的模拟1实验目的通过对页面、页表、地址转换和页面置换过程的模拟,加深对请求调页系统的原理和实现过程的理解。

2实验内容(1)假设每个页面中可存放10条指令,分配给一作业的内存块数为4。

(2)模拟一作业的执行过程。

该作业共有320条指令,即它的地址空间为32页,目前它的所有页都还未调入内存。

在模拟过程中,如果所访问的指令已经在内存中,则显示其物理地址,并转下一条指令。

如果所访问的指令还未装入内存,则发生缺页,此时需记录缺页的次数,并将相应页调入内存。

如果4个内存块中均已装入该作业,则需进行页面置换。

最后显示其物理地址,并转下一条指令。

在所有320条指令执行完毕后,请计算并显示作业运行过程中发生的缺页率。

(3)置换算法:请分别考虑OPT、FIFO和LRU算法。

(4)作业中指令的访问次序按下述原则生成:•50%的指令是顺序执行的。

•25%的指令是均匀分布在前地址部分。

•25%的指令时均匀分布在后地址部分。

代码:package mainDart;import java.util.ArrayList;import java.util.List;import java.util.Random;public class FIFO {private static int times=0;//记录置换内存页面的次数/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 先进先出算法* 总是淘汰最先进入内存的页面* 在实现的时候,记录上一次所替换的页面在内存的下标,则本次要替换的位置就是上次下标+1的位置,并且下标是0~3循环的* @param memoryNum* @param page*/public static void FIFOChangePage(List<Integer> memoryNum,int page){int index = FIFOChangePage(memoryNum,page,++times);memoryNum.remove(index);memoryNum.add(index, page);}/*** 返回本次替换的页面在内存中的位置* @param memoryNum* @param page* @param times记录替换页面的次数,第一次替换的是内存第0个单元* @return*/public static int FIFOChangePage(List<Integer> memoryNum,int page,int times) {if(times==1){return 0;}int index = (FIFOChangePage(memoryNum,page,times-1)+1)%4;return index;}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}List<Integer> memoryNum= new ArrayList<Integer>(4);//内存块存储的页面int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存,输出该页面所在内存块的号{}else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{memoryNum.add(page);}else//内存存满,需要调用页面置换算法,进行页面置换{FIFOChangePage(memoryNum,page);//先进先出算法}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}}package mainDart;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Random;public class LRU {/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 最近最久未使用算法* @param order*/public static void LRUChangePage(int [] order){List<Integer> memoryNum = new ArrayList<Integer>(4);//内存块int[] timeFlag =new int[]{-1,-1,-1,-1}; //用来记录内存当中各单元未被访问的时间值int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存{int index = memoryNum.indexOf(page);timeFlag[index]=0;//将时间变为0 }else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{//将没有命中的所有页面的时间加一for(int in=0;in<4;in++){if(timeFlag[in]!=-1){timeFlag[in]+=1;}}//将page加入内存并将时间置为0memoryNum.add(page);timeFlag[memoryNum.indexOf(page)]=0;}else//内存存满,需要调用页面置换算法,进行页面置换{int maxIn=-1;//记录拥有最大时间值的标记的下标int maxT=-1;//记录最大的时间值for(int in=0;in<4;in++)//找出内存中时间值最大的进行替换{if(timeFlag[in]>maxT){maxT=timeFlag[in];maxIn=in;}}memoryNum.remove(maxIn);memoryNum.add(maxIn,page);timeFlag[maxIn]=0;//将没有命中的所有页面的时间加一for(int in=0;in<4;in++){if(in!=maxIn){timeFlag[in]+=1;}}}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}LRUChangePage(order);}}package mainDart;import java.util.ArrayList;import java.util.List;import java.util.Random;public class Optimal {/*** 随机产生0~319之间的数* 产生320条指令** @return 包含320条指令的数组*/public static int[] productNumber(){int order[] = new int[320];//数组存储的数字表示指令Random rand = new Random();for(int i=0;i<320;i++){if(i%4==0){order[i]=rand.nextInt(319); //0<=order<319}else if(i%4==1){order[i]=order[i-1]+1;//1<=order<320}else if(i%4==2){order[i]= rand.nextInt(order[i-1]);}else if(i%4==3){order[i]=order[i-1]+rand.nextInt(320-order[i-1]);}}return order;}/**** @param order320条指令数组* @return 返回一个链表,依次保存着320条指令每条指令所在的页面*/public static List<Integer> pageSeq(int[] order){List<Integer> pageSeq = new ArrayList<Integer>();for(int temp:order){pageSeq.add(temp/10);}return pageSeq;}/*** 打印链表* @param list*/public static void printList(List<Integer> list){for(int temt:list){System.out.print(temt+"\t");}System.out.println();}/*** 最佳置换算法* 根据当前已经在内存中的页面在之后被需要的先后进行置换** @param pageSeq 整个320条指令,从头到尾所需要的页面* @param memoryNum 已满的内存空间* @param page等待被调入内存的页面*/public static void OptimalChangePage(List<Integer> pageSeq,int start,List<Integer> memoryNum,int page){int maxSeq=-1,index=0;for(int pageNum:memoryNum) //遍历内存{for(int i=start;i<pageSeq.size();i++){if(pageNum==pageSeq.get(i)){if(i>maxSeq){maxSeq=i;}break;}}}if(maxSeq>-1)//maxSeq==-1说明内存当中的四个页面在将来都不会再被使用,这时默认将内存块中的第一个页面置换出{index = memoryNum.indexOf(pageSeq.get(maxSeq));//记录将要被置换的那个页面所在内存位置}memoryNum.remove(index);//将内存中将来最久被使用的页面删除memoryNum.add(index, page);//将需要调入的页面加入内存}public static void main(String[] args) {int[] order = productNumber();System.out.println("320条随机指令数:");for(int i =0;i<order.length;i++){System.out.print(order[i]+"\t");if((i+1)%10==0){System.out.println();}}List<Integer> pageSeq = pageSeq(order); //依次存放着指令所在的页面号List<Integer> memoryNum= new ArrayList<Integer>(4);//内存块存储的页面int count=0;//记录缺页次数for(int i=0;i<320;i++){int page = order[i]/10;if(memoryNum.contains(page)) //若该指令所在页面已经在内存,输出该页面所在内存块的号{}else//没在内存,发生缺页,需要判断内存块是否存满,{if(memoryNum.size()<4) //内存没满,直接将所需页面调入内存{memoryNum.add(page);}else//内存存满,需要调用页面置换算法,进行页面置换{OptimalChangePage(pageSeq,i+1,memoryNum,page);//最佳置换算法}count++;//记录缺页次数}printList(memoryNum);//打印内存所调入页面的情况}System.out.println("缺页率:"+(double)count/320);}}package mainDart;import java.util.ArrayList;import java.util.List;public class TestAPP {public static void main(String[] args) {List<Integer> list = new ArrayList<Integer>();list.add(1);list.add(3);list.add(45);System.out.println(list);list.remove(1);list.add(1, -1);System.out.println(list);}}。

相关文档
最新文档