topic 18 (updated): virtual memory · • current process suspends, others can resume • os has...
TRANSCRIPT
![Page 1: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/1.jpg)
1
Topic 18 (updated): Virtual Memory
COS / ELE 375
Computer Architecture and Organization
Princeton University Fall 2015
Prof. David August
![Page 2: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/2.jpg)
2
Virtual Memory
Any time you see virtual, think “using a level of indirection”
Virtual memory: level of indirection to physical memory
• Program uses virtual memory addresses • Virtual address is converted to a physical address • Physical address indicates physical location of data
• Physical location can be memory or disk! 0x800
Virtual address
Mem: 0x3C00
Physical address
Disk: 0x803C4
![Page 3: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/3.jpg)
3
Virtual Memory
![Page 4: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/4.jpg)
4
Virtual Memory
1
![Page 5: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/5.jpg)
5
Virtual Memory: Take 1
Main memory may not be large enough for a task • Programmers turn to overlays and disk
• Many programs would have to do this
• Programmers should have to worry about main memory size across machines
Use virtual memory to make memory look bigger for all programs
![Page 6: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/6.jpg)
6
A System with Only Physical Memory
Examples: Most Cray machines, early PCs, nearly all current embedded systems, etc.
CPU
0: 1:
N-1:
Memory
Store 0x10
Load 0xf0
CPU’s load or store addresses used directly to access memory.
![Page 7: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/7.jpg)
7
A System with Virtual Memory Examples: modern workstations, servers, PCs, etc.
Address Translation: the hardware converts virtual addresses into physical addresses via an OS-managed lookup table (page table)
CPU
0: 1:
N-1:
Memory
Load 0xf0
0: 1:
P-1:
Page Table
Store 0x10
Disk
Virtual Addresses Physical
Addresses
![Page 8: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/8.jpg)
8
Page Faults (Similar to “Cache Misses”) What if an object is on disk rather than in memory? 1. Page table indicates that the virtual address is not in memory 2. OS trap handler is invoked, moving data from disk into memory
• Current process suspends, others can resume • OS has full control over placement, etc.
CPU
0: 1:
N-1:
Memory
Load 0x05
0: 1:
P-1:
Page Table
Store 0xf8
Disk
Virtual Addresses Physical
Addresses
Working Set
![Page 9: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/9.jpg)
9
Virtual Memory
2
![Page 10: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/10.jpg)
10
Virtual Memory: Take 2
Concurrently executing programs will interfere in memory • At some point, programs assume addresses • These addresses may conflict if we don’t manage them. • Which programs will execute concurrently?
• Don’t know • Manage dynamically
• Programs can maliciously interfere with each other! • They need protection from one another
Use virtual memory to avoid/manage conflict between programs
![Page 11: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/11.jpg)
11
Process 1:
Virtual Addresses Physical Addresses
VP 1 VP 2
Process 2:
PP 2 Address Translation 0
0
N-1
0
N-1 M-1
VP 1 VP 2
PP 7
PP 10
(Read-only library code)
Separate Virtual Address Spaces • Each process has its own virtual address space • OS controls how virtual is assigned to physical memory
![Page 12: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/12.jpg)
12
Motivation: Process Protection Page table entry contains access rights information • Hardware enforces this protection (trap into OS if
violation occurs) Page Tables
Process i:
Physical Addr Read? Write? PP 9 Yes No
PP 4 Yes Yes
XXXXXXX No No
VP 0:
VP 1:
VP 2: • • •
• • •
• • •
Process j:
0: 1:
N-1:
Memory
Physical Addr Read? Write? PP 6 Yes Yes
PP 9 Yes No
XXXXXXX No No • • •
• • •
• • •
VP 0:
VP 1:
VP 2:
![Page 13: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/13.jpg)
13
Virtual Memory
3
![Page 14: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/14.jpg)
14
Virtual Memory: Take 3
Programs and data exist on disk • Registers, caches, and memory just make using the
data on disk faster • Locality at different granularities
Use virtual memory to improve performance, hide physical
location from program
![Page 15: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/15.jpg)
15
Levels in Memory Hierarchy
CPU regs
C a c h e
Memory disk
size: speed: $/Mbyte: block size:
200 B 3 ns 8 B
Register Cache Memory Disk Memory 32 KB / 4MB 6 ns $100/MB 32 B
128 MB 60 ns $1.50/MB 8 KB
20 GB 8 ms $0.05/MB
larger, slower, cheaper
8 B 32 B 8 KB
cache virtual memory
![Page 16: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/16.jpg)
16
![Page 17: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/17.jpg)
17
Virtual Memory
Just like caches, but origins are different • Cache - performance goals • Virtual Memory - programmability/multiprogram goals
Blocks are called Pages • A virtual address consists of
• A virtual page number • A page offset field (low order bits of the address)
Virtual page number Page offset 0 11 31
![Page 18: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/18.jpg)
Page Tables
Each process gets its own page table, why?
![Page 19: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/19.jpg)
Page Tables
Can’t Execute From Here
![Page 20: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/20.jpg)
20
Page Faults
Blocks are called Pages Page Tables translate virtual to physical page numbers Misses are call Page faults (handled as an exception) • Retrieve data from disk • Huge miss penalty, pages are fairly large (how big?) • Reducing page faults is important • Can handle the faults in software instead of hardware • Using write-through is too expensive, use writeback
Virtual page number Page offset 0 11 31
![Page 21: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/21.jpg)
21
Servicing a Page Fault
1. Make space in memory by writing physical page to disk • Page Frames • Replacement policy?
2. Load page • Loading pages could waste processor time, use DMA • DMA allows processor to do something else
3. OS updates the process's page table • Desired data is in memory for process to resume
![Page 22: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/22.jpg)
22
Servicing a Page Fault
1. Processor Signals Controller “Read block of length P starting at disk address X and store starting at memory address Y”
2. DMA Read Occurs 3. I / O Controller Signals
Completion • Interrupts processor • Can resume suspended process
disk Disk
disk Disk
Memory-I/O bus
Processor
Cache
Memory I/O
controller
Reg
(2) DMA Transfer
(1) Initiate Block Read
(3) Read Done
![Page 23: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/23.jpg)
Where Is the Page Table?
![Page 24: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/24.jpg)
24
Making Translation Faster: The TLB Translation Look-Aside Buffer
![Page 25: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/25.jpg)
TLB Design Issues
Accessed frequently: speed is important TLB Miss Involves (not to be confused with page fault):
1. Stall pipeline 2. Invoke Operating System (what about OS pages?) 3. Read Page Table 4. Write entry in TLB (evicting old entry?) 5. Return to user code 6. Restart at reference
MIPS. Another HW Option?
![Page 26: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/26.jpg)
26
TLB Design Issues
Clearly, we want to minimize TLB misses:
• Can be fully-associative, set-associative, or direct mapped
• Often fully associative, can be set associative
• Sized to maximize hits, but make timing • Usually not more than 128, 256 entries (associtivity)
![Page 27: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/27.jpg)
27
![Page 28: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/28.jpg)
28
Loading Your Program: A Neat Trick
1. Ask operating system to create a new process 2. Construct a page table for this process 3. Mark all page table entries as invalid with a pointer to
the disk image of the program 4. Run the program and get an immediate page fault on
the first instruction.
![Page 29: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/29.jpg)
29
Process Interactions
Virtual Addresses are per Process Context Switch: Save “state”: regs, PC, page table (PTBR) TLB? • Could Flush TLB
• Every time perform context switch • Refill for new process by series of TLB misses • ~100 clock cycles each
• Could Include Process ID Tag with TLB Entry • Identifies which address space being accessed • OK even when sharing physical pages
![Page 30: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/30.jpg)
30
![Page 31: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/31.jpg)
31
A System with Physical Memory
Examples: Most Cray machines, early PCs, nearly all current embedded systems, etc.
CPU
0: 1:
N-1:
Memory
Store 0x10
Load 0xf0
CPU’s load or store addresses used directly to access memory.
![Page 32: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/32.jpg)
32
A System with Virtual Memory
CPU
0: 1:
N-1:
Memory
Load 0x05
0: 1:
P-1:
Page Table
Store 0xf8
Disk
Virtual Addresses Physical
Addresses
Working Set
![Page 33: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/33.jpg)
Page Tables
Each process gets its own page table, why?
![Page 34: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/34.jpg)
34
Process 1:
Virtual Addresses Physical Addresses
VP 1 VP 2
Process 2:
PP 2 Address Translation 0
0
N-1
0
N-1 M-1
VP 1 VP 2
PP 7
PP 10
(Read-only library code)
Separate Virtual Address Spaces • Each process has its own virtual address space • OS controls how virtual is assigned to physical memory
Page Frames
![Page 35: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/35.jpg)
35
Process Protection Page table entry contains access rights information • Hardware enforces this protection (trap into OS if
violation occurs) Page Tables
Process i:
Physical Addr Read? Write? PP 9 Yes No
PP 4 Yes Yes
XXXXXXX No No
VP 0:
VP 1:
VP 2: • • •
• • •
• • •
Process j:
0: 1:
N-1:
Memory
Physical Addr Read? Write? PP 6 Yes Yes
PP 9 Yes No
XXXXXXX No No • • •
• • •
• • •
VP 0:
VP 1:
VP 2:
![Page 36: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/36.jpg)
36
Virtual Memory Lingo
Blocks are called Pages Misses are called Page faults (handled as an exception) • Retrieve data from disk • Huge miss penalty, pages are fairly large (4-8K) • Reducing page faults is important • Can handle the faults in software instead of hardware • Using write-through is too expensive, use writeback
Virtual page number Page offset 0 11 31
![Page 37: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/37.jpg)
37
Making Translation Faster: The TLB Translation Look-Aside Buffer
![Page 38: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/38.jpg)
38
Virtual Memory Summary
Virtual memory provides • Protection and sharing • Illusion of large main memory • Speed/Caching (when viewed from disk perspective)
• Virtual Memory requires twice as many memory accesses, so cache page table entries in the TLB.
• Three things can go wrong on a memory access • TLB miss • Page fault • Cache miss
Caches and virtual memory?
![Page 39: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/39.jpg)
39
![Page 40: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/40.jpg)
40
Virtually Memory and Caches: 3 Options 1. Physically Addressed Cache
Translate before accessing cache Cache is: • Physically Indexed • Physically Tagged
• Allows multiple processes to have blocks in cache at same time, share pages, etc.
• Access rights checked as part of translation
• Speed?
CPU
Trans
Cache
MEM
VA
PA
PA
![Page 41: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/41.jpg)
41
Virtually Memory and Caches: 3 Options 2. Virtually Addressed Cache
CPU
Cache
Trans
MEM
VA
VA
PA
Translate after accessing cache Cache is: • Virtually Indexed • Virtually Tagged
• Translate Only on Miss!
• The synonym/alias problem • How would you make this work?
![Page 42: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/42.jpg)
42
Virtually Memory and Caches: 3 Options 3. Virtually Indexed, Physically Tagged
CPU
$ Trans
MEM
VA
PA L2 $
Translate during cache access Cache is: • Physically/Virtually Indexed • Physically Tagged • Excellent performance • Requires cache index to remain
invariant across translation. How?
![Page 43: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/43.jpg)
43
Virtually Indexed, Physically Tagged Example Note Size Here
![Page 44: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/44.jpg)
44
Issues With Overlapped TLB Access • Limits cache parameters: small caches, large page sizes,
or high n-way set-associative caches • Example: Suppose everything the same except that the
cache is increased to 8 K bytes instead of 4 K
11 2 00
Virtual page # Displ. 20 12
cache index
This bit is changed by VA translation, but is needed for cache lookup
Solutions: Go to 8K byte page sizes; Go to 2-way set-associative cache; or SW guarantee VA[13]=PA[13]
1K 4 bytes 4 bytes
10
2-way set-associative cache
![Page 45: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/45.jpg)
45
![Page 46: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/46.jpg)
46
Some Page Table Math
# of page table entries on 64-bit machine with 4K pages:
264 / 212 = (only) 252 entries Size of page table:
252 * 8 bytes per table entry = 255 bytes (only 32 petabytes)
kilo- 210, mega- 220, giga- 230, tera- 240,
peta- 250, exa- 260, zetta- 270, yotta- 280
![Page 47: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/47.jpg)
47
Some Page Table Math
Size of page table:
252 * 8 bytes per table entry = 255 bytes (only 32 petabytes)
Oh, by the way, that’s per process…
![Page 48: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/48.jpg)
48
Solutions 1. Limit Page Table Size • Keep a limit • Check limit before going to page
If more entries needed (process needs more memory): 1. Up the limit 2. Add the entries
Good way to do this: • Double page table size at each step: • Limit is: 0…01…1 (number 0 à 2n-1)
Also, can grow bi-directionally (stack/heap)
![Page 49: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/49.jpg)
49
Solutions 2. Inverted Page Table
!! These things are UGLY !! Each Physical Frame has an entry. Inverted page table size:
Physical memory size = 8 Gigabytes = 233 bytes Page frame size = 4K = 212 bytes
233 / 212 = 221 entries 221 entries * 8 bytes per entry (incl. PID) = 224 bytes
16MB, not too bad (not per process!)
![Page 50: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/50.jpg)
50
Solutions 3. Multilevel Page Tables
Key Idea: Take advantage of sparse use of virtual memory Create a hierarchy of pages:
Not Used
Create a red page table to describe very large pages (coarse cut of virtual address
space) Create a black page
table for each red page table entry used (finer
cut of superpage)
![Page 51: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/51.jpg)
51
Solution 3: Multi-Level Page Tables Example
![Page 52: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/52.jpg)
52
Solutions 4. Page The Page Table
• Compatible with other methods
• Tricky to get right • Need to have page portion that refers to rest of page
table always in memory
![Page 53: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/53.jpg)
53
![Page 54: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/54.jpg)
54
Segmentation Real Stuff (x86 IA32)
• Segments: Variable-sized pages
• Virtual address are segment number + offset • Generally 2 quantities
• Segment register • Offset is address
• Bounds checking
• Nice in some ways: • Program fits in one segment - set ReadOnly/Executable • Data in another - set ReadWrite/NonExecutable
![Page 55: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/55.jpg)
55
x86: Segmentation (From: IA-32 Intel® Architecture Software Developers Manual)
![Page 56: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/56.jpg)
56
x86: Segment Registers (From: IA-32 Intel® Architecture Software Developers Manual)
Pages and Segments Can Co-exist!
![Page 57: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/57.jpg)
57
![Page 58: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/58.jpg)
58
Relating to the MIPS Pipeline
Inst Fetch Dcd/ Reg ALU / E.A. Memory Write Reg TLB I-Cache RF Operation WB
E.A. TLB D-Cache
MIPS R3000 Pipeline
![Page 59: Topic 18 (updated): Virtual Memory · • Current process suspends, others can resume • OS has full control over placement, etc. CPU 0: 1: N-1: Memory Load 0x05 0: 1: P-1: Page](https://reader036.vdocuments.us/reader036/viewer/2022070918/5fb8281f348b2b50b30f512a/html5/thumbnails/59.jpg)
59
Summary
• Real/Virtual Tag/Index Cache
• Multi Level Page Tables
• Segments
• Pipeline Interaction