Memory Managment
Memory Managment
Acknowledgements: Prof. Xiangqun Chen at PKU and Prof. Yuanyuan Zhou at UCSD
Review
Memory
Management
Virtual Memory
The
Virtual Addresses
physical
addresses
virtual
addresses
processor
Many
vmap
physical
memory
Fixed Partitions
Physical
Variable Partitions
extension physical memory is broken up into
variable sized partitions
Natural
5 Monitor Job 7
Job 5
Job 3
Job 8
Free6
Job
Job 3
Job 8
Free6
Job
Job 8
Free6
Job
Job 8
Job 8
Free6
Job
Job 6
Free
7
Swapping
Move
Allows
Processes
virtual memory
Virtual
Memory
Physical
Memory
Page 1
Page 2
Page 3
Page N
Paging
Translating
addresses
Virtual address has two parts: virtual page number and offset
Virtual page number (VPN) is an index into a page table
Page table determines page frame number (PFN)
Physical address is PFN::offset
Page
tables
10
Page
M R
Prot
20
The Modify bit says whether or not the page has been written
It is set when a write to the page occurs
The Reference bit says whether the page has been accessed
It is set when a read or write to the page occurs
The Valid bit says whether or not the PTE can be used
It is checked each time the virtual address is used
The Protection bits say what operations are allowed on page
Read, write, execute
The page frame number (PFN) determines physical page
11
Natural
support
12
This Lecture
Paging Mechanisms
13
Page Table
0
P 1
0
1 P-> F
1
0
1
Virtual Memory
P
Contents(P,D)
Physical Memory
F
14
Virtual Memory
Virtual Address (004006)
004 006
Contents(4006)
004
006
Physical Memory
005
006
005
Contents(5006)
006
Paging Issues
Page
size is 2n
table:
16
How
Observation: Only need to map the portion of the address space actually
being used (tiny fraction of entire addr space)
How
So
now what?
17
Discussion
How to reduce page table size if the virtual pages are
sparse?
18
page tables
4K pages, 4 bytes/PTE
How many bits in offset? 4K = 12 bits
Want master page table in one page: 4K/4 bytes = 1K entries
Hence, 1024 secondary page tables. How many bits?
Master (1K) = 10, offset = 12, secondary = 32 10 12 = 10 bits
19
Secondary
Offset
Physical Address
Page table
Page frame
Offset
Page frame
20
21
Efficient Translations
Our
Now
Two lookups into the page tables, a third to fetch the data
can we use paging but also have lookups cost about the
same as fetching from memory?
Cache translations in hardware
Translation Lookaside Buffer (TLB)
TLB managed by Memory Management Unit (MMU)
22
offset
VPage#
PPage#
VPage#
PPage#
...
...
.
.
.
VPage#
Miss
Real
...
PPage#
page
TLB
table
Hit
PPage #
offset
Physical address
23
TLBs
Translation
Lookaside Buffers
implemented in hardware
TLBs
exploit locality
TLB Function
If
25
Page Table
0
P 1
0
1 P-> F
1
0
1
First
26
27
28
Managing TLBs
Address
Who
29
30
Optional
(necessary) bits
(useful) bits
Process tag
Reference
Modify
Cacheable
31
of TLB
Content-addressable memory/registers
TLB
32
memory
The physical memory is small
Too many running processes
33
Demand Paging
Real Memory
Request Page 3
Page Table
VM Frame
3 1
2
3
4
Memory
1
2
3
4
Disk
1
8
34
Paging
Real Memory
Request Page 1
Page Table
VM Frame
3 1
1 2
3
4
Memory
1
2
3
4
8
35
Paging
Real Memory
Request Page 6
Page Table
VM Frame
3 1
1 2
6 3
4
Memory
1
2
3
4
8
36
Paging
Real Memory
Request Page 2
Page Table
VM Frame
3 1
1 2
6 3
2 4
Memory
1
2
3
8
37
Paging
Real Memory
Page Table
VM Frame
3 1
1 2
6 3
2 4
Memory
1
2
3
4
8
38
Paging
Real Memory
Page Table
VM Frame
3 1
8 2
6 3
2 4
Memory
1
2
3
Disk
1
8
39
Summary
Paging mechanisms:
Optimizations
Next
Good Luck!
40