Mapping Cache
Mapping Cache
Nhemoy
A "Mapping
Usually, the cache hemory can store Areasonable number of memory blocks at any given time, but this
number is small compared Lto the total number of blocks in the main memory. The correspondene between the
mapping function.
main memory, blocks and those in the cache is specified by a
"The mapping techniques are classified as
1. Direct-mapping technique
2 Associative-mapping technique
.Fully-a8s0ciative
Set-associative techniques
" To discuss these techniques of cache mapping we consider a cache consists of 128 blocks of 16 worde each,
atotal of 2048 (2 K) main memory has 64 K words. This
64 K for
words and assume that the words of main
memory is addressable by a16-bit address and it can be viewed as 4 K blocks of 16 words each. The
T28 blocks of 16 words each in main [Link]
memory form a page
Z6.1 Direct-Mapping
It is the simplest
mapping technique.
In this technique, each block from the main memory has only one
In this example, the block i of
possible location in the cache organization
the main memory maps onto block j(i = i modulo 128) of the cache, as
Fig- 4.10.6. Therefore, whenever one of the main memory blocks 0, 128, shown in
256, ... is loaded in the cache, it is
Stored in cache block 0. Blocks 1, 129, 257...are stored in cache
block 1 and so on.
In general the mapping
expression is
j =imodulo m
where
i = Main memory block number
j= Cache block (ine) number
m = Number of
blocks (lines) in the cache Main memory
" To implement such cache system, the Block 0
divided into three fields, as shown in [Link]
is Block 1
4.7.6. Page 0
" The lOwer order 4-bits select one of the 16
words Cache Tag 0
in a block. This field is known as 5bits
word field. j=0 Tag
memory
" The Block o Biock 127
second field known as block field is used to j1 ag Block 128
distinguish a block from other blocks. Its length is Block Block 129
7-bits since 2 = 128. Page 1
Tag 1
" When anew block enters the j= 127 Tag
cache, the 7-bit cache Block 127
block ield determines the cache position in which Biock 2K5
means
that to determine whether requested word is in the cache, only tag field is necessary to be
This
, compared. This needs only one comparison.
from
maindrawback of direct mapped cache is that if processor needs to access sarne mernory locations Since
different pages of the main memory frequently, the controller has to access main mernory frequentiy
" The
two access nemory
of these locations can be in the cache at a time. For example, if processor want to
only one 2 of the main
location 100 Hfrom page 0 and then from page 2, the cache controller has to access page
memory. Therefore, we can say that direct-mapped cache
is easy to inplernent, however, it is not very flexible
Tag Biock O
cache,
Biock
block Tag
. The 12-tag bits are required to identify a memory
Biock 1
12bits
when it is resident in the cache. The high-Order
CPU are compared to
of an address received from the Tag Biock 127
see if the
the tag bits of each block of the cache to
Biock i
Set-Associative Mapping
he set-associative mapping is a combination of both direct and associative mapping.
parallel.
contains several groups of direct-mapped blocks that operate as several direct-mapped caches in
*A Hock of data from any page in the main memory can go into a particular block location a any
cache. Hence the contention problenm of the direct-mapped technique is eased by hayihg a few
dírect-mapped
Choices for block placement.
TECHNICAL PUBLICATIONS - An up thust for knowiedoe
Comt(vpant atik ad
Ahiechue
required Addrese Main emory
narisns dewend on the
number
lock 0
toc
Caches in the diret mayet
Cahe system et
blockplacement
(" In this
Block 4095
Whe
Memory
required address Main nemory
comparisons depend on the Block O
number Block
caches in the
direct-mapped Rlock belongs
cache system. to set 0
Page 0
These oomparisOns are always Tag 0
less than the Omparisons Block 63
requied in the Block 64
futv-associatire
Fig 4.7.8
mapping Set 0 Tag
Cache memory
Tag
Cache mernory
Biock 65
of the main
iAlhe remaining 4 (16- 4 - 8) address bits are tag bits which stores the higher address
TAgbitg
memory.
there are 12
address each block in the main memory (212= 4096) 12 bits are required and therefore,
Tag bits: To
tag bits.
technique is divided as shoWn below:
The main memory address for direct mapping
TAG WORD
Fig. 4.7.10
i) Associative mapping
TAG
WORD
Main memory address = 11 4
Ahlock
set-assoCiatre cache consists of 64 Memory
blocks divided into 4 block sets. The main
of 128 words of 16 bits length : memory contains 4096 blocks,
mamybits are
there in main
How
memory
?
J in each of the TAG, SET
bits are there and WORD fields ?
solution: i) Number of bits in main memory :
= Number of blocks x Number of words per block x Number of bits per word
= 4096 x 128 x 16
= 8388608 bits
To address these words we require (2 = 524288) 19 address lines. Therefore, tag bits are eight (19 -7-4).
memory of 1 K words. The cache uses direct
omote 5 A digital computer has a memory unit of 64 K x 16 and a cache
block and word field of the address format ?
ming with a block size of four words. How many bits there in the tag indes,
Solution : Word bits : Number of word bits = log, 4 = log, 2 = 2-bits
2° = 8 bits
.:. Number of block bits = log, 256 = log,
main memory
Tag bits : Number of bits to address
Block Word
Tag
2
Main memory address =
log, 2° = 16 bits
= log, 64 K =
= 16 - 8 2 =6 bits a total of 20.48
.i. Number of Tag bits block of four words. The cache can accommodate
memory uses
set associative cache
mple 4.16 A two wav
main memory size 1s
wUras from main nemory. The
?
128 Kx 32. of address format
index, block and word field AKTU 20121, Marks 5
i) How bits are there in the tag
îny log 2 = 17 bits
) What is size of cache memory = log, 128 K =
memory address 2048
Solution :Number of bits in main 512 Blocks
cache memory= 4
Number of blocks in the 5i2 = 256 sets
the cache memory =
Number of sets in = 8 bits
set field= log, 256 = log, 2"
Number of bitsin 2 bits
word field = log, 4 = log, 2* =
Number of bits in -8- 2 =7 bits
tag field = 17
Number of bits in
knowiedge
- An up thrust for
TECHNCAL PUBLICATIONS
Computer Organization and Architecture 4-32
Tag
Set Word Mernoy
2
Main memory address
17bits
16 - bits
128 K
Tag length = 32 - 10 - 4 = 18
S.
No.
Direct-mapping Associative-mapping Vsetassociative-mapping
main main tnemory can
Each block from the possible
A block of data from main memory A block of data from location of
1
memory has only one can be placed into any cache block go into a particular block
cache. any direct-mapped cache.
location in the position.
equal to
comparison. Needs comparison with all tag bits. Needs number of comparisons
Needs only one number of blocks per set.
2
in cache hit ratio
decreases if Cache hit ratio has no effect if The effect of reduction
access to the two
Cache hit ratio same processor needs to access same in case of frequent memory is
3
Drocessor needs to access
two location from two different differernt pages of the main
from memory
memory location pages of the main memory reduced.
different pages of the main
memory frequently. frequently.
address is divided into
address is divided into Main memory SET and WORD.
address is Main nemory three fields : TAG,
Main memory two fieids : TAG and WORD.
divided into three fields:TAG,
BLOCK and WORD. with number
Searching time increases
less. Searching time is more. of blocks per set.
5 Searching time is
between mapping techniques
Table 4.7.1 Comparison
memory may
477 Cache Coherency cache memory and another in main
same data, one in
CPU systemn, two copies of coherence problem.
"Ina single inconsistency is called as cache operations.
data
become different. This main memory caused by cache write
in the
updating systems eliminates data inconsistency system bus. This bus
master could
"Cache control of the
another bus master can take over another processor. When this
multiprocessor systems, held in the cache of
"In
main memory blocks which are already memory creating
inconsistency.
data into a held in main
write
cache no longer match those cache coherency :
happens, the datain the data inconsistency, that is to protect
approaches to prevent
four different
"The 80386 supports 2. Hardware trarnsparency
1. Bus watching (snooping) 4. Cache flushing. master writes to a
3. Non-cacheable memory invalidates the cache entry, if another
cache controller shows bus watching.
"Bus watching : In bus
watching,
resides in the cache memory. Fig. 4.7.11
which also main memory are routed
location in shared memory accesses of all devices to the that
hardware
transparency,
the main memory and to all other caches
" Hardware transparency : In all cache writes both
to
by copying system.
through the same cache or 4.7.12 shows hardware transparent
share the samememory. Fig.
knowledge
- An up thrust for
TECHNICAL PUBLICATIONS
4-34
Duter Oryenization and Architecture Col
80306 Cache
Shared
80386 82385
memory
transparoncy
Flg. 4.7.12 Hardwaro
Flg. 4.7.11 Bus watching
" Non-cacheable memory : The 80386DX can partition its main memory into a cacheable and non-cacheab,
coherency can be
as non-cacheable memory cache maintained, sine
memory. By designing shared memory
shared memory is never copied into cache.
Other bus
master
Non-cacheable
80386 Decode
Main
memory Cacheable
Decode
"Cache ffushing : To avoid data inconsistency, a cache flush writes any altered data to the main memory and
caches in the system are flushed before a device writes to shared memory.