FIFO、LRU、OPT的三个简单实现

1.利用随机数产生一个指令序列,共320条指令。其地址按下述原则生成:
①50%的指令是顺序执行的;
②25%的指令是均匀分布在前地址部分;
③25%的指令是均匀分布在后地址部分;
Instruction.java源代码:
package instructions; import java.util.ArrayList; /** * The instruction class. * @author DigitalSonic */ public class Instruction { private String name = null; private boolean inSequence = false; private ArrayList<Instruction> list = null; /** * Construct the instruction with a specified name. * @param Name The name of the instruction. */ public Instruction(String Name) { this.name = Name; } /** * Add the instruction to the sequence. * @param List the instruction sequence */ public void addToList(ArrayList List) { this.list = List; this.inSequence = true; List.add(this); } /** * Remove the instruction from the sequence. */ public void removeFromList() { this.list.remove(this); this.list = null; this.inSequence = false; } /** * Getter for property name. * @return Value of property name. */ public String getName() { return name; } /** * Getter for property inSequence. * @return Value of property inSequence. */ public boolean isInSequence() { return this.inSequence; } }
Sequence.java源代码:
package instructions; import java.util.ArrayList; /** * The instructions sequence class. * @author DigitalSonic */ public class Sequence { private Instruction[] instructions; private ArrayList<Instruction> list = new ArrayList<Instruction>(Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT); /** * Construct the sequence with the given instructions * @param Instructions The instructions used to construct the sequence. */ public Sequence(Instruction[] Instructions) { this.instructions = Instructions; generateSequence(); } /** * Print the sequence. */ public void printSequence() { for (int i = 0; i < Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; i++) { System.out.print(list.get(i).getName() + " "); } } /** * Getter for property instructions. * @return Value of property instructions. */ public Instruction[] getInstructions() { return instructions; } /** * Setter for property instructions. * @param instructions New value of property instructions. */ public void setInstructions(Instruction[] instructions) { this.instructions = instructions; } /** * Getter for property list. * @return Value of property list. */ public java.util.ArrayList<Instruction> getList() { return list; } /** * Setter for property list. * @param list New value of property list. */ public void setList(java.util.ArrayList list) { this.list = list; } private void generateSequence() { list.clear(); try { instructions[getRandom(0, Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT)].addToList(list); for (int i = 1; i< Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; i++) getNextInstruction(list.get(i - 1)).addToList(list); } catch (IndexOutOfBoundsException ex) { generateSequence(); } } private Instruction getNextInstruction(Instruction Current) throws IndexOutOfBoundsException { Instruction Next = null; if (Math.random() < 0.5) { Next = instructions[Integer.parseInt(Current.getName()) + 1]; } else { int Min, Max; if (Math.random() < 0.5) { Min = 0; Max = (int)(Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT * 0.5); } else { Min = (int)(Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT * 0.5); Max = Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; } while (Next == null) if (!instructions[getRandom(Min,Max)].isInSequence()) Next = instructions[getRandom(Min,Max)]; } return Next; } private int getRandom(int Min, int Max) { return (int)((Max - Min) * Math.random() + Min); } }  

2.  指令序列变换成页地址流
设:页面大小为1K; 用户虚存容量为32K。
在用户虚存中,按每1K存放10条指令排列虚存地址,即320条指令在虚存中的存放方式为:
第0条—第9条指令为第0页(对应虚存地址为[0,9]);
第10条—第19条指令为第1页(对应虚存地址为[10,19]); 
310条—第319条指令为第31页(对应虚存地址为[310,319]);
按以上方式,用户指令可组成32页。
Page.java源代码:
package instructions; /** * The page that stores instructions. * @author DigitalSonic */ public class Page { /** * The total count of the instructions stored in this page. */ public static final int PAGE_SIZE = 10; private Instruction[] instructions = null; private int visitTime; /** * Creates a new instance of Page. * @param Instructions The instructions stored in this page. */ public Page(Instruction[] Instructions) { this.instructions = Instructions; } /** * Getter for property instructions. * @return Value of property instructions. */ public Instruction[] getInstructions() { return this.instructions; } /** * Getter for property visitTime. * @return Value of property visitTime. */ public int getVisitTime() { return this.visitTime; } /** * Setter for property visitTime. * @param visitTime New value of property visitTime. */ public void setVisitTime(int visitTime) { this.visitTime = visitTime; } }
VirtualMemory.java源代码:
package instructions; /** * The virtual page memory. * @author DigitalSonic */ public class VirtualMemory { /** * The total count of the pages in this virtual memory. */ public static final int TOTAL_PAGE_COUNT = 32; /** * The count of the pages that user has. */ public static int UserPagesCount = 0; private Instruction[] instructions = null; private Page[] pages = null; private Page[] userPages = null; private int currentEmptyIndex; /** * Creates a new instance of VirtualMemory. */ public VirtualMemory() { int m, n; Instruction[] Tmp; Page[] Pages = new Page[TOTAL_PAGE_COUNT]; //generate instructions instructions = new Instruction[Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT]; for (int i = 0; i < Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; i++) instructions[i] = new Instruction(Integer.toString(i)); //generate pages for (m = 0; m < TOTAL_PAGE_COUNT; m++) { Tmp = new Instruction[Page.PAGE_SIZE]; for (n = 0; n < Page.PAGE_SIZE; n++) Tmp[n] = instructions[m * Page.PAGE_SIZE + n]; Pages[m] = new Page(Tmp); } this.pages = Pages; } /** * Creates a new instance of VirtualMemory. * @param Pages The memory pages stored in this virtual memory. */ public VirtualMemory(Page[] Pages) { this.pages = Pages; } /** * Getter for property pages. * @return Value of property pages. */ public Page[] getPages() { return this.pages; } /** * Getter for property instructions. * @return Value of property instructions. */ public Instruction[] getInstructions() { return this.instructions; } /** * Setter for property instructions. * @param instructions New value of property instructions. */ public void setInstructions(Instruction[] instructions) { this.instructions = instructions; } /** * Getter for property userPages. * @return Value of property userPages. */ public Page[] getUserPages() { return this.userPages; } /** * Setter for property userPages. * @param userPages New value of property userPages. */ public void setUserPages(Page[] userPages) { this.userPages = userPages; UserPagesCount = userPages.length; } /** * Initialize the user pages. */ public void initUserPages() { initUserPages(this.UserPagesCount); } /** * Initialize the user pages. * @param Count The count of the user pages. */ public void initUserPages(int Count) { this.UserPagesCount = Count; this.userPages = new Page[Count]; this.currentEmptyIndex = 0; } /** * Getter for property currentEmptyIndex. * @return Value of property currentEmptyIndex. */ public int getCurrentEmptyIndex() { return this.currentEmptyIndex; } /** * Setter for property currentEmptyIndex. * @param currentEmptyIndex New value of property currentEmptyIndex. */ public void setCurrentEmptyIndex(int currentEmptyIndex) { this.currentEmptyIndex = currentEmptyIndex; } }

3.  计算并输出下述各种算法在不同内存容量(用户内存容量为4页到32页)下的缺页率。
A.  FIFO先进先出的算法
B.  LRU最近最少使用算法
C.  OPT最佳淘汰算法
Algorithm.java源代码:
package instructions.algorithm; import instructions.*; /** * The abstract class represents algorithm. * @author DigitalSonic */ public abstract class Algorithm { private int lackCount = 0; protected String name; protected int userPagesCount = 0; protected VirtualMemory VM = null; protected Sequence seq = null; /** * Creates a new instance of Algorithm */ public Algorithm(int UserPagesCount, Sequence Seq, VirtualMemory VM) { this.userPagesCount = UserPagesCount; this.seq = Seq; this.VM = VM; } /** * To check whether the page is in the user pages. * @param page The wanted page. * @return True if the page is in the user pages, else it returns false. */ public boolean isPageInUserPages(Page page) { Page[] Pages = VM.getUserPages(); boolean Flag = false; for (int i = 0; i < Pages.length; i++) { if (Pages[i] == page) { Flag = true; break; } } if (!Flag) lackCount++; return Flag; } /** * The execution part of the algorithm. */ public void execute() { Page TargetPage = null; VM.initUserPages(userPagesCount); for (int i = 0; i < seq.getList().size(); i++) { TargetPage = VM.getPages()[Integer.parseInt(seq.getList().get(i).getName()) / Page.PAGE_SIZE]; TargetPage.setVisitTime(i); if (!isPageInUserPages(TargetPage)) replacePage(TargetPage); } System.out.println("Lack page count:" + (getLackCount() - userPagesCount) + " Rate:" + 100 * ((double)(getLackCount() - userPagesCount) / (double)seq.getList().size()) + "%"); } /** * Replace a page with the new one. * @param NewPage The page ready to be inserted. */ public abstract void replacePage(Page NewPage); /** * Getter for property name. * @return Value of property name. */ public String getName() { return this.name; } /** * Getter for property userPagesCount. * @return Value of property userPagessCount. */ public int getUserPagesCount() { return this.userPagesCount; } /** * Getter for property VM. * @return Value of property VM. */ public VirtualMemory getVM() { return this.VM; } /** * Getter for property seq. * @return Value of property seq. */ public Sequence getSeq() { return this.seq; } /** * Getter for property lackCount. * @return Value of property lackCount. */ public int getLackCount() { return this.lackCount; } }
FIFO.java源代码:
package instructions.algorithm; import instructions.*; /** * The implementation of "First In First Out" algorithm. * @author DigitalSonic */ public class FIFO extends Algorithm { /** * Creates a new instance of FIFO */ public FIFO(int UserPagesCount, Sequence Seq, VirtualMemory VM) { super(UserPagesCount, Seq, VM); this.name = "FIFO"; } /** * Replace a page with the new one. * @param NewPage The page ready to be inserted. */ public void replacePage(Page NewPage) { if (VM.getCurrentEmptyIndex() != VM.UserPagesCount) { VM.getUserPages()[VM.getCurrentEmptyIndex()] = NewPage; VM.setCurrentEmptyIndex(VM.getCurrentEmptyIndex() + 1); } else { VM.getUserPages()[findFIPage(VM.getUserPages())] = NewPage; } } private int findFIPage(Page[] Pages) { int Index = Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; for (int i = 0; i < Pages.length; i++) { if (Pages[i].getVisitTime() < Index) Index = i; } return Index; } }
LRU.java源代码:
package instructions.algorithm; import instructions.*; /** * The implementation of "Least Recently Used" algorithm. * @author DigitalSonic */ public class LRU extends Algorithm { /** * Creates a new instance of LRU */ public LRU(int UserPagesCount, Sequence Seq, VirtualMemory VM) { super(UserPagesCount, Seq, VM); this.name = "LRU"; } /** * Replace a page with the new one. * @param NewPage The page ready to be inserted. */ public void replacePage(Page NewPage) { if (VM.getCurrentEmptyIndex() != VM.UserPagesCount) { VM.getUserPages()[VM.getCurrentEmptyIndex()] = NewPage; VM.setCurrentEmptyIndex(VM.getCurrentEmptyIndex() + 1); } else { VM.getUserPages()[findLRUPage(VM.getUserPages(), NewPage.getVisitTime())] = NewPage; } } private int findLRUPage(Page[] Pages, int CurrentInstruction) { int[] Count = new int[Pages.length]; Page page; for (int m = 0; m < Pages.length; m++) { Count[m] = 0; page = Pages[m]; for (int n = 0; n < CurrentInstruction && n < seq.getList().size(); n++) { if (page == VM.getPages()[Integer.parseInt(seq.getList().get(n).getName()) / Page.PAGE_SIZE]) Count[m]++; } } return findMin(Count); } private int findMin(int[] Count) { int Min = Page.PAGE_SIZE * VirtualMemory.TOTAL_PAGE_COUNT; int Index = 0; for (int i = 0; i < Count.length; i++) { if (Count[i] < Min) { Min = Count[i]; Index = i; } } return Index; } }
OPT.java源代码:
package instructions.algorithm; import instructions.*; /** * The implementation of "Optimal" algorithm. * @author DigitalSonic */ public class OPT extends Algorithm { /** * Creates a new instance of OPT */ public OPT(int UserPagesCount, Sequence Seq, VirtualMemory VM) { super(UserPagesCount, Seq, VM); this.name = "OPT"; } /** * Replace a page with the new one. * @param NewPage The page ready to be inserted. */ public void replacePage(Page NewPage) { if (VM.getCurrentEmptyIndex() != VM.UserPagesCount) { VM.getUserPages()[VM.getCurrentEmptyIndex()] = NewPage; VM.setCurrentEmptyIndex(VM.getCurrentEmptyIndex() + 1); } else { VM.getUserPages()[findUnusedPage(VM.getUserPages(), NewPage.getVisitTime())] = NewPage; } } private int findUnusedPage(Page[] Pages, int CurrentInstruction) { int[] Pos = new int[Pages.length]; Page page; for (int m = 0; m < Pages.length; m++) { Pos[m] = 0; page = Pages[m]; for (int n = CurrentInstruction; n < seq.getList().size(); n++) { if (page == VM.getPages()[Integer.parseInt(seq.getList().get(n).getName()) / Page.PAGE_SIZE]) { Pos[m] = n; break; } } } return findMax(Pos); } private int findMax(int[] Count) { int Max = 0; int Index = 0; for (int i = 0; i < Count.length; i++) { if (Count[i] > Max) { Max = Count[i]; Index = i; } } return Index; } }
 

最后当然是一个执行上述代码的TestCase
TestCase.java源代码:
package instructions; import instructions.algorithm.*; /** * Run 3 algorithm and print the result. * @author DigitalSonic */ public class TestCase { public static void main(String[] args) { int i; VirtualMemory VM = new VirtualMemory(); Sequence Seq = new Sequence(VM.getInstructions()); System.out.println("Instructions sequence:"); Seq.printSequence(); System.out.println(); System.out.println("OPT"); for (i = 4; i <= 32; i++) { System.out.print("User pages count:" + i + " "); new OPT(i, Seq, VM).execute(); } System.out.println(); System.out.println("FIFO"); for (i = 4; i <= 32; i++) { System.out.print("User pages count:" + i + " "); new FIFO(i, Seq, VM).execute(); } System.out.println(); System.out.println("LRU"); for (i = 4; i <= 32; i++) { System.out.print("User pages count:" + i + " "); new LRU(i, Seq, VM).execute(); } } }  

运行结果:
Instructions sequence: 224 225 226 227 166 167 168 169 120 121 271 272 175 281 222 9 12 191 25 26 172 173 174 275 251 136 137 138 139 256 146 147 148 264 265 14 103 32 271 272 273 274 23 84 143 144 145 146 147 212 213 267 255 44 45 129 288 261 262 263 264 265 266 267 143 144 248 209 210 175 176 177 178 179 180 181 182 183 278 279 260 244 245 246 179 180 205 206 207 166 167 168 60 61 62 3 210 81 78 100 89 305 146 154 46 47 231 9 10 179 180 24 25 107 108 109 110 77 78 79 80 34 35 296 297 279 280 154 155 156 33 34 46 47 48 49 58 110 127 306 218 219 284 285 93 94 95 12 13 294 282 144 155 52 53 101 102 103 104 105 106 107 143 22 23 24 250 251 252 253 254 225 226 227 120 211 74 75 185 186 187 188 119 120 121 122 81 82 83 84 85 86 60 302 235 192 143 258 259 260 261 262 196 130 131 84 49 50 51 143 144 214 28 29 248 249 41 42 250 191 192 193 219 220 221 222 223 224 55 104 259 260 176 198 199 200 101 265 266 267 68 69 70 162 163 164 165 113 87 115 128 179 22 23 65 185 212 213 227 228 227 228 191 192 75 183 199 225 12 313 314 315 213 137 133 134 135 136 199 200 201 202 203 204 274 15 16 17 20 21 81 82 284 285 286 287 288 284 95 128 233 234 101 220 26 162 252 253 254 255 256 295 222 223 216 217 218 10 11 35 OPT User pages count:4 Lack page count:142 Rate:44.375% User pages count:5 Lack page count:133 Rate:41.5625% User pages count:6 Lack page count:125 Rate:39.0625% User pages count:7 Lack page count:119 Rate:37.1875% User pages count:8 Lack page count:112 Rate:35.0% User pages count:9 Lack page count:103 Rate:32.1875% User pages count:10 Lack page count:95 Rate:29.6875% User pages count:11 Lack page count:88 Rate:27.500000000000004% User pages count:12 Lack page count:81 Rate:25.3125% User pages count:13 Lack page count:75 Rate:23.4375% User pages count:14 Lack page count:69 Rate:21.5625% User pages count:15 Lack page count:63 Rate:19.6875% User pages count:16 Lack page count:57 Rate:17.8125% User pages count:17 Lack page count:52 Rate:16.25% User pages count:18 Lack page count:48 Rate:15.0% User pages count:19 Lack page count:44 Rate:13.750000000000002% User pages count:20 Lack page count:40 Rate:12.5% User pages count:21 Lack page count:36 Rate:11.25% User pages count:22 Lack page count:32 Rate:10.0% User pages count:23 Lack page count:29 Rate:9.0625% User pages count:24 Lack page count:26 Rate:8.125% User pages count:25 Lack page count:22 Rate:6.875000000000001% User pages count:26 Lack page count:18 Rate:5.625% User pages count:27 Lack page count:15 Rate:4.6875% User pages count:28 Lack page count:12 Rate:3.75% User pages count:29 Lack page count:8 Rate:2.5% User pages count:30 Lack page count:5 Rate:1.5625% User pages count:31 Lack page count:2 Rate:0.625% User pages count:32 Lack page count:0 Rate:0.0% FIFO User pages count:4 Lack page count:152 Rate:47.5% User pages count:5 Lack page count:145 Rate:45.3125% User pages count:6 Lack page count:138 Rate:43.125% User pages count:7 Lack page count:135 Rate:42.1875% User pages count:8 Lack page count:128 Rate:40.0% User pages count:9 Lack page count:120 Rate:37.5% User pages count:10 Lack page count:112 Rate:35.0% User pages count:11 Lack page count:104 Rate:32.5% User pages count:12 Lack page count:101 Rate:31.5625% User pages count:13 Lack page count:93 Rate:29.062500000000004% User pages count:14 Lack page count:86 Rate:26.875% User pages count:15 Lack page count:79 Rate:24.6875% User pages count:16 Lack page count:75 Rate:23.4375% User pages count:17 Lack page count:66 Rate:20.625% User pages count:18 Lack page count:56 Rate:17.5% User pages count:19 Lack page count:51 Rate:15.937499999999998% User pages count:20 Lack page count:47 Rate:14.6875% User pages count:21 Lack page count:43 Rate:13.4375% User pages count:22 Lack page count:38 Rate:11.875% User pages count:23 Lack page count:34 Rate:10.625% User pages count:24 Lack page count:28 Rate:8.75% User pages count:25 Lack page count:25 Rate:7.8125% User pages count:26 Lack page count:22 Rate:6.875000000000001% User pages count:27 Lack page count:19 Rate:5.9375% User pages count:28 Lack page count:15 Rate:4.6875% User pages count:29 Lack page count:11 Rate:3.4375000000000004% User pages count:30 Lack page count:5 Rate:1.5625% User pages count:31 Lack page count:2 Rate:0.625% User pages count:32 Lack page count:0 Rate:0.0% LRU User pages count:4 Lack page count:149 Rate:46.5625% User pages count:5 Lack page count:143 Rate:44.6875% User pages count:6 Lack page count:138 Rate:43.125% User pages count:7 Lack page count:132 Rate:41.25% User pages count:8 Lack page count:124 Rate:38.75% User pages count:9 Lack page count:119 Rate:37.1875% User pages count:10 Lack page count:113 Rate:35.3125% User pages count:11 Lack page count:109 Rate:34.0625% User pages count:12 Lack page count:98 Rate:30.625000000000004% User pages count:13 Lack page count:93 Rate:29.062500000000004% User pages count:14 Lack page count:87 Rate:27.187499999999996% User pages count:15 Lack page count:82 Rate:25.624999999999996% User pages count:16 Lack page count:77 Rate:24.0625% User pages count:17 Lack page count:71 Rate:22.1875% User pages count:18 Lack page count:69 Rate:21.5625% User pages count:19 Lack page count:61 Rate:19.0625% User pages count:20 Lack page count:54 Rate:16.875% User pages count:21 Lack page count:49 Rate:15.312500000000002% User pages count:22 Lack page count:43 Rate:13.4375% User pages count:23 Lack page count:38 Rate:11.875% User pages count:24 Lack page count:29 Rate:9.0625% User pages count:25 Lack page count:24 Rate:7.5% User pages count:26 Lack page count:21 Rate:6.5625% User pages count:27 Lack page count:17 Rate:5.3125% User pages count:28 Lack page count:11 Rate:3.4375000000000004% User pages count:29 Lack page count:8 Rate:2.5% User pages count:30 Lack page count:4 Rate:1.25% User pages count:31 Lack page count:2 Rate:0.625% User pages count:32 Lack page count:0 Rate:0.0%  

OPT,LRU,FIFO页面置换算法python实现 实验三 请求页式存储管理中常用页面置换算法模拟 【开发语言及实现平台或实验环境】 C++/C# Microsoft Visual Studio 6.0/ Microsoft Visual Studio .NET 2003 【实验目的】 (1)了解内存分页管理策略 (2)掌握调页策略 (3)掌握一般常用的调度算法 (4)学会各种存储分配算法的实现方法。 (5)了解页面大小和内存实际容量对命中率的影响... 阅读详情

相关推荐

虚拟内存页面置换算法(OPT、FIFO、LRU)模拟与实现

前言 需要调入新页面时,选择内存中哪个物理页面被置换,称为置换策略。页面置换算法的目标:把未来不再使用的或短期内较少使用的页面调出,通常应在局部性原理指导下依据过去的统计数据进行预测,减少缺页次数。 一、常用的页面置换算法 1)最佳置换算法(OPT):置换时淘汰“未来不再使用的”或“在离当前最远位置上出现的”页面。 2)先进先出置换算法(FIFO):置换时淘汰最先进入内存的页面,即选择驻留在内存时间最长的页面被置换。 3)最近最久未用置换算法(LRU):置换时淘汰最近一段时间最久没有使用的页面,即选择上次使

weixin_47700137的博客 1万+

页面调度算法 FIFO,LRU,OPT,及C++代码

页面调度算法 FIFO,LRU,OPT介绍了三种页面调度算法,给出了C++代码1.FIFO先来先去算法这个非常好理解,给出分析图 可以看出,缺页次数为8次,缺页中断率为8/12=66.7%,依次置换的页面为:1,2,5,3,4C++代码在最后给出2.LRULRU,Least Recently Used 近期最少使用算法,先给出分析图 这个也不难理解,我们只需要从之前的一个页面开始往左寻找就可

wf824284257的博客 1万+

编写页面置换算法OPT、FIFO、LRU的模拟程序

c语言编写页面置换算法OPT FIFO LRU的模拟程序。 源代码: #include <stdio.h> #define number 20 #define block 3 int opt(int a[]) { int i,j,zero=0,one=0,two=0,q=0; int b[block]; for(i=0;i<block;i++) { b[i]=-1; } for(i=0;i<number;i++)

qq_43523736的博客 4288

【实验4 存储管理】

实验

weixin_56603071的博客 1913

操作系统:FIFO、LRU、OPT页面置换算法

题目 在一个请求分页系统中,分别采用 FIFO、LRU和 OPT页面置换算法时,假如一个作业的页面走向为 4、3、2、1、4、3、5、4、3、2、1、5,当分配给该作业的物理块数M分别为 3、4时,试计算在访问过程中所发生的缺页次数和缺页率,并比较所得结果。 页面置换算法 ...

数据分析阿宇君的博客 5727

《操作系统》实验二.doc

实验二 存储管理 1、实验目的 通过模拟实现内存分配的伙伴算法和请求页式存储管理的几种基本页面置换算法,了 解存储技术的特点。掌握虚拟存储请求页式存储管理中几种基本页面置换算法的基本思 想和实现过程,并比较它们的效率。 2、实验内容 实现一个内存管理的伙伴算法,实现内存块申请时的分配和释放后的回收。 设计一个虚拟存储区和内存工作区,并使用下述算法计算访问命中率。 1) 最佳置换算法(Optimal) 2) 先进先出法(Fisrt In First Out) 3) 最近最久未使用(Least Recently Used) 4) 最不经常使用法(Least Frequently Used) 5) 最近未使用法(No Used Recently) 其中,命中率=1-页面失效次数/页地址流长度。 试对上述算法的性能加以较各:页面个数和命中率间的关系;同样情况下的命中率比较 。 3、实验分析 对于伙伴算法,用随机函数仿真进程进行内存申请,并且以较为随机的次序进行释放。 对其碎片进行统计,当申请分配内存失败时区分实际空间不足和由于碎片而不能满足。 对于虚拟存储区和内存工作区的不同算法,其中主要的流

操作系统实验五--存储管理

文章目录操作系统实验五--存储管理一、实验目的二、实验内容三、设计原理及相关算法四、结果分析五、源代码 操作系统实验五–存储管理 一、实验目的 1、了解虚拟存储技术的特点,掌握请求页式存储管理的主要页面置换算法原理。 2、掌握请求页式存储管理中页面置换算法的模拟设计方法。 二、实验内容 设计一个虚拟存储区和内存工作区,并使用下述方法计算访问命中率。 ①先进先出的算法(FIFO); ②最近最少少使用算法(LRR); ③最佳淘汰算法(OPT):选淘汰最不常用的页地址; ④最少访问页面算法(LFR); ⑤最近最不

一顿吃不饱的博客 1万+

单细胞实战之亚细胞分群从T/NK至CD4+T细胞——从入门到进阶(中级篇1)

亚细胞分群从T/NK至CD4+T细胞

zfyyzhys的博客 6389

广州大学2022操作系统实验三——内存管理

模拟实现请求页式存储管理的几种基本页面置换算法 (1)最佳淘汰算法(OPT) (2)先进先出的算法(FIFO) (3)最近最久未使用算法(LRU)

llll1515的博客 2042

k8s部署 普罗米修斯(Prometheus)监控

Prometheus是一个开源的服务监控系统和时序数据库其提供了通用的数据模型和快捷数据采集、存储和查询接口它的核心组件Prometheus服务器定期从静态配置的监控目标或者基于服务发现自动配置的目标中进行拉 取数据新拉取到啊的 数据大于配置的内存缓存区时,数据就会持久化到存储设备当中。

D2961953033的博客 3855

如何通过插值法计算cell delay?

插值法的公式:Z = A + B * X + C * Y + D * X * Y,其中X为input transition,Y为output load,A、B、C、D为四个参数,Z为delay值。从而得到Z=-0.086176 + 11.5493 * x + 0.65917 * y - 24.859 * x * y,当X=0.014930、Y=0.296311时,得到Z=0.1716ns。从而得到A = 0.08075,B = 3.47539,C = 0.04008,D = 0.01648。

芯冰乐 1076

广州大学操作系统实验三 内存管理

广州大学操作系统实验三 内存管理 一、实验目的 1、了解虚拟存储技术的特点,掌握虚拟存储请求页式存储管理中几种基本页面置换算法的基本思想和实现过程,并比较它们的效率。 2、了解程序设计技术和内存泄露的原因 二、 实验内容 1、模拟实现请求页式存储管理的几种基本页面置换算法(1)最佳淘汰算法(OPT)(2)先进先出的算法(FIFO)(3)最近最久未使用算法(LRU)) 三、 实验要求 (1)通过随机数产生一个指令序列,共320条指令。指令的地址按下述原则生成:A:50%的指令是顺序执行的B:25%的指令是均匀

m0_48437268的博客 3204

项目经理必看:如何建立高效的相关方沟通机制?

你是否遇到过这样的场景?客户突然说“这不是我要的”,开发团队抱怨“需求总变”,高层追问“进度滞后为什么不早说”?这些问题的根源往往是——相关方沟通机制失效。本文聚焦“如何建立高效沟通机制”,覆盖从识别相关方到持续优化的全流程,适用于IT、产品、工程等各类项目。本文将按“理解问题→拆解核心概念→掌握工具方法→实战落地→未来趋势”的逻辑展开,重点讲解“相关方分析矩阵”“沟通计划表”等实用工具,并用“组织生日派对”的案例贯穿全文,让抽象概念变得可感知。相关方识别:用“权力/利益矩阵”找对人(像派对邀请关键客人)

项目管理的博客 1295

【操作系统】关于LRU算法,FIFO算法,OPT算法页面调度算法及例子

短小精悍,一篇文章掌握三种算法!!!

一个平平无奇的攻城狮 7107

CAPL如何设置或修改CANoe TCP/IP协议栈的底层配置

MSS = MTU - tcpHeader - ipHeader,也就是MTU = MSS(1360) + tcpHeader(20) + ipHeader(20) = 1400,说明CAPL是可以动态设置网络底层配置参数的!然后在CAPL中设置此网卡MTU值为1400,然后创建UDP套接字,一次性发送2000个字节,在Trace窗口看看首帧报文二层Data的长度。所以我们还不能用UDP协议来验,应该用TCP协议来验,也就是在TCP三次握手时通过Tester的MSS值推导出自己的MTU值。

jasonj333 992

华为od 面试八股文_C语言_02_含答案

华为od 面试八股文_C语言_02_含答案

MISAYAONE的博客 2230

缺页中断——FIFO、LRU、OPT这三种置换算法

FIFO、LRU、OPT这三种置换算法的缺页次数2缺页中断  在请求分页系统中,可以通过查询页表中的状态位类确定所要访问的页面是否存在于内存中。每当所要访问的压面不在内存时,会产生一次缺页中断,此时操作系统会根据页表中的外存地址在外存中找到所缺的一页,将其调入内存。

smile4lee的博客 9万+

手把手教你学Simulink--基于飞行控制与稳定性的场景实例:多旋翼无人机在风扰动下的稳定性分析

本文介绍了使用Simulink仿真多旋翼无人机在风扰动下稳定性的方法。通过构建包含飞行器动力学模型、PID控制系统和环境模拟模块的仿真系统,分析了无人机在不同风速条件下的飞行性能。详细说明了从创建模型、设置动力学方程、设计PID控制器到添加风扰动模型的完整流程,并提供了性能评估指标。该方法可用于验证控制系统有效性,优化飞行稳定性参数,为无人机控制系统的设计和调试提供参考。

MHD0815的博客 328

操作系统 FIFO算法 LRU算法 OPT算法(C++)

题目 实验三 请求调页存储管理方式的模拟 1.实验目的 通过对页面、页表、地址转换和页面置换过程的模拟,加深对请求调页系统的原理和实现过程的理解。 2.实验内容 (1)假设每个页面中可存放10条指令,分配给作业的内存块数为4。 (2)用c语言模拟一个作业的执行过程,该作业共有320条指令,即它的地址空间为32页,目前它的所有页都还未调入内存。在模拟过程中,如果所访问的指令已在内存,则显示其物理地址,并转下一条指令。如果所访问的指令还未装入内存,则发生缺页,此时需记录缺页的次数,并将相应页调入内存。如果4个

Authur_gyc 6392

App爬虫实战篇-以华为真机手机爬取集换社的app为例

在开始学习这篇文章之前,建议你先按照之前2篇文章(和),配置必要的环境,才可以继续完成本章节内容。

youbingchen的博客 780

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

C++实现虚拟内存页面置换算法(FIFO, OPT, LRU)

虚拟内存页面置换算法(FIFO, OPI, LRU) 代码 #include <iostream> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int MAX_SIZE = 1e3+5; const int INF = 0x3f3f3f3f; int pg_last[MAX_SIZE]; //last time of using pa

tb_youth的博客 7685

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

操作系统之页面置换算法——FIFO、OPT和LRU

操作系统中FIFO、OPT、LRU三种页面替换算法的定义和例题分析

PleaSure乐事的博客 8852

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

操作系统实验之页面置换算法(OPT、FIFO、LRU)C++简单实现

南邮操作系统实验之页面置换算法(OPT、FIFO、LRU)C++简单实现

淘萄桃的博客 3万+

[操作系统]页面置换算法实验及C++实现(OPT、FIFO、LRU)

进程运行时,若其访问的页面不再内存中而需将其调入,但内存已无空闲空间时,就需要从内存中调出一页程序或数据,送入磁盘的对换区。选择调出页面的算法就称为页面置换算法。

This blog is a space to document my professional learnings, personal reflections, and everything in between. 5836

操作系统计算FIFO,LRU,OPT,LFU,NUR缺页率,C语言实现

操作系统计算FIFO,LRU,OPT,LFU,NUR缺页率 修改“计算机操作系统教程第四版习题解答与实验指导”中实验四置换算法存在的bug 该程序是比较这5种页面置换算法的缺页率 引入头文件、定义常数值、结构体、函数声明 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <u...

luohaifang的博客 1万+
上一篇: FIFO、LRU、OPT的三个简单实现
下一篇: [BlackBox项目]Plog用户操作分析
dingx
博客等级 码龄24年 67粉丝 112原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值