Cache Memory: Prepared by - : Manan Mewada (TA, IET)
Cache Memory: Prepared by - : Manan Mewada (TA, IET)
Outline
Introduction
Memory Hierarchy
Need of cache
Cache working
Jobs of cache
Bus structure
Cache mapping
Associative mapping
Direct mapping
Set-associative mapping
Introduction
Memory access time is important to performance!
Users want large memories with fast access times
ideally unlimited fast memory
Tradeoff between size and speed
Larger the size, slower the speed (more access time), vice
versa.
Interface:
1G-32G
Interface:
80G-2T
Cache
Level(s)
Main Memory
EPROM
Magnetic Disc
Need of Cache
In an early 80s CPUs were very slow and main memories are
very small, so memory speed was match up with the
execution speed of CPU.
During the evaluation in technology CPU speed was increased,
but with the increment in size of the memory, the effective
speed of memory was not improved significantly.
To solve out this problem circuit designers introduced a small
and fast temporary memory which is known as cache.
Typical instruction execution time in CPU 1-2ns.
Cache memory access time 1-5ns.
Main memory access time 40-60ns.
Cache Working
CPU
Cache
Cache
controller
Main
Memory
(DRAM)
All the data and instruction need for CPU is stored in main
memory.
Caches are faster than DRAM, so they are used for temporary
data storage.
Hit If the requested data/instruction is in cache, read or
write operation is performed directly using that
data/instruction in cache, without accessing main memory.
Miss If requested data/instruction is not in cache, a block
containing the requested data/instruction is brought to
cache, and then the processor request is completed.
Jobs of Cache
To perform reading ahead tasks.
Hold on the commonly used instructions or commonly
used calculations for CPU
Bus Structure
CPU chip
register file
L1
cache
cache bus
L2 cache
ALU
system bus
bus interface
I/O
bridge
memory bus
main
memory
Cache Mapping
Commonly used methods:
Associative Mapped Cache
Direct-Mapped Cache
Set-Associative Mapped Cache
Offset
4
1
Valid
12
Dirty
Tag
12
CB 0
MB 0
CB 1
MB 1
CB 15
MB 4095
12
Disadvantages
Considerable hardware overhead needed for cache
bookkeeping.
There must be a mechanism for searching the tag
memory in parallel.
Direct-Mapped Cache
Each CB corresponds to an explicit set of MBs.
In our example we have 212 MBs and 24 CBs.
A total of 212 / 24 = 28 MBs can be mapped onto each CB.
Dirty
Tag
MB 0
MB 1
4
1
CB 0
MB 16
CB 1
MB 17
CB 15
MB 4095
Direct-Mapped Cache
The 16-bit main memory address is partitioned into a 8bit tag field, followed by a 4-bit CB field, followed by a 4bit offset field.
Tag (8)
CB field (4)
Offset (4)
Direct-Mapped Cache
Advantages
The tag memory is much smaller than in associative
mapped cache.
No need for an associative search, since the CB field is
used to direct the comparison to a single field.
Disadvantages
Higher miss rate.
Offset
MB 0
4
1
Valid
Dirty
Tag
MB 1
CB 0
set
0
CB 1
9
CB 15
MB 16
MB 17
set
7
MB 4095
Advantages
In our example the tag memory increases only slightly from the
direct mapping and only two tags need to be searched for each
memory reference.
The set-associative cache is widely used in todays microprocessors.
Thank You
Cache Write
Data is in the
cache
Data is not in
the cache
Data is in the
cache
Data is not in
the cache
Forward to
CPU
Load through:
Forward the
data/byte as
cache line is
filled
Or
Fill cache line
and than
forward
Write through:
Write data to
both cache and
main memory
Or
Write Back:
Write data to
cache only.
Differ main
memory write
until cache
block is flush
Write allocate:
Bring line into
the cache, then
update it
Or
Write no
allocate:
Update main
memory only