04 Cache Memory Comparc
04 Cache Memory Comparc
Cache Memory
Cache memory
Cache memory is a small amount of fast memory
Placed between two levels of memory hierarchy
Between processor and main memory (our focus)
Between main memory and disk (disk cache)
Expected to behave like a large amount of fast memory
• Disk cache
• You can also find the cache memory on your hard drive. This is called the “disk
cache”. It is the slowest of all cache levels because the data is loaded from disk to
memory
• Disk
magnetic disk is a circular plate constructed with metal or plastic coated with
magnetic material often both side of disk are used and several disk stacked on one
spindle which Read/write head available on each surface.
• Optical
• The huge commercial success of CD enabled the development of low cost optical
disk storage technology that has revolutionized computer data storage.
• Tape
• A magnetic tape is the strip of plastic coated with a magnetic recording medium.
Data can be recorded and read as a sequence of character through read / write
head.
Cache and Main Memory
The cache is a smaller, faster memory which stores
copies of the data from the most frequently used main
memory locations. Sits between normal main memory
and CPU.
May be located on CPU chip or module.
Cache/Main Memory Structure
Cache operation – overview
• CPU requests contents of memory location
• Check cache for this data
• If present, get from cache (fast)
• If not present, read required block from
main memory to cache
• Then deliver from cache to CPU
• Cache includes tags to identify which
block of main memory is in each cache
slot
Cache Read Operation - Flowchart
Typical Cache Organization
Cont…
• In this organization, the cache connects to
the processor via data, control, and
address lines.
• The data and address lines also attach
to data and address buffers, which attach
to a system bus from which main memory
is reached.
• When a cache hit occurs, the data and
address buffers are disabled and
communication is only between processor
and cache, with no system bus traffic.
• When a cache miss occurs, the desired address is loaded onto
the system bus and the data are returned through the data
buffer to both the cache and the processor.
• In other organizations, the cache is physically interposed
between the processor and the main memory for all data,
address, and control lines.
• In this latter case, for a cache miss, the desired word is first
read into the cache and then transferred from cache to
processor.
How does the CPU cache work?
• The CPU needs to access ultra-fast memory to get the most out
of its performance. The CPU cache works with this memory and
the CPU first looks into the cache memory when it wants to
access data.
• If the data is not there in cache memory, that is called
a miss, and if it is found, it will be called a hit. Then it goes and
searches the main memory
Cache Design
• Addressing
• Size
• Mapping Function
• Replacement Algorithm
• Write Policy
• Block Size
• Number of Caches
Cache Addressing
• Where does cache sit? 2 types:
— Between processor and virtual memory management
unit
— Between MMU and main memory
• Logical cache (virtual cache) stores data using
virtual addresses
— Processor accesses cache directly, not thorough physical
cache
— Cache access faster, before MMU address translation
— Virtual addresses use same address space for different
applications
– Must flush cache on each context switch
• Physical cache stores data using main memory
physical addresses
Comparison of Cache Sizes
Year of
Processor Type L1 cache L2 cache L3 cache
Introduction
IBM 360/85 Mainframe 1968 16 to 32 KB — —
PDP-11/70 Minicomputer 1975 1 KB — —
VAX 11/780 Minicomputer 1978 16 KB — —
IBM 3033 Mainframe 1978 64 KB — —
IBM 3090 Mainframe 1985 128 to 256 KB — —
Intel 80486 PC 1989 8 KB — —
Pentium PC 1993 8 KB/8 KB 256 to 512 KB —
PowerPC 601 PC 1993 32 KB — —
PowerPC 620 PC 1996 32 KB/32 KB — —
PowerPC G4 PC/server 1999 32 KB/32 KB 256 KB to 1 MB 2 MB
IBM S/390 G4 Mainframe 1997 32 KB 256 KB 2 MB
IBM S/390 G6 Mainframe 1999 256 KB 8 MB —
Pentium 4 PC/server 2000 8 KB/8 KB 256 KB —
High-end server/
IBM SP 2000 64 KB/32 KB 8 MB —
supercomputer
CRAY MTAb Supercomputer 2000 8 KB 2 MB —
Itanium PC/server 2001 16 KB/16 KB 96 KB 4 MB
SGI Origin 2001 High-end server 2001 32 KB/32 KB 4 MB —
Itanium 2 PC/server 2002 32 KB 256 KB 6 MB
IBM POWER5 High-end server 2003 64 KB 1.9 MB 36 MB
CRAY XD-1 Supercomputer 2004 64 KB/64 KB 1MB —
Mapping Function
• Determines how memory blocks are mapped to cache lines
• The effectiveness of the cache mechanism is based on a
property of computer programs called locality of reference.
• The process /technique of bringing data of main memory
blocks into the cache block is termed as cache mapping
Three types
• ∗ Direct mapping
• » Specifies a single cache line for each memory block
• ∗ Set-associative mapping
• » Specifies a set of cache lines for each memory block
• ∗ Associative mapping
• » No restrictions
• – Any cache line can be used for any memory block
Direct Mapping
• Each block of main memory maps to only
one cache line
—i.e. if a block is in cache, it must be in one
specific place
• Address is in two parts
• Least Significant w bits identify unique
word
• Most Significant s bits specify one
memory block
• The MSBs are split into a cache line field r
and a tag of s-r (most significant)
Direct Mapping
Address Structure
• 24 bit address
• 2 bit word identifier (4 byte block)
• 22 bit block identifier
— 8 bit tag (=22-14)
— 14 bit slot or line
• No two blocks in the same line have the same Tag field
• Check contents of cache by finding line and checking Tag
Direct Mapping from Cache to Main Memory
Direct Mapping Cache Organization
Direct Mapping Summary
•
Direct Mapping advantage &
disadvantages
advantages
• Simple method
• Inexpensive
disadvantages
• Fixed location for given block
—If a program accesses 2 blocks that map to
the same line repeatedly, cache misses are
very high
Associative Mapping
• A main memory block can load into any line
of cache.
• Memory address is interpreted as tag and
word
• Tag uniquely identifies block of memory.
• Every line’s tag is examined for a match
• Cache searching gets expensive
Associative Mapping from
Cache to Main Memory
Fully Associative Cache Organization
Associative Mapping
Address Structure
Word
Tag 22 bit 2 bit
• 22 bit tag stored with each 32 bit block of data
• Compare tag field with tag entry in cache to
check for hit
• Least significant 2 bits of address identify which
16 bit word is required from 32 bit data block
Associative Mapping Summary
•
Set Associative Mapping
• Cache is divided into a number of sets
• Each set contains a number of lines
• A given block maps to any line in a given
set
—e.g. Block B can be in any line of set i
• e.g. 2 lines per set
—2 way associative mapping
—A given block can be in one of 2 lines in only
one set
Mapping From Main Memory to Cache:
v Associative
K-Way Set Associative Cache
Organization
Set Associative Mapping
Address Structure
Word
Tag 9 bit Set 13 bit 2 bit