1.What is a virtual address? What is a physical address? How do they relate to each other?
虛拟位址是作業系統給應用程式提供的一種假象,讓應用程式以為它擁有一個從0 開始的連續的大記憶體空間。
程序中使用的記憶體引用都是虛拟位址(virtual address),硬體接下來将虛拟位址加上基址寄存器中的内容,得到實體位址(physical address),再發給記憶體系統。

目的
- 透明(transparency)。使用者編寫程式的時候,直接認為自己擁有很大的連續位址空間,記憶體被虛拟化的假象像是透明的一樣無法感覺。程式員使用起來更容易!
- 保護(protection)。作業系統應確定程序受到保護(protect),不會受其他程序影響,作業系統本身也不會受程序影響。當一個程序執行加載、存儲或指令提取時,它不應該以任何方式通路或影響任何其他程序或作業系統本身的記憶體内容(即在它的位址空間之外的任何内容)。是以,保護讓我們能夠在程序之間提供隔離(isolation)的特性,每個程序都應該在自己的獨立環境中運作,避免其他出錯或惡意程序的影響。
- 虛拟記憶體可以比實體位址更大。通過swapping,允許實體記憶體更大的應用程式同時運作。
詳細解釋
硬體記憶體更大,是以需要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?
程序會立即終止運作。
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.
- How many bits are in a physical address?
1024 / 256 = 4 physical pages, as basic unit of physical addressing
log2(4) = 2 bits, 2個bit可以表示總共4個頁
每個頁256個bytes,還需要8bits,表示offset
-
How many bits represent the page number?
4 2^4 = 16
-
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
Resident bit: also called valid bit and present bit, true if the corresponding
virtual page is in physical (main) memory.