天天看点

操作系统cs439复习- problem 5

1.What is a virtual address? What is a physical address? How do they relate to each other?

虚拟地址是操作系统给应用程序提供的一种假象,让应用程序以为它拥有一个从0 开始的连续的大内存空间。

进程中使用的内存引用都是虚拟地址(virtual address),硬件接下来将虚拟地址加上基址寄存器中的内容,得到物理地址(physical address),再发给内存系统。

操作系统cs439复习- problem 5

目的

  1. 透明(transparency)。用户编写程序的时候,直接认为自己拥有很大的连续地址空间,内存被虚拟化的假象像是透明的一样无法感知。程序员使用起来更容易!
  2. 保护(protection)。操作系统应确保进程受到保护(protect),不会受其他进程影响,操作系统本身也不会受进程影响。当一个进程执行加载、存储或指令提取时,它不应该以任何方式访问或影响任何其他进程或操作系统本身的内存内容(即在它的地址空间之外的任何内容)。因此,保护让我们能够在进程之间提供隔离(isolation)的特性,每个进程都应该在自己的独立环境中运行,避免其他出错或恶意进程的影响。
  3. 虚拟内存可以比物理地址更大。通过swapping,允许物理内存更大的应用程序同时运行。

详细解释

操作系统cs439复习- problem 5
操作系统cs439复习- problem 5
操作系统cs439复习- problem 5
操作系统cs439复习- problem 5

硬件内存更大,所以需要64位的内存电脑。

如果物理地址更大,也需要虚拟地址,可以隔离多个应用程序。比如一个应用程序的多个实例

Virtual Address (VA) is the address used by CPU. It represents the location of

the data in virtual space (stored in hard disk), which is divided into

multiple equal-sized virtual pages.

Physical Address (PA) represents the location of data in main memory. It

represents offset of the referenced physical page.

Translation between physical address and virtual address is supported by

memory management unit (MMU). Specifically, MMU deal with the page tables that

restores the correspondence of PA and VA.

2. What causes a memory exception? What is the end result for the running process?

操作系统cs439复习- problem 5

进程会立即终止运行。

a. segmentation fault:

Caused by accessing data that is not owned by calling process or

attempting to access an illegal memory area.

The program will abort.

b. protection fault:

Caused by permission denied. The caller has no right to write or read the

specified block of data.

The program will abort.

c. normal page fault:

Caused by cache miss. That is, the required data is not memory-resident.

This will trigger a cache miss interrupt handler, after which the program

will continue to proceed if the required data is later successfully loaded

to memory.

Cache miss causes a normal page fault.

The running process will proceed after the required data is loaded from

virtual space to physical space.

3. Name two advantages of paging over relocation.

Paging has what advantage over relocation?

A. Easier to manage transfer of pages from disk

B. Requires less hardware support

C. No external fragmentation

Two types of wasted space:

– External Fragmentation

• Unused memory between units of allocation

• For example, two fixed tables for two but a party of four

– Internal Fragmentation

• Unused memory within a unit of allocation

• For example, a party of three at a table for four

4. Consider a paging system with 16 pages and a page size of 256 bytes. The system has 1024 bytes of physical memory.

  1. How many bits are in a physical address?
操作系统cs439复习- problem 5

1024 / 256 = 4 physical pages, as basic unit of physical addressing

log2(4) = 2 bits, 2个bit可以表示总共4个页

每个页256个bytes,还需要8bits,表示offset

  1. How many bits represent the page number?

    4 2^4 = 16

  2. How many bits are in the complete virtual address?

    8bits,表示offset 4bits表示 page number

    12bits

4.What size are the page frames?

The system’s page size is equivalent to its frame size.

256 X8 = bits

5. Pages have (at least) the following three bits associated with them: the resident bit, the clock/reference bit, and the dirty bit. Describe each bit and its use

操作系统cs439复习- problem 5

Resident bit: also called valid bit and present bit, true if the corresponding

virtual page is in physical (main) memory.