Chapter 4 - Cache Memory
Chapter 4 - Cache Memory
Location
Refers to whether memory is internal and external to the computer
Internal memory is often equated (make equal) with main memory
Processor requires its own local memory, in the form of registers
Cache is another form of internal memory
External memory consists of peripheral storage devices that are
accessible to the processor via I/O controllers
Capacity
Memory is typically expressed in terms of bytes
Unit of transfer
For internal memory the unit of transfer is equal to the number of
electrical lines into and out of the memory module
Method of Accessing Units of Data
Sequential Direct Random
Associative
access access access
Main memory
Capacity and Performance:
What is cache?
Cache and Main Memory
What is a Cache? Memory Management
Unit - MMU
Cache: A small
size, expensive,
memory which
has high-speed
access is located
between CPU
and RAM (large
memory size,
cheaper, and
lower-speed
Memory).
L0: cache in CPU, working
with CPU rate. It is not
usually implemented.
Cache/Main Memory Structure
Main memory is
divided into the
same size blocks.
Some blocks will
be loaded to
cache.
Overview of
cache design
parameters
Main Memory Address Specifications
Opcode Memory Add.
(1) Physical Address
(2) Abtract Address
(3) Virtual Address 3010 3005
App
Physical Addresses
3005
CPU
PC=3010 3000
Mem. Of
Operating
3005 Mem. System
Decoder
Main Memory Address Specifications
Physical Addresses
3005
When the operating system is
upgraded, the OS needs more
Old
memory ( ex: 4000 bytes), old
App.
applications are not compatible.
4000
Address must be specified by an
other way to ensure that old 3005
programs can be run in new OS. Mem. Of
Abstract addresses Operating
System
Main Memory Address Specifications
Abstract Addresses
All addresses in an application will be
specified by compilers using an offset 5
(difference) from the base address 4005
(position at which the app. is loaded) pp.
-A register (base register) must be
added to maintain the base address of 4000
the process
An address is specified by <base,
offset) Mem. Of
Operating
CPU System
Base:4000
Mem.
5
+ Add. bus Decoder
Main Memory Address Specifications
Virtual Addresses: Paging- Segmentation
Contemporary OSs allows many X=10
programs running concurrently 4
although system’s memory is limited. 3
Solution is that the program content
and memory will be divided into
some pages (same-size, ex: 4KB) or
segments (different size). Only 2
-When an instruction/data is
accessed, physical address
must be supplied. A mapping
is needed as a mean for
determining physical
addresses from their virtual
addresses. This mapping is
implemented in OS as a page
table.
- A hardware is needed to
translate virtual address to
physical address MMU –
Memory Management Unit.
Operating Systems - Tannenbaum
Main Memory Address Specifications
Virtual Addresses: Paging- Segmentation
Time-sharing
mechanism
Physical
Caches
Physical cache stores data
using physical addresses
Mapping Function
Because there are fewer cache lines than main memory
blocks, an algorithm is needed for mapping main memory
blocks into cache lines
A block in main
memory can be
load to any line of
the cache
Direct Mapping Cache Organization
READ BY YOURSELF
s: Block index
r: Line index
w: word index
penalty
READ BY YOURSELF
+
Direct
Mapping
Example
READ BY YOURSELF
+
Direct Mapping Summary
Compare
to each
Tag
READ BY YOURSELF
+
Associative
Mapping
Example
READ BY YOURSELF
+
Associative Mapping Summary
Mapping From
Main Memory
to Cache:
k-Way
Set Associative
READ BY YOURSELF
READ BY YOURSELF
k-Way
Set
Associative
Cache
Organization
READ BY YOURSELF
+
Set Associative Mapping Summary
Number of sets = v = 2d
First-in-first-out (FIFO)
Replace that block in the set that has been in the cache longest
Easily implemented as a round-robin or circular buffer technique
If at least one write operation has been A more complex problem occurs when
performed on a word in that line of the multiple processors are attached to
cache then main memory must be the same bus and each processor has
updated by writing the line of cache out its own local cache - if a word is altered
to the block of memory before bringing in one cache it could conceivably
in the new block invalidate a word in other caches
+
Write Through
and Write Back
Write through- Ghi thẳng
Simplest technique
All write operations are made to main memory as well as to the
cache
The main disadvantage of this technique is that it generates substantial
(heavy) memory traffic and may create a bottleneck
The on-chip cache reduces the processor’s external bus activity and
speeds up execution time and increases overall system performance
When the requested instruction or data is found in the on-chip cache, the bus
access is eliminated
On-chip cache accesses will complete appreciably faster than would even
zero-wait state bus cycles
During this period the bus is free to support other transfers
Two-level cache:
Internal cache designated as level 1 (L1)
External cache designated as level 2 (L2)
Potential savings due to the use of an L2 cache depends on the hit rates
in both the L1 and L2 caches
The use of multilevel caches complicates all of the design issues related
to caches, including size, replacement algorithm, and write policy
Hit Ratio (L1 & L2) For 8 Kbyte and 16Kbyte L1
+
Unified Versus Split Caches
Has become common to split cache:
One dedicated to instructions
One dedicated to data
Both exist at the same level, typically as two L1 caches
Characteristics of Memory
Elements of cache design
Systems
Cache addresses
Location
Cache size
Capacity
Mapping function
Unit of transfer
Replacement algorithms
Memory Hierarchy Write policy
How much? Line size
Number of caches
How fast?
How expensive?
Cache memory principles