Linux操作系统实验报告存储管理试验参考模板.docx

上传人:b****7 文档编号:10009626 上传时间:2023-02-07 格式:DOCX 页数:17 大小:271.74KB
下载 相关 举报
Linux操作系统实验报告存储管理试验参考模板.docx_第1页
第1页 / 共17页
Linux操作系统实验报告存储管理试验参考模板.docx_第2页
第2页 / 共17页
Linux操作系统实验报告存储管理试验参考模板.docx_第3页
第3页 / 共17页
Linux操作系统实验报告存储管理试验参考模板.docx_第4页
第4页 / 共17页
Linux操作系统实验报告存储管理试验参考模板.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

Linux操作系统实验报告存储管理试验参考模板.docx

《Linux操作系统实验报告存储管理试验参考模板.docx》由会员分享,可在线阅读,更多相关《Linux操作系统实验报告存储管理试验参考模板.docx(17页珍藏版)》请在冰豆网上搜索。

Linux操作系统实验报告存储管理试验参考模板.docx

Linux操作系统实验报告存储管理试验参考模板

电子信息学院

实验报告书

课程名:

《Linux操作系统实验》

题目:

实验三存储管理试验

实验类别【验证】

班级:

BX0907

学号:

09

姓名:

吴沛儒

评语:

实验态度:

认真()一般()差()

实验结果:

正确()部分正确()错()

实验理论:

掌握()熟悉()了解()不懂()

操作技能:

强()一般()差()

实验报告:

好()一般()差()

成绩:

指导教师:

胡静

批阅时间:

年月日

成绩:

指导教师:

宁建红

批阅时间:

年月日

1、实验内容或题目

(1)模拟初始内存页面分配(数组、结构体均可)

(2)实现Buddyheap算法

(3)通过键盘输入随机产生申请和释放操作

∙请求:

r8代表申请8个页面。

∙释放:

f4代表释放4个页面。

(4)每个申请或释放操作,都在屏幕上显示操作前与操作后的内存分配的对比图。

(5)实验假设申请和释放的页数都是2的整次幂。

(1)建立工作集页面模型。

(2)利用随机函数动态生成进程访问页面的序列号。

(3)实现FIFO页面淘汰算法。

(4)实现页故障率反馈模型。

2、实验目的与要求

(1)用C语言是实现模拟Linux系统中连续内存分配用到的伙伴对算法。

(2)通过链表的形式输出在内存申请和释放过程中内存状态的对比图。

(1)了解工作集模型的原理及其特点。

(2)实现页故障率反馈模型。

3、实验步骤与源程序

1.Buddyheap算法模拟

源程序;

#include

#include

typedefstructblock

{

intsize;

intstart;

intloc;

structblock*next;

structblock*prior;

}block;

intmaxsize=512;

block*note;

block*id[10];

voidprintmem(){

inti;

for(i=9;i>=0;i--){

printf("%d->",i);

block*temp=(structblock*)malloc(sizeof(structblock));

temp=id[i]->next;

while(temp!

=NULL){

printf("%d(%s)(%d)->",temp->size,temp->loc==1?

"占用":

"空闲",temp->start);temp=temp->next;

}

printf("\n");

}

}

voidinit(){

inti;

for(i=0;i<9;i++){

id[i]=(structblock*)malloc(sizeof(structblock));

id[i]->prior=id[i];id[i]->next=NULL;

}

note=(structblock*)malloc(sizeof(structblock));

note->size=maxsize;

note->start=0;

note->loc=0;

note->next=NULL;

id[9]=(structblock*)malloc(sizeof(structblock));

id[9]->next=note;

id[9]->prior=id[9];

note->prior=id[9];

printmem();

}

intpower(intx,inty){

intk=0,tmp=1;

for(;k

tmp=tmp*x;

}

returntmp;

}

introot(intx,inty){

intresult=y,count=0;

while(result!

=1){

result=result/x;

count++;

}

returncount;

}

intsplit(inttempId){

block*pend=(structblock*)malloc(sizeof(structblock));

block*cend=(structblock*)malloc(sizeof(structblock));

block*newf=(structblock*)malloc(sizeof(structblock));

block*newu=(structblock*)malloc(sizeof(structblock));

pend=id[tempId]->next;

intflag=0,isFirst=0;

while(pend!

=NULL){

if(pend->loc==0){

if(isFirst==0){

id[tempId]->next=pend->next;

}else{

pend->prior->next=pend->next;

}

intsize=(pend->size)/2;

intstart=pend->start;

newu->size=size;

newu->start=start;

newf->start=start+size;

newu->loc=0;

newf->size=size;

newf->loc=0;

newf->prior=newu;

newu->next=newf;

newf->next=NULL;

tempId--;

cend=id[tempId];

while(cend->next!

=NULL){

cend=cend->next;

}

cend->next=newu;

newu->prior=cend;

flag=1;

return1;

}else{

pend=pend->next;

isFirst++;

}

}

if(flag==0){

tempId=tempId+1;

if(tempId<=9){

free(pend);free(cend);free(newu);free(newf);

split(tempId);

}else{

return-1;

}

}

}

intmerge(inttempId,block*first){

block*merger=(structblock*)malloc(sizeof(structblock));

block*second=NULL;

second=id[tempId]->next;

intnextStart=first->start+first->size;

intpreStart=first->start-first->size;

intflag=0,isFirst=0;

while(second!

=NULL){

if((second->start==nextStart||second->start==preStart)&&second->loc==0){

merger->size=(first->size)+(second->size);

merger->loc=0;

merger->start=(first->start)<(second->start)?

(first->start):

(second->start);

if(first->next!

=NULL){

first->next->prior=first->prior;

}

if((first->prior->prior)==first->prior){

id[tempId]->next=first->next;

}else{

first->prior->next=first->next;

}

if(second->next!

=NULL){

second->next->prior=second->prior;

}

if(isFirst==0){

id[tempId]->next=second->next;

}else{

second->prior->next=second->next;

}

tempId++;

merger->next=id[tempId]->next;

merger->prior=id[tempId];

if(id[tempId]->next!

=NULL)id[tempId]->next->prior=merger;

id[tempId]->next=merger;

if(tempId<9){

merge(tempId,merger);

}else{

return0;

}

return1;

}else{

second=second->next;

isFirst++;

}

}

return1;

}

intfreeb(intsize){

block*first=(structblock*)malloc(sizeof(structblock));

inttempId=root(2,size);

first=id[tempId]->next;

intflag=0;

while(first!

=NULL){

if(first->loc==1){

first->loc=0;

flag=1;

break;

}else{

first=first->next;

}

}

if(flag==1){

merge(tempId,first);

printmem();

}else{

printf("需要释放的内存块不存在!

\n");

}

return1;

}

intrequestb(intsize){

block*temp=(structblock*)malloc(sizeof(structblock));

inttempId=root(2,size);

intflag=0;

temp=id[tempId]->next;

while(temp!

=NULL){

if(temp->loc==0&&temp->size==size){

temp->loc=1;

flag=1;

printf("分配成功!

\n");

printmem();

return1;

}else{

temp=temp->next;

}

}

if(flag==0){

tempId++;

if(tempId<=9){

intrs=split(tempId);

if(rs==-1){

printf("没有合适的空间可分配!

\n");

return-1;

}else{

requestb(size);

}

}else{

printf("没有合适的空间可分配!

\n");

return-1;

}

}

free(temp);

}

intmain(){

init();

intflag=1;

intsize;

charorder;

do{

printf("请输入命令:

(以空格相隔,示例:

r8)\n");

scanf("%c%d",&order,&size);

if(order=='r'){

requestb(size);

}elseif(order=='f'){

freeb(size);

}else{

printf("error!

");

}

printf("是否继续?

(1继续,0退出):

");

scanf("%d",&flag);

getchar();

}while(flag==1);

}

结果图:

2.页故障率反馈模型

源程序;

#include

#include

#include

#defineMAX_WORKSET10

#defineWINDOW_SIZE20

intmempage=10;

intprocArray[WINDOW_SIZE];

intwin[MAX_WORKSET][2];

doublemaxRate=0.8,minRate=0.2;

doublecurRate;

intcur_workset=3;

intconflictCount=0;

voidprint(){

curRate=(double)conflictCount/(double)WINDOW_SIZE;

printf("缺页故障率:

%g,故障率上限/下限:

%g/%g\n",curRate,maxRate,minRate);

}

voidchangeArray(){

inti;

for(i=0;i

procArray[i]=rand()%mempage;

}

printf("进程调用页面序列:

");

for(i=0;i

printf("%d|",procArray[i]);

}

printf("\n");

}

voidinit(){

inti,j;

//changeArray();

for(i=0;i

win[i][0]=-1;

win[i][1]=cur_workset;

}

}

voidchangePage(intnumber){

inti,flag=0;

for(i=1;i

if(win[flag][1]<=win[i][1]){

flag=i;

}

}

win[flag][0]=procArray[number];

win[flag][1]=1;

conflictCount++;

for(i=0;i

if(i!

=flag&&win[i][1]!

=-1){

win[i][1]++;

}

}

}

voidstep(intnumber){

inti,hit=0;

for(i=0;i

if(procArray[number]==win[i][0]){

//number++;

hit=1;

break;

}

}

if(hit==0){

changePage(number);

}

}

voidrun(){

inti;

conflictCount=0;

changeArray();

for(i=0;i

step(i);

}

printf("冲突次数:

%d,",conflictCount);

}

voidfeedback(){

curRate=(double)conflictCount/(double)WINDOW_SIZE;

if(curRate>maxRate){

cur_workset++;

}elseif(curRate

cur_workset--;

}

}

intmain(){

init();

charquit;

do{

run();

print();

feedback();

printf("输入任意字符继续,q退出\n");

scanf("%c",&quit);

getchar();

}while(quit!

='q');

}

4、结果分析与实验体会

存储管理是操作系统中最重要的组成部分之一。

在早期计算时代,由于人们所需要的内存数目远远大于物理内存,人们设计出了各种各样的策略来解决此问题,其中最成功的是虚拟内存技术。

它使得系统中为有限物理内存竞争的进程所需内存空间得到满足。

我们以BuddyHeap算法为例,实现模拟Linux系统中连续内存分配。

BH算法具有速度快的明显特点,同时解决了外碎片问题,但带来内碎片,这是由于实际请求一般不能恰好与2i相对应,此时必须向上取整。

对于更大块的请求内碎片的浪费更严重。

为此Linux将剩余的内碎片按2j整数次幂切片并由二次分配器进行单独管理。

此外当进程物理空间不要求连续时,内存分配由第三分配器完成。

此外,这个实验还需要很好的理解FIFO算法,这是最简单的页面淘汰算法,在实现时,对应每一个页面需要有一个调入时间,该时间可设在内存中并用软件记录,不过最好设在寄存器中并由硬件记录。

当内存空间紧张时,调入时间最早的页面将被淘汰。

FIFO算法易于理解和编程,但它的效率不高。

被置换的页面可能存有一个初始化程序段,很早以前曾用到,以后不会再用到;但也可能存有一组经常访问的全局变量,初始化时被调入内存,在整个程序运行过程中都将会用到。

这次实验难点在理论方面,在理解了之后操作比较顺利。

友情提示:

范文可能无法思考和涵盖全面,供参考!

最好找专业人士起草或审核后使用,感谢您的下载!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1