两个数组内的页面错误计数?
家庭作业
考虑二维数组 A:
int A[][] = new int[200][200];
其中 A[0][0] 位于页大小为 500 的分页内存系统中的位置 500(有点不切实际 - 不是 512)。操作矩阵的小进程位于第 0 页(位置 0 到 499)。因此,每个指令读取都来自当前存储在页 0 中的指令。
假设只有 5 个页框(包括页 0),则使用 LRU 替换并假设页框的以下数组初始化循环会生成多少页错误0包含进程而其他四个最初是空的?
A)for (int j = 0; j < 200; j++) for (int i = 0; i < 200; i++) A[i][j] = 0;
B)for (int i = 0; i < 200; i++) for (int j = 0; j < 200; j++) A[i][j] = 0;
问题:
我从哪里开始解决这个问题?我已经浏览了我的文本,但没有发现其中有太多用处。我扔了一些数字,发现:
40,000 = 数组项总数
80 (40k/500) = 总页数
A) 20,000 (80*250) 因为每个其他循环都会导致页面错误?
B) 80(每页一个,40,000/500 = 80)?
我走在正确的轨道上吗?有什么建议吗?提示?
Homework:
Consider the two-dimensional array A:
int A[][] = new int[200][200];
where A[0][0] is at location 500 in a paged memory system with pages of size 500 (a little unrealistic -- not 512). A small process that manipulates the matrix resides in page 0 (locations 0 to 499). Thus, every instruction fetch will be from an instruction currently stored in page 0.
Assuming there are only five page frames, including page 0, how many page faults are generated by the following array-initialization loops, using LRU replacement and assuming that page frame 0 contains the process and the other four are initially empty?
A)for (int j = 0; j < 200; j++)
for (int i = 0; i < 200; i++)
A[i][j] = 0;
B)for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
A[i][j] = 0;
Question:
Where do I begin to figure this out? I have went through my text but haven't found much of it to be useful. I threw some numbers around and I found:
40,000 = total number of array items
80 (40k/500) = total number of pages
A) 20,000 (80*250) because every other loop causes a page fault?
B) 80 (One for each page, 40,000/500 = 80)?
Am I on the right track? Any advice? Hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑一下循环 A 和循环 B 中初始化发生的顺序,以及多维数组在内存中的布局方式。其中一个将按顺序访问内存地址,另一个将跳转。 200 次赋值后,您将在一种情况下查看 A[199][0],在另一种情况下查看 A[0][199]。你摸过多少页了?
Think about the order that the initialization happens in loop A vs loop B, and how a multi-dimentional array is laid out in memory. One of them will access memory addresses in-order, the other will jump around. After 200 assignments, you'll be looking at A[199][0] in one case, and A[0][199] in the other. How many pages have you touched?