Cache Memory
Cache Memory
Outline
• Cache Memory Principles
• Elements of Cache Design
• Cache Addresses
• Cache Size
• Mapping Function
• Direct
• Associative
• Set Associative
Cache Memory Principles
• Cache memory is intended to give memory speed approaching that of
the fastest memories available, and at the same time provide a large
memory size at the price of less expensive types of semiconductor
memories.
• There is a relatively large and slow main memory together with a
smaller, faster cache memory. The cache contains a copy of portions
of main memory.
• When the processor attempts to read a word of memory, a check is
made to determine if the word is in the cache. If so, the word is
delivered to the processor.
• If not, a block of main memory, consisting of some fixed number of
words, is read into the cache and then the word is delivered to the
processor. Because of the phenomenon of locality of reference, when
a block of data is fetched into the cache to satisfy a single memory
reference, it is likely that there will be future references to that same
memory location or to other words in the block.
Cache and Main Memory
• Figure depicts the use of multiple levels of cache. The L2 cache is
slower and typically larger than the L1 cache, and the L3 cache is
slower and typically larger than the L2 cache.
Structure of cache and main
memory
Figure depicts the structure of a cache/main-memory system.
Main memory consists of up to 2n addressable words, with each
word having a unique n-bit address.
S Data Field
Address field
Cache Size=2r+w=216
0 0 16384
1
1
2
2
. .
. .
. .
32767 1677721
16383= 5=2s
16383= 214 -1
214 -1
Tag = s Word = w
SET-ASSOCIATIVE MAPPING
• Set-associative mapping is a compromise that exhibits the strengths
of both the direct and associative approaches while reducing their
disadvantages.
• In this case, the cache consists of a number sets, each of which
consists of a number of lines. The relationships are
• Main memory Format
Tag = s – d Set = d Word = w
4.1. A set-associative cache consists of 64 lines, or slots, divided into four-line sets. Main memory
contains 4K blocks of 128 words each. Show the format of main memory addresses.
k = 4,
• m = 64
• m = v k => v = m / k, v = 64 / 4 = 16
• v = 2d => 16 = 2d => 24 = 2d => d = 4
• 4 K Blocks of 128 words each
• Block Size = 128 = 2w = 27 => w = 7
• Number of Blocks in memory = 2s = 4 K = 212 s = 12
• Tag = s-d =8 Tag = s-d =8 Set d = 4 Word w= 7
• Set = 4
• Word = 7
(Questions 4.2,4.3,4.4(c) ,4.5,4.6 done in class)