Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 8

Set-Associative Mapping

 Set Associative Mapping is the easy control of the direct


mapping cache and the more flexible mapping of the fully
associative cache.
 The disadvantage of direct mapping is that two words with
the same index in their address but with different tag values
cannot reside in cache memory at the same time
 In set associative mapping, each cache location can have
more than one pair of tag + data items, each word of cache
can store two or more word of memory under the same index
address
 In general, a set associative cache of set size k will
accommodate k words of main memory in each word of
cache.
 Each index address refers to two data words and their associated tags.
 Each tag requires six bits and each data word has 12 bits, so the word length is
2*(6+12) = 36 bits
Memory Memory data
Add.

Main Memory Two Way Associative mapping Cache


The words stored at addresses 01000 and 02000 of main memory are stored in
cache memory at index address 000 ,and words at addresses 02777 and 00777
are stored in cache at index address 777.

On CPU memory request,


1.The index value of the address is used to access the cache.
2.The tag field of the CPU address is then compared with both tags in the cache
to determine if a match occurs.
• The comparison logic is similar to associative memory
search so the name is "set-associative . "

Hit ratio improves as the set size increases as more words with the same index
but different tags can reside in cache.
An increase in the set size increases the number of bits in words of cache and
requires more complex comparison logic.
Writing into Cache

Writing into cache is done in two ways:


1.Write through
2.Write Back

Write through : whenever write operation is performed all write


operations are made to main memory as well as to the cache,
ensuring that main memory is always valid.
 The advantage of the write-through cache is that the main
memory always contains the same data as the cache
contains.
 The main disadvantage is that it generates substantial
memory traffic and may create a bottleneck.
Writing into Cache

Write Back : Cache is updated and marked by the flag. When the
word is removed from cache, flag is checked if it is set the
corresponding address in main memory is updated.

The main disadvantage is that data may be lost in case the cache is
disrupted.
Cache Initialization

 The cache is initialized when power is applied to the


computer or when the main memory is loaded with a
complete set of programs from auxiliary memory.
 After initialization the cache is considered to be empty,
but in effect it contains some nonvalid data
 The cache is initialized by clearing all the valid bits to 0.

 It is customary to include with each word in cache a valid


bit to indicate whether or not the word contains valid data.
Cache Initialization

 Valid bit of word is set whenever the word is read from


main memory and updated in cache.

 If valid bit is 0, new word automatically replace the invalid


data.

 Thus the initialization condition has the effect of forcing


misses from the cache until it fills with valid data.
Thank You

You might also like