


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Cache Memory and Virtual Memory
The Least Recently Used (LRU) replacement algorithm describes which virtual memory page or cache block should be replaced when a new page or cache block needs to be brought into main memory or the cache. LRU replacement means that the page or block that was least recently used should be replaced.
Cache Memory
Temporal Locality - data/instructions that have been used recently are likely to be used again. For example: instructions in a loop, data used in a loop.
Spatial Locality - data/instructions near data/instructions that have been used are likely to be used soon. For example: linear execution of instructions, stepping through an array.
Locality of reference allows the cache to operate efficiently because it describes the principles that data that was recently used will probably be used again, and data that is close to data that has been used will probably be used soon.
Virtual Memory
The working set is the data, instructions, and stack that is currently being used by a running program.
Thrashing occurs when the computer is spending more time accessing memory (to swap pages in and out of main memory) than it spend actually processing.
The Translation Lookaside Buffer (TLB) acts as a cache for the page table. It contains translations of virtual addresses to physical addresses.
Fall, 2004 Homework: Memory updated: 3-nov-
Cache Performance Calculation
z hn = hit rate in level n cache z Cn = time to fetch a word from level n cache z M = time to access a word from main memory.
1a. Without looking at your notes, try to derive the formula for determining the average access time for a word in a system with a single cache. Think about it!
t = h 1 C 1 + (1 - h 1 )M
1b. Assume the following values for a theoretical system containing an L1 cache.
Determine the average access time for a memory word in the described system.
2a. Without looking at your notes, try to derive the formula for determining the average access time for a word in a system with three caches. Think about it!
t = h 1 C 1 + (1 - h 1 )(h 2 C 2 + (1 - h 2 )(h 3 C 3 + (1 - h 3 )M))
2b. Assume the following values for a theoretical system containing an L1, L2, and L3 cache.
Determine the average access time for a memory word in the described system.
Location Latency Hit Rate
L1 (on-chip) C^1 = 5ns^ h 1 = 50%
Main Memory M = 100ns h 3 = 100%
Location Latency Hit Rate
L1 (on-chip) C^1 = 5ns^ h 1 = 50%
L2 (on-chip) C^2 = 10ns^ h 2 = 75%
L3 (off-chip) C^3 = 35ns^ h 3 = 90%
Main Memory M = 100ns hM = 100%
3a. Suppose the system has a 2-way set associative cache. Now how is the address broken up? How many main memory blocks maps to each cache set?
A set-associative cache works almost the same as a direct-mapped cache. The only difference is that the “Block” field becomes the “set” field. In this case, we have 1024 cache lines/blocks. Because we are
using a 2-way set-associative cache, there are two lines per set, for a total of 512 sets (2 9 sets). This means we need 9 bits to determine which set a particular address would belong to, so our address is broken up as follows:
Tag = 4 bits Set = 9 bits Word = 6 bits
Each set holds two blocks, so twice as many main memory blocks can map to each set. This is reflected in the fact that the tag field now includes 4 bits, indicating that 16 different main memory blocks can map to each set. The 4-bit tag indicates which of the 16 memory blocks that could occupy that block in the set is actually occupying it.
3b. Describe how the system will check if a given word is currently in the cache. How many compares between the address and the tag field will be necessary?
To check if the word we want is in the cache, we use the 9 bits of the set field to determine which of the 512 cache sets our word could be stored in. Then we check the first 4 bits of the address against each tag in that set. Because there are two lines in each set (2-way set associative) we must make two compares. If we find a tag that matches our address, our word is in the cache and we use the last 6 bits of the address to select it from the cache line. Otherwise, we get a new block from main memory and replace one of the two lines in our cache set.