DECO - Module 4.3 - Cache
DECO - Module 4.3 - Cache
DECO - Module 4.3 - Cache
CACHE MEMORY
Module IV : CACHE MEMORY
4
Cache operation – overview
5
How data is copied into cache?
Hit Ratio :The ratio of the total number of hits divided by the total CPU
accesses to memory (i.e. hits plus misses) is called Hit Ratio.
Hit Ratio = Total Number of Hits / (Total Number of Hits + Total Number of
Miss)
There are fewer cache lines than main memory blocks, an algorithm is
needed for mapping main memory blocks into cache lines.
There is also a need for a way to determine which main memory block
currently occupies a cache line.
The choice of the mapping function dictates how the cache is
organized.
Three techniques can be used:
1. Associative mapping
2. Direct (single or block mapping)
3. Set associative mapping
Example of cache memory
This permits any location in cache to store any word from main
memory.
The steps of the Associative Mapping are:
1. A CPU address of 15 bits is put in the argument register and the
associative memory is searched for matching address.
A:If the address is found, 12-bit data is read and sent to CPU
B: If no match occurs, the main memory is accessed for word.
2. If all the blocks are already in use, it’s usually best to replace the least
recently used one, if if it hasn’t used it in a while, it won’t be needed
again anytime soon.
However, a fully associative cache is expensive to implement.
— Because there is no index field in the address anymore, the entire
address is used, increasing the total cache size.
— Data could be anywhere in the cache, so we must check the tag of
every cache block.
Associative mapping Cache
(octal digits)
11
Associative mapping advantages & disadvantages
12
Direct Mapping
General case:
2kwords -cache memory
2n words - main memory
The cache tag is 00 but the address tag is 02, which does not
produces a match.
Therefore, the main memory is accessed and the data word
5670 is transferred to the CPU.
The cache word at index address 000 is then replaced with a tag
of 02 and data of 5670.
16
Direct mapping Cache Organization
(block size of 8 words )
Index field is now divided into two parts: BLOCK FIELD & WORD FIELD
64 x 8 = 512
6 Bit 3-bit
Advantage
Simple
Fast
Disadvantage
Its main disadvantage is that the hit ratio may drop if 2 or more words with
same index but different tags are accessed repeatedly (cannot reside in
cache memory at the same time).
18
Problem 1
1. A main memory contains 8 words while the cache has only 4 words. Using
direct address mapping, identify the fields of the main memory address for the
cache mapping.
Solution:
Total memory words = 8 = 23
Require 3 bit for main memory address.
Total cache words = 4 = 22
Require 2 bit for cache address.
19
Thank You