存储管理实验报告

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

广东海洋大学学生实验报告书(学生用表)实验名称存储管理课程名称操作系统课程号

学院(系)软件学院专业

软件工程班级

学生姓名学号实验地点实验日期

一、实验目的

修改MINIX操作系统内存管理的源程序,将MINIX的首次适应算法改为最佳适应和最差适应

算法,对修改之后的MINIX源代码进行重新编译和重新启动,以测试你修改的正确性。

二、实验内容

1、打开Minix3,进入alloc.c所在目录

2、修改原算法为最佳适应算法(BEST_FIT)和最差适应算法(WORST_FIT)的程序如下:

#include "pm.h"

#include

#include

#include

#include

#include "mproc.h"

#include "../../kernel/const.h"

#include "../../kernel/config.h"

#include "../../kernel/type.h"

#define NR_HOLES (2*NR_PROCS) /* max # entries in hole table */

#define NIL_HOLE (struct hole *) 0

PRIVATE struct hole {

struct hole *h_next; /* pointer to next entry on the list */

phys_clicks h_base; /* where does the hole begin? */

phys_clicks h_len; /* how big is the hole? */

} hole[NR_HOLES];

PRIVATE u32_t high_watermark=0;

PRIVATE struct hole *hole_head;/* pointer to first hole */

PRIVATE struct hole *free_slots;/* ptr to list of unused table slots */

#define swap_base ((phys_clicks) -1)

FORWARD _PROTOTYPE( void del_slot, (struct hole *prev_ptr, struct hole *hp) );

FORWARD _PROTOTYPE( void merge, (struct hole *hp) );

#define swap_out() (0)

GDOU-B-11-112

/*====================================================================== =====*

* alloc_mem *

*======================================================================= ====*/

PUBLIC phys_clicks alloc_mem(clicks)

phys_clicks clicks; /* amount of memory requested */

#define USING_BEST_FIT

#ifdef USING_BEST_FIT

{

//先找到第一个满足要求的空洞,

//再以第一个为标准寻找最适合的空洞。

//当最适合的空洞完全吻合

//就直接划给它,当空洞较大时就切割。

//首先注册目标指针、目标前一个指针、头指针

//记录目标大小和目前最适合大小

register struct hole *hp;

register struct hole *prevAim_ptr;

register struct hole *Aim_ptr;

phys_clicks old_base;

//如果循环一次都没找到

//就把可以退出内存的进程赶出去

//再循环

do{

hp = hole_head;

prevAim_ptr = NIL_HOLE;

Aim_ptr = NIL_HOLE;

for(;hp != NIL_HOLE && hp->h_base < swap_base;

prevAim_ptr=hp,hp=hp->h_next)

{

//find the best hole

if(hp->h_len == clicks)

{

old_base = hp->h_base; /* remember where it started */

hp->h_base += clicks; /* bite off */

hp->h_len -= clicks; /* ditto */

del_slot(prevAim_ptr, hp);/* Delete the hole which used up completely. */

/* Remember new high watermark of used memory. */

if(hp->h_base > high_watermark)

high_watermark = hp->h_base;

return(old_base);

}

//当从没记录过合适内存时

//把遇到的第一个合适节点保存在aim中

if(hp->h_len > clicks && Aim_ptr == NIL_HOLE)

{

Aim_ptr=hp;

}

//当找到一个比原来aim更合适的空间

//记录新的空间

if(hp->h_len > clicks && hp->h_len < Aim_ptr->h_len)

{

//mark it down

Aim_ptr=hp;

}

}

//we found it

if(Aim_ptr != NIL_HOLE)

{

old_base = Aim_ptr->h_base; /* remember where it started */

Aim_ptr->h_base += clicks; /* bite off */

Aim_ptr->h_len -= clicks; /* ditto */

/* Remember new high watermark of used memory. */

if(Aim_ptr->h_base > high_watermark)

high_watermark = Aim_ptr->h_base;

return(old_base);

}

}while(swap_out());

return(NO_MEM);

}

#endif

#ifdef USING_WORST_FIT

{

相关文档
最新文档