Virtual and Cache Memory Example

33
Virtual and Cache Memory Example Warning: this is intended to be viewed as a slide show. Do NOT print all slides. Print just Slide 2 for an overview.

description

Virtual and Cache Memory Example. Warning: this is intended to be viewed as a slide show. Do NOT print all slides. Print just Slide 2 for an overview. Virtual and Cache Memory Example. Virtual Address. re-issue request. Check TLB. Search Cache. Search Page Table. no. yes. no. Hit?. - PowerPoint PPT Presentation

Transcript of Virtual and Cache Memory Example

Page 1: Virtual and Cache Memory Example

Virtual and Cache Memory Example

Warning: this is intended to be viewed as a slide show.

Do NOT print all slides.

Print just Slide 2 for an overview.

Page 2: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Page 3: Virtual and Cache Memory Example

Ideal Situation:TLB hit, Cache hit

Page 4: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Processor: The processor issues a request for a piece of memory at a virtual address (the processor doesn’t know it is a virtual address, it just knows the address).

Page 5: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: the MMU checks in the Translation Lookaside Buffer (TLB) to see if the data at the virtual address is stored in main memory.

Page 6: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If the mapping between the virtual address and the physical address is in the TLB, a TLB hit occurs, otherwise a TLB miss occurs.

Page 7: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If a TLB hit occurred, the MMU uses the TLB mapping to convert the virtual address to a physical address (which refers to a location in main memory).

Page 8: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: Use hardware to search in the cache (using tags) to see if the data at that memory address is stored in the cache.

Page 9: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: If the memory address is found in the cache, then a cache hit has occurred. If it is not found, then a cache miss has occurred.T = hC + (1-h)M

Page 10: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: Return requested data from cache.

Page 11: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Memory: Return requested data. Total time, with TLB hit and cache hit: 4-5ns.

Page 12: Virtual and Cache Memory Example

Cache Memory:What if you have a cache miss?

A cache miss occurs when the data that you are trying to access is not currently in the cache.

Page 13: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: If the memory address is found in the cache, then a cache hit has occurred. If it is not found, then a cache miss has occurred.T = hC + (1-h)M

Page 14: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: Fetch the data from main memory and store it in the cache, using a replacement algorithm to evict previously cached data if necessary. Time: >220ns

Page 15: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Cache Memory: Return requested data from cache.

Page 16: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Memory: Return requested data. Total time, with TLB hit and cache miss: ~220ns.

Page 17: Virtual and Cache Memory Example

Virtual Memory: What if you have a TLB miss?

A TLB miss occurs when the mapping between the virtual address and the physical address is not stored in the TLB. It does not mean that the data is not in main memory.

Page 18: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If the mapping between the virtual address and the physical address is in the TLB, a TLB hit occurs, otherwise a TLB miss occurs.

Page 19: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Search the actual page table for the mapping of the virtual address to a physical address, indicating that the data at that address currently in main memory.

Page 20: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If the virtual address has a mapping in the page table, then the data is in main memory. This is a page hit. Otherwise, it is a page fault.

Page 21: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Use the address mapping in the page table to generate the physical address associated with the virtual address, indicating where the data is in main memory.

Page 22: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Update the TLB with the mapping between the virtual address and the physical address.

Page 23: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Reissue the memory request. This time, a TLB hit will occur and searching the cache will happen as in the first example.

Page 24: Virtual and Cache Memory Example

Virtual Memory: What if you have a page fault?

A page fault occurs when the data at the virtual address is not currently stored in main memory, so does not have a physical address stored in the page table.

Page 25: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If the virtual address has a mapping in the page table, then the data is in main memory. This is a page hit. Otherwise, it is a page fault.

Page 26: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: If a page fault has occurred, then update main memory by bringing the data in from secondary storage, using a replacement algorithm if needed.

Page 27: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Update the Page Table with the mapping between the virtual address and the physical address.

Page 28: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Generate the physical address indicating where the data at the virtual address is stored in main memory.

Page 29: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Update the TLB with the mapping between the virtual address and the physical address.

Page 30: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Virtual Memory: Reissue the memory request. This time, a TLB hit will occur and searching the cache will happen as in the first example. Total time: > 6ms.

Page 31: Virtual and Cache Memory Example

GeneratePhys. Address

Check TLB

Hit? Hit?

Virtual Address

Memory Data

Search Cache

Return Datafrom Cache

Update Cache From Main Mem.

yes

yes

no

SearchPage Table

Hit?

GeneratePhys. Address

Update TLB

Update Main Mem.From Disk

UpdatePage Table

yes

no

Virtual MemoryCache

re-issue request

no

Hardware Software

Virtual and Cache Memory Example

Page 32: Virtual and Cache Memory Example
Page 33: Virtual and Cache Memory Example

GeneratePhys. Address

Search#1

Hit? Hit?

Virtual Address

Memory Data

Search#2

Return Data

Update#2

yes

yes

no

Search#3

Hit?

GeneratePhys. Address

Update#1

Update Main Mem.From Disk

Update#3

yes

no

re-issue request

no

Hardware Software