Chapter-4-Continued (Autosaved)
Chapter-4-Continued (Autosaved)
Chapter-4-Continued (Autosaved)
(continued):
VIRTUAL MEMORY
Motivations for Virtual Memory
• Provide Protection
• One process can’t interfere with another.
• because they operate in different address spaces.
• User process cannot access privileged information
• different sections of address spaces have different permissions.
Virtual memory is stored in a hard disk image. The physical
memory holds a small number of virtual pages in physical
page frames.
A mapping between a virtual and a physical memory:
Motivation #1: DRAM a “Cache” for Disk
C
CPU a Memory
CPU c Memory disk
disk
regs
regs h
e
CPU
P-1:
N-1:
Disk
Address Translation: Hardware converts virtual addresses to
physical addresses via OS-managed lookup table (page table)
Page Faults (like “Cache Misses”)
• What if an object is on disk rather than in memory?
• Page table entry indicates virtual address not in memory
• OS exception handler invoked to move data from disk into
memory
• current process suspends, others can resume
• OS has full control over placement, etc.
Disk
Disk
Solution: Separate Virt. Addr. Spaces
• Virtual and physical address spaces divided into
equal-sized blocks
• blocks are called “pages” (both virtual and physical)
PP 7
Virtual 0
VP 1
Address PP 10
VP 2
Space for ...
Process 2: M-1
N-1
Motivation #3: Protection
• Page table entry contains access rights
information
• hardware enforces this protection (trap into OS if
Page Tables
violation occurs) Memory
Read? Write? Physical Addr 0:
VP 0: Yes No PP 9 1:
Process i: VP 1: Yes Yes PP 4
VP 2: No No XXXXXXX
• • •
• • •
• • •
n–1
• M = 2 = Physical address limit
m
p p–1 0
virtual page number page offset virtual address
address translation
m–1 p p–1 0
physical page number page offset physical address
if valid=0
then page
not in memory m–1 p p–1 0
physical page number (PPN) page offset
physical address
Page Table Operation
hit
VA PA miss
TLB Main
CPU Cache
Lookup Memory
miss hit
Trans-
lation
data
Address Translation with a
TLB
n–1 p p–1 0
virtual page number page offset virtual address
TLB hit
physical address
• Common solution
• multi-level page tables ...
• e.g., 2-level table (P6)
• Level 1 table: 1024 entries, each of which
points to a Level 2 page table.
• Level 2 table: 1024 entries, each of which
points to a page
Simple Memory System Example
• Addressing
• 14-bit virtual addresses
• 12-bit physical address
• Page size = 64 bytes
13 12 11 10 9 8 7 6 5 4 3 2 1 0
VPN VPO
(Virtual Page Number) (Virtual Page Offset)
11 10 9 8 7 6 5 4 3 2 1 0
PPN PPO
(Physical Page Number) (Physical Page Offset)
Simple Memory System Page Table
• TLB
• 16 entries
12•
TLBT associative
4-way TLBI
13 11 10 9 8 7 6 5 4 3 2 1 0
VPN VPO
Set Tag PPN Valid Tag PPN Valid Tag PPN Valid Tag PPN Valid
0 03 – 0 09 0D 1 00 – 0 07 02 1
1 03 2D 1 02 – 0 04 – 0 0A – 0
2 02 – 0 08 – 0 06 – 0 03 – 0
3 07 – 0 03 0D 1 0A 34 1 02 – 0
Simple Memory System Cache
• Cache CT CI CO
• 16 lines
11 10 9 8 7 6 5 4 3 2 1 0
• 4-byte line size
• Direct mapped PPN PPO
VPN VPO
VPN ___ TLBI ___TLBT ____ TLB Hit? __ Page Fault? __ PPN: ____
• Physical Address
CT CI CO
11 10 9 8 7 6 5 4 3 2 1 0
VPN VPO
VPN ___ TLBI ___TLBT ____ TLB Hit? __ Page Fault? __ PPN: ____
• Physical Address
CT CI CO
11 10 9 8 7 6 5 4 3 2 1 0
VPN ___ TLBI ___TLBT ____ TLB Hit? __ Page Fault? __ PPN: ____
VPN VPO
• Physical Address
CT CI CO
11 10 9 8 7 6 5 4 3 2 1 0