[OS'25] Lecture 4
[OS'25] Lecture 4
Chapter 8
Virtual Memory – Part II
[H/W Role + OS Role]
Dave Bremer
Otago Polytechnic, N.Z.
©2008, Prentice Hall
Shared
Memory CPU Resourc
e
[3] Thrashing
Address
Time
From Last Time…
VM view Page Tables RAM view
1111 1111 (level 2)
stack 1) Table Size > Frame Size
Virtual Paging: 11 11101
stack
1111 0000
Single table
2) Partial should fit
required 10 11100
01 10111
1100 0000 Page Table 00 10110
(level 1)
111 in 1 frame 11 null
10 10000
stack
110 null
101 null 01 01111
00 01110
heap 100
011 null
1000 0000
010 heap
• P (present bit): in RAM or Not 001 null
000 11 01101
MMU Role?
OS Role?
Agenda
• H/W Roles [cont.]
1. Paging PART I
1. Multilevel Paging (Ex)
2. Cache
• OS Roles
– Main Goal
– Fetch Policy PART II
– Placement Policy
– Replacement Policy
• Intel MMU
• Questions (Credits to Dr. Ahmed Salah)
Learning Outcomes
• Stanford CS140
– Lec.5 Virtual Memory (H/W)
• Berkeley CS162
– Lec.13 Address Translation + Caching
Virtual Paging
• 3 Problems:
1. Sparse VM + Large Page Table!
2. Page table grows in RAM!
• Proportional to virtual memory/process
3. # references to RAM per program reference!!
• 1 Issue:
– Page Size
Virtual Paging
• 3 Problems:
1. Sparse VM + Large Page Table!
2. Page table grows in RAM!
• Proportional to virtual memory/process
3. # references to RAM per program reference!!
• 1 Issue:
– Page Size
Virtual Paging
Pr3: # ref’s to RAM per program ref!!
• Idea:
– In simple paging: each virtual memory reference can cause two
physical memory accesses
• One to fetch the page table
• One to fetch the data
512 Entries
Per Table
IA64: 64bit addresses: Six-level page table!?
No!
Too slow
Too many almost-empty tables
HOW
is this done?
Virtual Paging
Pr3: # ref’s to RAM per program ref!!
• Accessing TLB:
– As the TLB only contains some of the page table entries we
cannot simply index into the TLB based on the page number
• Each TLB entry must include the page number as well as the
complete page table entry
– The process is able to simultaneously query numerous TLB
entries to determine if there is a page number match
Virtual Paging
Pr3: # ref’s to RAM per program ref!!
• Accessing TLB:
Direct Mapping Associative Map.
Virtual Paging
Cache the Address
TLB &
Cache
Cache the Code/Data
Memory
Pr3: # ref’s to RAM per program
ref!!
What happens to TLB on a Context Switch?
• Need to do something, since TLBs map virtual addresses
to physical addresses
– Address Space just changed, so TLB entries no longer valid!
• Options?
– Invalidate TLB: simple but might be expensive
» What if switching frequently between processes?
– Include ProcessID in TLB
» This is an architectural solution: needs hardware
What if TLB change?
– e.g., to move page from memory to disk or vice versa…
– Must invalidate TLB entry!
» Otherwise, might think that page is still in memory!
– Called “TLB Consistency”
10/19/15 Kubiatowicz CS162 ©UCB Fall 2015 Lec 14.22
Virtual Paging
Page Table
Pr3: # ref’s to RAM per program ref!! P# Fr# P M
0 100 1 0
• Example: Given: 1 200 1 1
2 300 1 0
• Virtual size / process = 2 KB
3 400 1 0
• Page size = 64 bytes
4 500 1 1
• “Process A” reference addresses: 5 - 0 0
5, 64, 128, 512, 20, 30, 520,256, 30, 520, 100 6 600 1 1
• TLB size = 3 entries 7 - 0 0
• Questions: 8 700 1 0