Linux操作系统实验报告存储管理试验_第1页
Linux操作系统实验报告存储管理试验_第2页
Linux操作系统实验报告存储管理试验_第3页
Linux操作系统实验报告存储管理试验_第4页
Linux操作系统实验报告存储管理试验_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、电子信息学院实验报告书课程名:Linux操作系统实验题目:实验三存储管理试验实验类别【验证】班级:BX0907学号:09姓名:吴沛儒评语:实验态度认真()一()差()实验结果正确()部分正确()错()实验理论掌握()熟悉()了解()不懂()操作技能强()一()差()实验报告好()一()差()成绩:一指导教师:胡靛批阅时间:月日« Linux操作系统实验报告-10 -1、实验内容或题目(1)模拟初始内存页面分配(数组、结构体均可)(2)实现Buddyheap算法(3)通过键盘输入随机产生申请和释放操作?请求:r8代表申请8个页面。?释放:f4代表释放4个页面。(4)每个申请或释放操作,

2、都在屏幕上显示操作前与操作后的内存分配的对比图(5)实验假设申请和释放的页数都是2的整次幕。(1)建立工作集页面模型。(2)利用随机函数动态生成进程访问页面的序列号。(3)实现FIFO页面淘汰算法。(4)实现页故障率反馈模型。2、 实验目的与要求(1)用C语言是实现模拟Linux系统中连续内存分配用到的伙伴对算法。(2) 通过链表的形式输出在内存申请和释放过程中内存状态的对比图。(1)了解工作集模型的原理及其特点(2)实现页故障率反馈模型。3、 实验步骤与源程序1.Buddyheap算法模拟源程序;int start;int loc;struct block *next;struct bloc

3、k *prior;#include<stdio.h>#include<stdlib.h>typedefstructblockintmaxsize=512;block*note;block*id10;voidprintmem()inti;for(i=9;i>=0;i-)printf("%d->”,i);block*temp=(structblock*)malloc(sizeof(structblock);temp=idi->next;while(temp!=NULL)printf("%d(%s)(%d)->",temp

4、->size,temp->loc=1?"占用":"空闲",temp->start);temp=temp->next;printf("n");voidinit()inti;for(i=0;i<9;i+)idi=(structblock*)malloc(sizeof(structblock);idi->prior=idi;idi->next=NULL;note=(structblock*)malloc(sizeof(structblock);note->size=maxsize;note-&

5、gt;start=0;note->loc=0;note->next=NULL;block);id9->next=note;id9->prior=id9;note->prior=id9;printmem();int power(int x,int y)int k=0,tmp=1;for(;k<y;k+)tmp=tmp*x;return tmp;int root(int x,int y)int result=y,count=0;while(result!=1)result=result/x;count+;return count;int split(int te

6、mpId)block * pend=(struct block *)malloc(sizeof(struct block);block * cend=(struct block *)malloc(sizeof(struct block);block * newf=(struct block *)malloc(sizeof(struct block);block * newu=(struct block *)malloc(sizeof(struct block);pend=idtempId->next;int flag=0,isFirst=0;id9=(structblock*)mallo

7、c(sizeof(structwhile(pend!=NULL)if(pend->loc=0)if(isFirst=0)idtempId->next=pend->next;else pend->prior->next=pend->next;int size=(pend->size)/2;int start=pend->start;newu->size=size;newu->start=start;newf->start=start+size;newu->loc=0;newf->size=size;newf->l

8、oc=0;newf->prior=newu;newu->next=newf;newf->next=NULL;tempId-;cend=idtempId;while(cend->next!=NULL)cend=cend->next;cend->next=newu;newu->prior=cend;flag=1;return 1;else pend=pend->next;isFirst+;if(flag=0)tempId=tempId+1;if(tempId<=9)free(pend);free(cend);free(newu);free(ne

9、wf);split(tempId);elsereturn-1;intmerge(inttempId,block*first)block*merger=(structblock*)malloc(sizeof(structblock);block*second=NULL;second=idtempId->next;intnextStart=first->start+first->size;intpreStart=first->start-first->size;intflag=0,isFirst=0;while(second!=NULL)if(second->s

10、tart=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(fi

11、rst->prior->prior)=first->prior)idtempId->next=first->next;else first->prior->next=first->next;if(second->next!=NULL)second->next->prior=second->prior;if(isFirst=0)idtempId->next=second->next;elsesecond->prior->next=second->next;tempId+;merger->n

12、ext=idtempId->next;merger->prior=idtempId;if(idtempId->next!=NULL) idtempId->next->prior=merger;idtempId->next=merger;if(tempId<9)merge(tempId,merger);else return 1;else second=second->next;isFirst+;return 1;int freeb(int size)block * first=(struct block *)malloc(sizeof(struc

13、t block);int tempId=root(2,size);first=idtempId->next;int flag=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");return0;return 1;int requestb(int size)block * temp=(struct

14、 block *)malloc(sizeof(struct block);int tempId = root(2,size);int flag=0;temp=idtempId->next;while(temp!=NULL)if(temp->loc=0 && temp->size=size)temp->loc=1;flag=1;printf("分配成功!n");printmem();return 1;elsetemp=temp->next;if(flag=0)tempId+;if(tempId<=9)int rs=split

15、(tempId);if(rs=-1) printf("没有合适的空间可 分配!n");return -1;else requestb(size);else printf("没有合适的空间可分 配!n");return -1;free(temp);int main()init();int flag=1;int size;char order;doprintf("请输入命令:(以空格相隔,示 例:r 8)n");scanf("%c %d",&order,&size);if(order='r

16、9;)requestb(size);else if(order='f)freeb(size);elseprintf("error!");printf("是否继续?(1继续,0退出):");scanf("%d",&flag);getchar();while(flag=1);结果图:室fajackiejackie-Laptop:-文件的想腾旧查看W)度索罐跳河窜助(用jacktejackte-laptop:gcc-obuddybuddy.cjacktejackte-laptop:./buddy94512(空阑)(©

17、;)08*A5>4>3>2<>1*)&蛹人皓令M以空格相隰,示例:s)riza分配成功!9>B'空闲)(”6)->7-128(占用)(6)-Z2S(空闲)(128)->6"争5->4>3->2->1->是否立续?(请1续,日退出):1请输入命令:(以空格相嗣,示例:用r64分配成功!.f管jackie9jackie-lapt4p:-文件(F)编辑旧查看促)攫素缰需部助(川请输入命令:(以空格相隔,示例:8)f649->S->7-占用)(0)0125(占用)(256)>12”

18、空闹)(324)-0*(空闹)(")>64(占用)(192)->5>4>3->221*A0*是否继续?(1鲜续,日退出)二1请输入命令:(以空格相晴,示例"B)f649aE>_71Z8(空阑)(1工8)7128(占用)(。”123(占用)(256)>128(空阑“384”>C-5A4.>t3f2->1 ->受否热续?(1维续,白退出):1请输入命令:(以空格相隔,示例力8)fl282 .页故障率反馈模型源程序;#include <stdio.h>#include <malloc.h>#

19、include <stdlib.h>#define MAX_WORKSET 10#define WINDOW_SIZE 20int mempage=10;int procArrayWINDOW_SIZE;int winMAX_WORKSET2;double maxRate=0.8,minRate=0.2;double curRate;int cur_workset=3;int conflictCount=0;void print()curRate=(double)conflictCount/(double) WINDOW_SIZE;printf("缺页故障率:g,故障率上

20、限/下 限:%g/%gn",curRate,maxRate,minRate);void changeArray()int i;for(i=0;i<WINDOW_SIZE;i+)procArrayi=rand()%mempage;printf("进程调用页面序列:");for(i=0;i<WINDOW_SIZE;i+)printf("%d|",procArrayi);printf("n");void init()int i,j;changeArray();for(i=0;i<MAX_WORKSET;i+)wi

21、ni0=-1;wini1=cur_workset;void changePage(int number)int i,flag=0;for(i=1;i<cur_workset;i+)if(winflag1 <= wini1) flag=i;winflag0=procArraynumber;winflag1=1;conflictCount+;for(i=0;i<cur_workset;i+)if(i!=flag && wini1!=-1) wini1+;void step(int number)int i,hit=0;for(i=0;i<cur_workse

22、t;i+)if(procArraynumber = wini0) number+;hit=1;break;if(hit=0)changePage(number);void run()int i;conflictCount=0;changeArray();for(i=0;i<WINDOW_SIZE;i+)step(i);printf("冲突次数:d,",conflictCount);void feedback()curRate=(double)conflictCount/(double) WINDOW_SIZE;cur_workset+;else if(curRate&

23、lt;minRate)cur_workset-;int main()init();char quit;dorun();print();feedback。;printf("输入任意字符继续,q退出 n");scanf("%c",&quit);getchar();while(quit != 'q');if(curRate>maxRate)萼6Ljackle(Wjackle-laptop:h又件旧酝辑(E)直看1%摆姿格)绕岫理由(H)jackicjdckte-laptopgcc-owsnratewsnrate,cJackteJackte-laptop./wsnrate进程调用内面序列:3|6|7|5|3|5|6|2|9|l|2|7|fl|9|3|6|B|6|2|6|冲突次数:16,缺页故障率:0.8,故障率上限/下限;0.8/0.2辅人任邕字符辞续.。退出进程调用页面序列:1|B|7|9|Z|«|Z|3J7|5|9|ZJ2|

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论