COSS - Lecture - 5 - With Annotation
COSS - Lecture - 5 - With Annotation
Software Systems
0 2 0 2 2 0 0 2 0 0 0 2 1
Problem 6
• Suppose a 1024-byte cache has an access time of 0.1 microseconds and the main memory stores
1 Mbytes with an access time of 1 microsecond. A referenced memory block that is not in cache
must be loaded into cache .
• Answer the following questions:
a) What is the number of bits needed to address the main memory?
a) If the cache hit ratio is 95%, what is the average access time for a memory reference?
Avg access time = hit ratio * cache access + (1- hit ratio) * (cache access + memory access)
Associative Mapping
•Given :
• Cache of 128KByte, Cache block of 8 bytes
• 32 MBytes main memory
•Find out
a) Number of bits required to address the memory
e) Tag, Word
Problem 8
•Cache of 64KByte, Cache block of 4 bytes , 16 M Bytes main memory and
associative mapping.
Fill in the blanks:
0 2 0 2 2 0 0 2 0 0 0 2 1
Set Associative Mapping
• Cache is divided into a number of sets (v sets each with k lines)
• m=v*k
• i = j modulo v
where i = cache set number
j = main memory block number
v = number of sets in the cache
• Each set contains ‘k’ number of lines
• A given block maps to any line in a given set
- e.g. Block B can be in any line of set i
• m-way set associative cache
- 2 way set associative mapping 2 lines per set
- A given block can be in one of 2 lines in only one set
Example
• 16 Bytes main memory,
Block Size is 2 Bytes,
• Cache of 8 Bytes, 2 way set
associative cache i = j modulo v Set #
• # address bits 0%2
• Cache line size 1%2
• # main memory blocks 2%2
• # Number of cache lines 3%2
• # lines per set 4%2
• # of sets
5%2
6%2
7%2
Two-Way Set Associative Cache Organization
Set Associative Mapping Summary
• A computer has an 8 GByte memory with 64 bit word sizes. Each block of
memory stores 16 words. The computer has a direct-mapped cache of 128
blocks. The computer uses word level addressing. What is the address
format? If we change the cache to a 4- way set associative cache, what is
the new address format?
Replacement Algorithms (1/3)
• Least Recently used (LRU): Replace the block that has been in
the cache longest with no reference to it
- e.g. 2 way set associative
- Uses “USE” bits
- Most effective method
• Least frequently used: Replace block which has had fewest hits
- Uses counter with each line
• First in first out (FIFO): Replace block that has been in cache
longest
- Round robin or circular buffer technique
• Random
Problem 3
time 0 1 2 3 4 5 6 7 8 9 10 11
L0
L1
L2
L3
H/M
Problem 2 - LFU
Ref 0 4 0 2 1 8 0 1 2 3 0 4
L0
L1
L2
L3
H/M
Problem 2 - FIFO
Ref 0 4 0 2 1 8 0 1 2 3 0 4
L0
L1
L2
L3
H/M