Professional Documents
Culture Documents
MEMORY MANAGEMENT
PHYSICAL TYPES
Semiconductor
RAM
Magnetic
Optical
CD & DVD
Others
Bubble
Hologram Pritee
Parwek
MEMORY HIERARCHY
Registers
In CPU
“RAM”
External memory
Backing store
Pritee
Parwek
THE BOTTOM LINE
How much?
Capacity
How fast?
Time is money
How expensive?
Pritee
Parwek
HIERARCHY LIST
Registers
L1 Cache
L2 Cache
Main memory
Disk cache
Disk
Optical
Tape
Pritee
Parwek
MEMORY HIERARCHY
Main Memory
RAM
Pritee
Parwek
MEMORY HIERARCHY
Auxiliary Memory
Non volatile
Pritee
Parwek
MEMORY HIERARCHY
Main Memory I/O Processor
CPU
Cache
Magnetic
Disks Magnetic Tapes
Pritee
Parwek
CPU
Increasing distance
Level 1
from the CPU in
access time
Level n
Processor
Control Tertiary
Secondary Storage
Storage (Tape)
Second Main
(Disk)
On-Chip
Registers
Level Memory
Cache
Pritee
Parwek
Pritee Parwekar
TABLE OF TECH AND ACCESS TIME
Memory technology Typical access time
SRAM 0.5–5 ns
DRAM 50–70 ns
DRAM:
Value is stored as a charge on capacitor
(must be refreshed)
Very small but slower than SRAM (factor of 5
to 10)
Pritee
Parwek
MEMORY CELL OPERATION
Pritee
Parwek
Hit: data appears in some block in the upper level (example:
Block X)
Hit Rate: the fraction of memory access found in the upper
level
Lower Level
To Processor Upper Level Memory
Memory
Blk X
From Processor Blk Y
Pritee
Parwek
MEMORY HIERARCHY: HOW DOES IT WORK?
Pritee
Parwek
PROBLEM 1
Consider two-level memory hierarchy (M1,M2)
t1,t2 are access time of M1 and M2 ,h1 is hit ratio of
M1.Calculate effective access time
EAT=h1*t1+(1-h1)(1+t2)
If cost per unit f M1 is C1 and the cost per unit of M2
is C2 then the average cost of memory =
C1*M1 + C2*M2 / (M1+M2)
Pritee
Parwek
PROBLEM 2
Suppose the access time of cache memory is 80ns
and that of main memory is 800ns.It is estimated
that the memory requests are for read. The hit ratio
for read access is 0.8.
Determine the average access time of the system
only memory read cycle
Pritee
Parwek
CACHE MEMORY
Pritee
Parwek
WHY IS CACHE MEMORY NEEDED?
Pritee
Parwek
WHY IS CACHE MEMORY NEEDED ?
Pritee
Parwek
CACHE MEMORY
Pritee
Parwek
WHY IS CACHE MEMORY FAST?
Pritee
Parwek
WHY IS CACHE MEMORY FAST
Pritee
Parwek
CACHE MEMORY
High speed (towards CPU speed)
Small size (power & cost)
Miss
Main
CPU Memory
Cache (Slow)
(Fast) Mem
Hit Cache
Pritee
Parwek
CACHE MEMORY
00000000 Main
00000001 Memory
00000 Cache •
00001 •
• •
• •
• •
• •
FFFFF •
•
•
Pritee
Parwek
CACHE AND MAIN MEMORY
Pritee
Parwek
CACHE DESIGN
Size
Mapping Function
Replacement Algorithm
Write Policy
Block Size
Number of Caches
Pritee
Parwek
CACHE
Pritee
Parwek
CACHE DESIGN
Size
Mapping Function
Replacement Algorithm
Write Policy
Block Size
Number of Caches
Pritee
Parwek
CACHE-MAPPING FUNCTIONS
DIRECT MAPPING
ASSOCIATIVE MAPPING
Pritee
Parwek
CACHE MEMORY
00000000 Main
00000001 Memory
00000 Cache •
00001 •
• •
• •
• •
• •
FFFFF •
•
•
Cache
000
001
010
011
111
100
101
110
Memory Pritee
Parwek
DIRECT MAPPING Pritee Parwekar
0 0, m, 2m, 3m…2s-m
1 1,m+1, 2m+1…2s-m+1
Pritee
Parwek
DIRECT MAPPING FROM CACHE TO MAIN
MEMORY
Pritee
Parwek
DIRECT MAPPING CACHE ORGANIZATION
Pritee
Parwek
DIRECT MAPPING EXAMPLE
Pritee
Parwek
ANSWER
word id (2 bits)
Pritee
Parwek
PROBLEM
Pritee
Parwek
Pritee Parwekar
DIRECT MAPPING
ADDRESS STRUCTURE
Tag s-r Line or Slot r Word w
7 14 2
23 bit address
2 bit word identifier (4 byte block)
21 bit block identifier
7 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
PROBLEM
Pritee
Parwek
ASSOCIATIVE MAPPING
Pritee
Parwek
ASSOCIATIVE MAPPING FROM
CACHE TO MAIN MEMORY
Pritee
Parwek
FULLY ASSOCIATIVE CACHE
ORGANIZATION
Pritee
Parwek
ASSOCIATIVE MAPPING
ADDRESS STRUCTURE
Word
Tag 22 bit 2 bit
22 bit tag
Compare tag field with tag entry in cache to
check for hit
Least significant 2 bits of address identify
which word is required from data block
Pritee
Parwek
SET ASSOCIATIVE MAPPING
Pritee
Parwek
SET ASSOCIATIVE MAPPING
Pritee
Parwek
SET ASSOCIATIVE MAPPING
Pritee
Parwek
SET ASSOCIATIVE MAPPING
Pritee
Parwek
SET ASSOCIATIVE MAPPING
Pritee
Parwek
PROBLEM
Pritee
Parwek
SOLUTION
Let us assume we have a Main Memory of size
4GB (232), with each byte directly addressable by a
32-bit address. We will divide Main memory into
blocks of each 32 bytes (25). Thus there are 128M
(i.e. 232/25 = 227) blocks in Main memory.
Pritee
Parwek
PROBLEM
Pritee
Parwek
PROBLEM
Pritee
Parwek
PROBLEM
Pritee
Parwek
PROBLEM
Pritee
Parwek
SET ASSOCIATIVE MAPPING
EXAMPLE
In the below example we have
chosen the block 14 from Main
memory and compared it with the
different block replacement
algorithms. In Direct Mapped cache
it can be placed in Frame 6 since 14
mod 8 = 6. In Set associative cache
it can be placed in set 2.
Pritee
Parwek
MAPPING FROM MAIN MEMORY TO
CACHE:
V ASSOCIATIVE
Pritee
Parwek
MAPPING FROM MAIN MEMORY TO
CACHE:
K-WAY ASSOCIATIVE
Pritee
Parwek
K-WAY SET ASSOCIATIVE CACHE
ORGANIZATION
Pritee
Parwek
SET ASSOCIATIVE MAPPING
ADDRESS STRUCTURE
Word
Tag 9 bit Set 13 bit 2 bit
Pritee
Parwek
TWO WAY SET ASSOCIATIVE MAPPING
EXAMPLE
Pritee
Parwek
SET ASSOCIATIVE MAPPING
SUMMARY
Address length = (s + w) bits
Number of addressable units = 2s+w words or
bytes
Block size = line size = 2w words or bytes
Number of blocks in main memory = 2d
Number of lines in set = k
Number of sets = v = 2d
Number of lines in cache = kv = k * 2d
Size of tag = (s – d) bits
Pritee
Parwek
Therefore, cache line's tag size depends on 3
factors:
Size of cache memory;
Here,
Stag — size of cache tag, in bits;
Smemory — cacheable range of operating memory, in bytes;
Scache — size of cache memory, in bytes;
A — associativity of cache memory, in ways.
Pritee
Parwek
EXAMPLE
Pritee
Parwek
VALID BIT / DIRTY BIT
Pritee
Parwek
VALID BIT / DIRTY BIT
Dirty bit :- keeps track of whether or not
a line has been modified while it is in the
cache. A slot that is modified must be
written back to the main memory before the
slot is reused for another line.
Pritee
Parwek
REPLACEMENT
ALGORITHM
Optimal Replacement: replace the block
which is no longer needed in the future. If
all blocks currently in Cache Memory will
be used again, replace the one which will
not be used in the future for the longest
time.
Pritee
Parwek
REPLACEMENT ALGORITHMS
For Associative & Set-Associative Cache
Which location should be emptied when
the cache is full and a miss occurs?
First In First Out (FIFO)
Pritee
Parwek
REPLACEMENT ALGORITHMS
CPU A B C A D E A D C F
Reference
Miss Miss Miss Hit Miss Miss Miss Hit Hit Miss
Cache A A A A A E E E E E
B B B B B A A A A
FIFO C C C C C C C F
D D D D D D
Pritee
Parwek
REPLACEMENT ALGORITHMS
CPU A B C A D E A D C F
Reference
Miss Miss Miss Hit Miss Miss Hit Hit Hit Miss
Cache A B C A D E A D C F
A B C A D E A D C
LRU A B C A D E A D
B C C C E A
Pritee
Parwek
LOAD-THROUGH
STORE-THROUGH
Pritee
Parwek
When the cache is missed :
Pritee
Parwek
Pritee
Parwek
CACHE CONFLICT
Pritee
Parwek
PROBLEM
Pritee
Parwek
PROBLEM
Pritee
Parwek
PROBLEM
Pritee
Parwek
Pritee
Parwek