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万+

fpga的希尔伯特变换实现

fpga的希尔伯特变换实现零.实现背景一.希尔伯特实现的基本原理2.实现1)matlab仿真1)fpga滤波器实现实现成本:fpga实现采用VIvado的FIR的IP核, 零.实现背景 因为今明工作项目需要使用到希尔伯特变换来处理问题,所以顺便就把设计流程和代码都整理下来,以便供他人使用。选用Xilinx的7系列板子,Vivado平台。 一.希尔伯特实现的基本原理 希尔伯特变换的物理意义十分简单:...

weixin_42219690的博客 1万+

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

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

llll1515的博客 2042

FPGA新手必看:用USB转TTL实现串口通信的完整流程(附CH340G电路详解)

本文为FPGA新手提供了通过USB转TTL模块实现串口通信的完整实战指南。详细解析了CH340G电路设计要点、硬件连接方法,并分享了经过验证的Verilog代码框架,帮助读者快速掌握FPGA与PC通信的核心技术,解决电平匹配与波特率设置等常见问题。

cake8的博客 1049

芯片低功耗设计的两种常用EDA流程

如题。

EricWZY2008的专栏 5557

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

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

m0_48437268的博客 3204

【HCIP-AI 进阶之路(一)】零成本白嫖算力,7天速通华为人工智能资深开发者认证

《HCIP-AIEIDeveloper认证备考指南》摘要:本文深度解析华为HCIP-AI(H13-331)认证考试要点,涵盖考试大纲、评分标准及备考策略。重点剖析昇腾AI全栈架构,包括达芬奇架构核心计算单元(Cube/Vector/Scalar Unit)和四大层级关系(芯片-CANN-框架-应用)。针对无硬件资源的开发者,提供MindSpore CPU版、ModelArts免费算力和沙箱实验室三种零成本实践方案。文章强调该认证对国企/华为生态企业求职者的价值,并指出多选题是主要失分点。下篇将聚焦计算机视觉

2301_82049134的博客 1184

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

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

一个平平无奇的攻城狮 7107

bcftools学习笔记(一)

欢迎关注"生信修炼手册"!本篇主要介绍index, view, query, sort, reheader这五个命令。1. indexindex命令用于对VCF文件建立索...

庐州月光的博客 6010

UNet改进(47):Deformable Convolution在UNet中的集成与应用

本文提出了一种可变形U-Net(DeformableUNet)结构,通过在U-Net的双卷积模块中集成可变形卷积(DeformConv2d)来提升模型对物体形变和复杂结构的建模能力。传统卷积受限于固定感受野,而可变形卷积通过动态调整采样位置,能更好地适应不规则形状。实现中,在DoubleConv模块的第二个卷积层替换为可变形卷积,同时保持第一层为标准卷积以确保稳定性。实验表明,该方法在保持参数量基本不变的情况下,显著提升了分割精度(mIoU从0.712提升到0.743)。

2501_91516851的博客 202

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

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

smile4lee的博客 9万+

EMI辐射发射超标案例

EMI辐射发射超标案例

让你爱上电路设计 8503

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

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

Authur_gyc 6392

FPGA控制AD5754实现模数转换Verilog代码与测试激励

本文提供了使用FPGA控制AD5754芯片实现数字信号转模拟信号的Verilog代码和测试激励。AD5754芯片简介:AD5754是一款16位数字信号转模拟信号的芯片。通信方式:FPGA与AD5754之间通过SPI接口进行通信,SPI时钟clk的最大频率为30MHz。模拟输出:AD5754提供了四路模拟输出。工作方式:当前AD5754采用单极性工作方式。指令刷新:根据现有理解,同轴的速度和电流指令应同时刷新。利用LDAC引脚控制模拟信号的刷新,但需实际验证。CLR信号验证。

whm128的博客 246

IEM模型,地表粗糙度模拟

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

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

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

PleaSure乐事的博客 8852

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

操作系统实验之页面置换算法(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、付费专栏及课程。

余额充值