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

上传人:小飞机 文档编号:3160653 上传时间:2023-03-11 格式:DOCX 页数:15 大小:40.67KB
返回 下载 相关 举报
Linux操作系统实验报告 存储管理试验.docx_第1页
第1页 / 共15页
Linux操作系统实验报告 存储管理试验.docx_第2页
第2页 / 共15页
Linux操作系统实验报告 存储管理试验.docx_第3页
第3页 / 共15页
Linux操作系统实验报告 存储管理试验.docx_第4页
第4页 / 共15页
Linux操作系统实验报告 存储管理试验.docx_第5页
第5页 / 共15页
亲,该文档总共15页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Linux操作系统实验报告 存储管理试验.docx》由会员分享,可在线阅读,更多相关《Linux操作系统实验报告 存储管理试验.docx(15页珍藏版)》请在三一办公上搜索。

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

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

3、de #include typedef struct block int start; int loc; struct block *next; struct block *prior; int size; block; Linux操作系统实验报告 - 2 - int maxsize=512; block *note; block *id10; void printmem int i; for(i=9; i=0;i-) printf(%d -,i); block); int power(int x,int y) int root(int x,int y) int result=y,count=

4、0; while(result!=1) return count; result=result/x; count+; int k=0,tmp=1; for(;knext=note; id9-prior=id9; note-prior=id9; printmem; block * temp = (struct block *)malloc(sizeof(struct block); temp = idi-next; while(temp!=NULL) printf(%d(%s)(%d)-,temp-size,temp-loc=1?占用:空闲,temp-start); temp=temp-next

5、; void init int i; for(i=0;inext; int flag=0,isFirst=0; idi-prior=idi;idi-next=NULL; note=(struct block *)malloc(sizeof(struct block); note-size=maxsize; note-start=0; note-loc=0; note-next=NULL; id9=(struct block *)malloc(sizeof(struct Linux操作系统实验报告 - 3 - while(pend!=NULL) if(pend-loc=0) if(isFirst

6、=0) isFirst+; idtempId-next=pend-next; else if(flag=0) tempId=tempId+1; if(tempIdprior-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-loc=0; newf-prior=newu; newu-next=newf; newf-next=NULL; tempI

7、d-; cend=idtempId; free(pend);free(cend);free(newu);free(newf); split(tempId); else return -1; int merge(int tempId,block *first) block * merger=(struct block *)malloc(sizeof(struct block); block * second=NULL; second=idtempId-next; int nextStart=first-start+first-size; int preStart=first-start-firs

8、t-size; int flag=0,isFirst=0; while(second!=NULL) while(cend-next!=NULL) cend-next=newu; newu-prior=cend; flag=1; return 1; cend=cend-next; if(second-start=nextStart | second-start=preStart) & second-loc=0) ; merger-size=(first-size)+(second-size) merger-loc=0; else pend=pend-next; merger-start=(fir

9、st-start)start)?(first-start):(second-start); Linux操作系统实验报告 - 4 - if(first-next!=NULL) return 1; first-next-prior=first-prior; int freeb(int size) block * first=(struct block *)malloc(sizeof(struct block); int tempId=root(2,size); first=idtempId-next; int flag=0; while(first!=NULL) if(flag=1) merge(

10、tempId,first); printmem; if(first-loc=1) first-loc=0; flag=1; break; return 1; else second=second-next; isFirst+; if(first-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-ne

11、xt; else second-prior-next=second-next; tempId+; else first=first-next; merger-next=idtempId-next; merger-prior=idtempId; if(idtempId-next!=NULL) idtempId-next-prior=merger; idtempId-next=merger; if(tempIdnext; while(temp!=NULL) 配!n); return -1; free(temp); int main init; int flag=1; int size; char

12、order; do if(temp-loc=0 & temp-size=size) if(flag=0) tempId+; if(tempIdloc=1; flag=1; printf(分配成功!n); printmem; return 1; printf(请输入命令:(以空格相隔,示例:r 8)n); scanf(%c %d,&order,&size); if(order=r) requestb(size); else temp=temp-next; else if(order=f) freeb(size); else printf(是否继续?(1继续,0退printf(error!); 分

13、配!n); 出):); scanf(%d,&flag); getchar; return -1; else requestb(size); while(flag=1); 结果图: Linux操作系统实验报告 - 2 - 2. 页故障率反馈模型 Linux操作系统实验报告 - 3 - 源程序; #include #include #include #define MAX_WORKSET 10 #define WINDOW_SIZE 20 int mempage=10; int procArrayWINDOW_SIZE; int winMAX_WORKSET2; double maxRate=0.

14、8,minRate=0.2; double curRate; int cur_workset=3; int conflictCount=0; void print curRate=(double)conflictCount/(double)WINDOW_SIZE; printf(缺页故障率:%g,故障率上限/下限:%g/%gn,curRate,maxRate,minRate); void changeArray void init int i,j; /changeArray; for(i=0;iMAX_WORKSET;i+) wini0=-1; wini1=cur_workset; void

15、changePage(int number) void step(int number) int i,hit=0; for(i=0;icur_workset;i+) if(procArraynumber = wini0) /number+; hit=1; break; int i,flag=0; for(i=1;icur_workset;i+) winflag0=procArraynumber; winflag1=1; conflictCount+; for(i=0;icur_workset;i+) if(i!=flag & wini1!=-1) wini1+; if(winflag1 = w

16、ini1) flag=i; int i; for(i=0;iWINDOW_SIZE;i+) printf(进程调用页面序列:); for(i=0;iWINDOW_SIZE;i+) printf(n); printf(%d|,procArrayi); procArrayi=rand%mempage; Linux操作系统实验报告 - 2 - cur_workset+; else if(curRatemaxRate) int i; conflictCount=0; changeArray; for(i=0;iWINDOW_SIZE;i+) printf(冲突次数:%d,conflictCount);

17、 step(i); n); scanf(%c,&quit); getchar; while(quit != q); Linux操作系统实验报告 - 2 - 4、 结果分析与实验体会 存储管理是操作系统中最重要的组成部分之一。在早期计算时代,由于人们所需要的内存数目远远大于物理内存,人们设计出了各种各样的策略来解决此问题,其中最成功的是虚拟内存技术。它使得系统中为有限物理内存竞争的进程所需内存空间得到满足。我们以Buddy Heap算法为例,实现模拟Linux系统中连续内存分配。BH算法具有速度快的明显特点,同时解决了外碎片问题,但带来内碎片,这是由于实际请求一般不能恰好与2相对应,此时必须向上

18、取整。对于更大块的请求内碎片的浪费更严重。为此Linux将剩余的内碎片按2整数次幂切片并由二次分配器进行单独管理。此外当进程物理空间不要求连续时,内存分配由第三分配器完成。此外,这个实验还需要很好的理解FIFO算法,这是最简单的页面淘汰算法,在实现时,对应每一个页面需要有一个调入时间,该时间可设在内存中并用软件记录,不过最好设在寄存器中并由硬件记录。当内存空间紧张时,调入时间最早的页面将被淘汰。FIFO算法易于理解和编程,但它的效率不高。被置换的页面可能存有一个初始化程序段,很早以前曾用到,以后不会再用到;但也可能存有一组经常访问的全局变量,初始化时被调入内存,在整个程序运行过程中都将会用到。这次实验难点在理论方面,在理解了之后操作比较顺利。 ji

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

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号