虚拟存储器管理方案实验报告Word格式.docx
- 文档编号:20748126
- 上传时间:2023-01-25
- 格式:DOCX
- 页数:13
- 大小:18.03KB
虚拟存储器管理方案实验报告Word格式.docx
《虚拟存储器管理方案实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《虚拟存储器管理方案实验报告Word格式.docx(13页珍藏版)》请在冰豆网上搜索。
4.算法中实页的组织因为能分配的实页数n是在程序运行时由用户动态指派的,所以应使用链表组织动态产生的多个实页。
为了调度算法实现的方便,可以考虑引入free和busy两个链表:
free链表用于组织未分配出去的实页,首指针为freehead,初始时n个实页都处于free链表中;
busy链表用于组织已分配出去的实页,首指针为busyhead,尾指针为busytail,初始值都为null。
当所要访问的一个虚页不在实页中时,将产生缺页中断。
此时若free链表不为空,就取下链表首指针所指的实页,并分配给该虚页。
若free链表为空,则说明n个实页已全部分配出去,此时应进行页面置换:
对于FIFO算法要将busyhead所指的实页从busy链表中取下,分配给该虚页,然后再将该实页插入到busy链表尾部;
对于LRU算法则要从所有已分配实页的虚页中找出time值为最小的虚页,将该虚页从装
载它的那个实页中置换出去,并在该实页中装入当前正要访问的虚页。
三、程序流程图
三个模块的流程图
1〉登录模块
2〉参数输入模块
开始
打开waccept窗口
关闭winput窗口
3〉算法实现模块
打开winput窗口
关闭waccept窗口
输入当前磁头位置
输入各磁道号位置
四、主要程序清单
模块之间的调用关系
#include
intproducerand(intremainder);
voidinitprocess;
voidchosedisplace;
structlinknode
fifo(structlinknodehead,intrandcount);
voidOptimal(structlinknodehead,intrandprocess);
structlinknode
LRU(structlinknodehead,intrandprocess);
initlink;
voidchoestey;
intallotment(structlinknodehead);
boolcheckfifooptimal(structlinknode
head,intcheckpage);
voidrecover(structlinknodehead,intrandprocess);
voidrecovermemory;
intprocess[10][20];
//数组的横坐标为进程序列,纵坐标为每个进程的页号
intprocessallotment[6];
//存储每个进程已经分配的块数
intfinishp[6];
//标志进程是否完成(1完成0不完成)
intfinishprocess=0;
//进程完成的个数
intfindpage[6];
//每个进程命中的个数
structlinknodeplinkhead[6];
structlinknodeplink[6];
{
intmemoryallotment[6];
intstey=0;
structlinknodelinkper;
//空链表的前驱指针
intpage;
intprocesspage;
intused;
intmemorypage;
structlinknodelink;
//空链表的后继指针
structlinknodeprocessper;
//进程的前去指针
structlinknodeprocess;
//进程的后继指针
};
intmain
structlinknodehead=initlink;
initprocess;
choestey;
intre=allotment(head);
if(re==0)
{printf(“内存分配出现问题。
”);
system(“pause”);
}
chosedisplace;
recovermemory;
voidrecovermemory
intn=0;
printf(“是否回收全部已分配的内存空间?
\n回收输入1,不回收输入2\n”);
scanf(“d”,n);
if(n==1)
for(inti=1;
iused=0;
head=head->
process;
voidchoestey
printf(“请选择置换算法\n”);
printf(“1表示FIFO\n2表示Optimal\n3表示LRU\n”);
boolflag=true;
while(flag)
scanf(“d”,stey);
switch(stey)
case1:
{printf(“您选择的是FIFO替换算法\n”);
flag=false;
break;
case2:
{printf(“您选择的是Optimal替换算法\n”);
break;
case3:
{printf(“您选择的是LRU替换算法\n”);
}default:
printf(“输入错误,请重新输入\n”);
voidchosedisplace//选择置换算法
structlinknodehead;
intrandcount;
//进程序号
boolfind;
while(finishprocessmemorypage,p->
processpage,p->
page);
p=p->
ipage==checkpage)
returntrue;
head=head->
else
returnfalse;
LRU(structlinknodehead,intrandprocess)
structlinknodebhead;
bhead=head;
while(head->
process!
=0)
if(head->
page==process[randprocess][processallotment[randprocess]+1])break;
elsehead=head->
}if(head->
page!
=process[randprocess][processallotment[randprocess]+1])//没找到
bhead->
page=process[randprocess][processallotment[randprocess]+1];
head->
process=bhead;
processper=head;
bhead=bhead->
processper=0;
process=0;
{head->
process->
processper=head->
processper;
plink[randprocess]=plink[randprocess]->
returnbhead;
else//找到了
if(head==bhead)//头
processper=plink[randprocess];
plink[randprocess]->
process=head;
findpage[randprocess]++;
returnhead;
process==0)//尾
else//中间
processper->
process=head->
voidOptimal(structlinknodehead,intrandprocess)
structlinknodemap;
map=head;
intma=1,i;
while(head!
for(i=processallotment[randprocess]+1;
ipage)
if(i>
ma)
ma=i;
map->
fifo(structlinknodehead,intrandprocess)
structlinknodephead;
//改变后的头指针
phead=head;
process=phead;
phead->
phead=phead->
returnphead;
intallotment(structlinknodehead)//为进程分配内存
intallotsum=0;
//已经分配完进程的个数
号:
d\n“,head->
memorypage,head->
processpage,head->
d\n”,head->
intrandprocess;
//当前要分配内存的进程标号
boolboolallot[6];
iused==0)
if(processallotment[randprocess]==0)
plinkhead[randprocess]=head;
plink[randprocess]=head;
processpage=randprocess;
page=process[randprocess][1];
used=1;
printf(“内存块号:
d\t进程号:
d\t
link;
memoryallotment[randprocess]++;
bool
checksame=checkfifooptimal(plinkhead[randprocess],process[randprocess][processallotment[randprocess]+1]);
if(checksame==false)
process=head;
printf(”内存块号:
link;
if(stey==3)plinkhead[randprocess]=LRU(plinkhead[randprocess],randprocess);
p->
memorypage=1;
V
!
++LUnSlOIle
(^==[ssθ□ojdpuej]ιuθiιno∣∣ejθLUθLu)j!
ΘS∣Θ{
∣,=[ssθ□ojdpuej]dqs!
uu
++ssθ□ojdqsιuu
θ∏4=[ssθ□ojdpuej];
OIleIOOq
(ssθ□ojdpuej111u?
障準(强GPS≡JHUUd
([θ][ssθ□ojdpuej]ssθ□ojd==[ssθ□ojdpuej]ιuθiιno∣∣essθ□ojd)j!
:
0UJnlal
渝莎强GPS≡JHUUd
}(O==PEoII”!
ΘS∣Θ
++[ssθ□ojdpuej]ιuθiιno∣∣essθ□ojd
++[ssθ□ojdpuej]θ6edpuuθs∣θboolallot[randprocess]=true;
printf(”进程d分配成功\n“,randprocess);
structlinknodep;
printf(”初始内存分配情况:
\n“);
imemorypage,p->
return1;
voidinitprocess
intperrandcount;
process=NULL;
processper=NULL;
linkper=q;
link=NULL;
page=-1;
q->
link=p;
memorypage=i+1;
q=q->
intproducerand(intremainder)//产生随机数
randcount=(rand+(unsigned)time(NULL))remainder+1;
returnrandcount;
五、程序运行结果
六、实验体会这次的实验,我们了解到了请求页式虚存管理是常用的虚拟存储管理方案之一。
通过请求页式虚存管理中对页面置换算法的模拟,有助于理解虚拟存储技术的特点,并加深对请求页式虚存管理的页面调度算法的理解。
这次实验让我们对计算机操作系统的学习更进一步,我受益匪浅。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 虚拟 存储器 管理 方案 实验 报告