首页 > 其他分享 >操作系统导论习题解答(15. Address Translation)

操作系统导论习题解答(15. Address Translation)

时间:2022-10-14 19:11:26浏览次数:73  
标签:VA 15 Address register bounds 地址 Base address 习题

Mechanism: Address Translation

In developing the virtualization of the CPU, we focused on a general mechanism known as limited direct execution (or LDE ).

1. An Example

void func () {
	int x = 3000;
	x = x + 3;
}

对于这个程序,它的存储地址如下:
在这里插入图片描述
对应的汇编代码如下:

128: movl 0x0(%ebx), %eax
132: addl $0x03, %eax
135: movl %eax, 0x0(%ebx)

在这里插入图片描述
上面这个程序从地址0开始并且最大到16KB,但是对于虚拟内存而言,操作系统想要放置这个程序在任何地址,不一定从地址0开始。下面这个图片就是把程序放在以32KB地址开头的位置。
在这里插入图片描述

2. Dynamic (Hardware-based) Relocation

dynamic relocation : base and bounds.
对于每个CPU,都有2个硬件寄存器,一个为base register,一个为 bounds register.
每个程序的实际物理地址就等于虚拟地址加上基准地址。如下:
在这里插入图片描述
以上图(Figure 15.2)所示,程序的首地址为32KB,那么就设置base register为这个值。再看上上图(Figure 15.1),程序自己觉得自己的地址是从0开始,所以virtual address就为0。

bounds register的作用就是保护,bounds register的值有两种定义方式。一种是定义为程序总的长度,另一种是定义为程序最后结束的实际物理地址值。
我们定义它采用第一种方式,看上面那个程序,程序总的地址长度为16KB,那么bounds register的值就为16KB,如果发生越界,操作系统就抛出异常。

3. Homework (Simulation)

The program relocation.py allows you to see how address translations are performed in a system with base and bounds registers. See the README for details.
在这里插入图片描述

3.1 Question & Answer

1. Run with seeds 1, 2, and 3, and compute whether each virtual address generated by the process is in or out of bounds. If in bounds, compute the translation.

在这里插入图片描述
只有 VA 1 没有超出界限。
VA 1 --> VALID: 0x00003741(decimal: 14145)
只要VA N (N = 0, 1, 2, 3, 4,...)的 decimal < Limit,就没有超出界限。
对于没有超出界限的有:
VALID = Base + Virtual Address
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2. Run with these flags: -s 0 -n 10. What value do you have set -l (the bounds register) to in order to ensure that all the generated virtual addresses are within bounds?

在这里插入图片描述
从上图我们可以看出,VA中最大的为dicimal 929,我们就可以把Limit设置成930(为什么不是929?这是要特别注意的地方)。

在这里插入图片描述

在这里插入图片描述

3. Run with these flags: -s 1 -n 10 -l 100. What is the maximum value that base can be set to, such that the address space still fits into physical memory in its entirety?

在这里插入图片描述
我们看一下上图,Limit的值为100,而物理地址的值= Base + VA,能够表示的物理地址最大值 = Base + Limit,故只要Limit >= VA,那么无论Base设置什么值,都超出了范围。
不存在可以设置的Base的最大值,使得所有地址空间适合物理内存。

4. Run some of the same problems above, but with larger address spaces (-a) and physical memories (-p).

在这里插入图片描述
在这里插入图片描述
从上面这两副图,我们可以看到当把 address space size 扩大1倍后(从1K(默认值) --> 2K),相应的VA 的大小也扩大了1倍。

在这里插入图片描述

在这里插入图片描述
从上面两幅图,我们可以看到当把 phys mem size 扩大1倍后(从13884(默认值) --> 27768),相应的 Base的大小也扩大了1倍。

5. What fraction of randomly-generated virtual addresses are valid, as a function of the value of the bounds register? Make a graph from running with different random seeds, with limit values ranging from 0 up to the maximum size of the address space.

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
...........略

在这里插入图片描述
...略

标签:VA,15,Address,register,bounds,地址,Base,address,习题
From: https://www.cnblogs.com/astralcon/p/16792699.html

相关文章

  • 操作系统导论习题解答(17. Free Space Management)
    Free-SpaceManagement使用segmentation实现虚拟内存时,我们可能会遇到上图所示情况,总共未使用的空间是20字节,但是被分成了2个10字节的内存段,如果有个15字节的程序请求CPU......
  • 15
    今日内容总结1.内置函数大全#A系列:abs(x)获取绝对值操作aiter()相当于调用x.__aiter__all(x)如果x中的数据值全为真值(或迭代对象为空)则......
  • 第三章 顺序结构程序设计习题【原始版手机编辑,转换电脑数据混乱,看水印】
     声明三个长整型的变量为x,y,z;把5的值赋给x,把6的值赋给n;根据数学式对应的c语言表达式给y赋值;输出y,此时就是表达式的值。声明两个整数类型m和n,并赋值1和2;利用复合运算......
  • 概要15
    今日内容回顾目录今日内容回顾重要内置函数常见内置函数可迭代对象迭代器对象for循环的本质异常捕获处理重要内置函数常见内置函数可迭代对象迭代器对象for循环本质......
  • day15学习分享 内置参数
    目录今日内容概要今日内容详细作业讲解重要内置函数常见内置函数可迭代对象迭代器对象for循环本质异常捕获/处理今日内容概要作业讲解重要内置参数常见内置参数可......
  • Python基础15
    今日内容概要重要内置函数常见内置函数可迭代对象迭代器对象for循环的本质异常今日内容详细重要内置函数1.zip() zip函数是可以接收多个可迭代对象,然后把每......
  • AtCoder Regular Contest 150 B Make Divisible 贪心 整除分块
    给出一个A和B想要找到一个X和Y使得\(A+X|B+Y\).同时使得X+Y最小求出X+Y的最小值。值域是\([1,10^9]\)直接枚举X不太行会被某种数据卡掉。考虑正解:先固定K另\(\frac{B......
  • LeetCode 1115. Print FooBar Alternately
    原题链接在这里:https://leetcode.com/problems/print-foobar-alternately/题目:Supposeyouaregiventhefollowingcode:classFooBar{publicvoidfoo(){f......
  • torch进行多GPU卡训练时,报错RuntimeError: Address already in use
    torch进行GPU卡训练时,报错RuntimeError:Addressalreadyinuse参考:https://www.it610.com/article/1279180977062559744.htm问题在于,TCP的端口被占用,一种解决方法是,运行......
  • 工作总结!日志打印的15个建议
    前言大家好,我是程序员田螺。日志是快速定位问题的好帮手,是撕逼和甩锅的利器!打印好日志非常重要。今天我们来聊聊日志打印的15个好建议~1.选择恰当的日志级别常见的日志级......