Caches and Virtual Memory:-Plan
Caches and Virtual Memory:-Plan
Caches
Virtual memory as a cache for the disk.
Virtual addresses, Pages and page-tables.
Write-through or Write Back?
Making Page tables fast :- Translation Look-aside Buffers.
CPU
Increasing distance
Level 1
from the CPU in
access time
Level n
Valid
Addresses that use this entry
Entry Tag Data
7
6
5
4
3 96-127, 65632-65663, 131068-131099
2 64-95, 65600-65631, 131036-131067, …
1 32-63, 65568-65599, 131004-131035, …
0 0-31, 65536-65567, 131072-131003, …
(a)
Bits 16 11 3 2
(b)
Caches and Virtual Memory – Justin Pearson Page 5
Caches
Cache hit The item you are looking for is in the cache.
Cache miss the item you are looking for is not in the cache, you
have to copy the item from the main memory.
7
6
5
4
3
2
1
0
Disk addresses
Disk addresses
Virtual address
31 30 29 28 27 15 14 13 12 11 10 9 8 3210
Translation
29 28 27 15 14 13 12 11 10 9 8 3210
Physical address
Virtual address
31 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
20 12
Page table
18
If 0 then page is not
present in memory
29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
Physical address
Virtual page
number
Page table
Physical memory
Physical page or
Valid disk address
1
1
1
1
0
1
1
0
1 Disk storage
1
0
1
Virtual page
number
Page table
Physical memory
Physical page or
Valid disk address
1
1
1
1
0
1
1
0
1 Disk storage
1
0
1
If each process has it own page table, then you can stop one
process overwriting or reading the data of another process. How?
Programs can be compiled to run at one address and don’t need
to be relocated when loaded. Why?
Process can share memory blocks. How?
Suppose a page is 212 bytes and you have a virtual address space
of 232 bytes, how many pages are there?
There would be
232 32 12
= 2 = 222
212
pages.
Suppose each entry in the page table took up 4-bytes (not
unreasonable) then the size of a page table for a process would
be:
222 22 = 224 = 16Meg
What ever scheme you use to optimise your page table you want
to minimise the amount of time you spend translating virtual
addresses to physical addresses.
Remember every address request a process makes in a virtual
address request. Processes can only make virtual address request
they never have access to the physical addresses.
If virtual address translation is slow, this will be a real bottleneck.
1
1 Physical memory
1
1
0
1
Page table
Physical page
Validor disk address
1
1
1 Disk storage
1
0
1
1
0
1
1
0
1
Virtual address
TLB access
No Yes
Write?
Write protection
exception Write data into cache,
No Yes update the tag, and put
Cache miss stall Cache hit? the data and the address
into the write buffer
Deliver data
to the CPU