Ch04 The Memory System
Ch04 The Memory System
Ch04 The Memory System
• Memory Hierarchy
• Main Memory
• Associative Memory
• Cache Memory
• Virtual Memory
MEMORY HIERARCHY
Memory Hierarchy is to obtain the highest possible
access speed while minimizing the total cost of the memory system
Auxiliary memory
Magnetic
tapes I/O Main
processor memory
Magnetic
disks
CPU Cache
memory
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Increasing size
Basic Concepts of Memory
k
n-bit data bus Up to 2 addressable
MDR locations
Cache L1
SRAM
Cache L2
Main
ADRAM
memory
secondary
storage
memory
Basic Concepts of Memory
• Random Access Memory à any location can be accessed for read / write operation
in fixed amount of time .
• Types of RAM :à à
1. Static memory / SRAM : Capable of retain states as long as power is
applied, volatile in nature.[High cost & speed]
2. Asynchronous DRAM : Dynamic RAM are less expensive but they do not
retain their state indefinitely. Widely used in computers.
3. Synchronous DRAM : Whose operation is directly Synchronized with a clock
signal.
4. Performance Parameter :- Bandwidth & Latency.
5. Bandwidth :-Number of bytes transfer in 1 unit of time.
6. Latency:- Amount of time takes to transferred a word of data to & from
memory.
• Read Only Memory / ROM :à à location can be accessed for read operation only in
fixed amount of time . Capable of retain states called as, non-volatile in nature.
• Programmable ROM : Allows data to be loaded by user.
• Erasable PROM : Erased [ by UV ray ]Stored data to load new data.
• Electrically EPROM : Erased by different voltages.
• Memory uses semiconductor integrated circuit to increase performance.
• To reduce memory cycle time à Use Cache memory àA small SRAM physically very
closed to processor which works on locality of reference.
• Virtual memory is used to increase the size of the physical memory.
Internal Organization of Memory Chips
2 4
32 - to -1
O/P MUX
&
I/P DMUX
An Example of DRAM
• DRAM cell consist of a capacitor,
C , & a transistor, T .
• To store information in cell,
transistor T is turn on, & provide
correct amount of voltage to bit
line.
• After transistor turn off capacitor
begins to discharge.
• So, Read operation must be
completed before capacitor
drops voltage below some
threshold value [ by sense
amplifier connected to bit line].
Single Transistor Dynamic memory Cell
Design 16MB DRAM Chip
• 2 M x 8 memory chip .
• Cells are organized in the form of 4K x 4K .
• 4096 cells in each row divided into 512 group of 8. Hence 512 byte data can be stored in each row.
• 12 [ 512 x 8 = 212 ] bit address to select row & 9 [ 512 = 212 ] bits to specify a group of 8 bits in the
selected row.
• RSA [Row address strobe] & CSA [Column address strobe] will be crossed to find the proper bit
to read or write.
• The information on D7-0 lines is transferred to the selected circuit for write operation.
Synchronous DRAM
• Directly synchronize with a clock signal = SDRAM
• The address & data connections are buffered by means register.
• During read operation all cells in selected row loaded into latch & then to O/P register.
• Refresh counter refresh contain of the cells only.
• SDRAM can work on different modes by mode register like burst & self CSA activation
..
Memory Controller
• Memory address are divided into 2 parts.
• High order address bit which select row in the cell array, are provided first & latched into memory
chip under control of RSA signal.
• Low order address bit , which selects a column are provided on the same address & latched
through CSA signal.
• Controller accepts a complete address & R/W signal from processor under control of REQUEST
signal, which indicates memory access operation is needed.
• Controller forwards row & column address timing to have address multiplexing function.
• Then R/W & CS are send to memory.
• Data lines are directly connected between processor & memory.
Row/Column
Address address
RAS
R/W
CAS
Memory
Request Controller R/W
Processor Clock
CS Memory
Clock
data
Associative Memory
• Reduces the search time
efficiently
• Address is replaced by
content of data called as
Content Addressable Memory
(CAM)
• Called as Content based data.
• Hardwired Requirement :àà
– It contains memory array &
logic for m words with n bits
per each word.
– Argument register (A) & Key
register (k) each have n bits.
– Match register (M) has m bits,
one for each word in memory.
– Each word in memory is
compared in parallel with the
content of argument register
and key register.
– If a match found for a word
which matches with the bits
of argument register & its
corresponding bits in the
match register then a search
for a data word is over.
Cache Memory
• Relatively small SRAM [ Having low access time ]memory located
physically closer to processor.
• Locality of Reference
• The references to memory at any given time interval tend to be confined
within a localized areas
• This area contains a set of information and the membership changes
gradually as time goes by
• Temporal Locality à The information which will be used in near future is
likely to be in use already( e.g. Reuse of information in loops)
• Spatial Locality à If a word is accessed, adjacent(near) words are likely
accessed soon (e.g. Related data items (arrays) are usually stored
together; instructions are executed sequentially)
• Cache is a fast small capacity memory that should hold those information
which are most likely to be accessed
Main memory
CPU
Cache memory
Performance Of Cache Cache Write
Memory • Write Through
• All the memory accesses are directed – If Hit, both Cache and memory is
first to Cache written in parallel
• If the word is in Cache; Access cache – If Miss, Memory is written
to provide it to CPU à CACHE HIT – For a read miss, missing block may
• If the word is not in Cache; Bring a be overloaded onto a cache block
block (or a line) including that word to
replace a block now in Cache à • Write-Back (Copy-Back)
CACHE MISS – If Hit, only Cache is written
• Hit Ratio - % of memory accesses – If Miss, missing block is brought to
satisfied by Cache memory system Cache and write into Cache
• Te: Effective memory access time – Update only the cache location &
in Cache memory system mark it as updated with an
• Tc: Cache access time associated flag bit called as dirty /
• Tm: Main memory access time modified bit.
• Te = h*Tc + (1 - h) [Tc+Tm] – For a read miss, candidate block
• Example: must be written back to the memory
Tc = 0.4 µs, Tm = 1.2µ µs, h = 85% • Memory is not up-to-date, i.e., the same
item in Cache and memory may have
• Te = 0.85*0.4 + (1 - 0.85) * 1.6 = 0.58µ
µs different value called as cache coherence
problem.
Cache Memory
MEMORY AND CACHE MAPPING - ASSOCIATIVE MAPPLING -
Mapping Function à Specification of correspondence between main memory
blocks and cache blocks
Associative mapping
Direct mapping
Set-associative mapping
Associative Mapping
- Any block location in Cache can store any block in memory
à Most flexible
- Mapping Table is implemented in an associative memory
à Fast, very Expensive
- Mapping Table Stores both address and the content of the memory word
Argument register
Address Data
01000 3450
CAM 02777 6710
22235 1234
Cache Memory
- DIRECT MAPPING -
- Each memory block has only one place to load in Cache
- Mapping Table is made of RAM instead of CAM
- n-bit memory address consists of 2 parts; k bits of Index field and n-k bits of
Tag field
- n-bit addresses are used to access main memory and k-bit Index is used to
access the Cache
Addressing Relationships Tag(6) Index(9)
00 000 32K x 12
000
512 x 12
Main memory Cache memory
Address = 15 bits Address = 9 bits
Data = 12 bits Data = 12 bits
77 777 777
01777 4560
02000 5670
777 02 6710
02777 6710
Cache Memory
DIRECT MAPPING
Operation
1. CPU generates a memory request with memory address (TAG;INDEX)
2. Access Cache using INDEX ; (tag; data)
Compare TAG on memory address and tag on cache memory
3. If two tags matches à then it is cache Hit
4. Provide corresponding Cache [INDEX] to find (data) & then send it to CPU
5. If not match à then a cache Miss & read required data from main memory.
6. Stores new data from Memory [tag : INDEX] à on Cache together with tag
& data [INDEX] (data)
7. Cache [INDEX] ß (TAG ; M [ TAG ; INDEX ])
8. CPU ß Cache [INDEX] (data)
Block 63 770 02
777 02 6710
Cache Memory
- SET ASSOCIATIVE MAPPING
Each memory block has a set of locations in the Cache to load
Set Associative Mapping Cache with set size of two or more words of memory
under same index address
Index Tag Data Tag Data
000 01 3450 02 5670
Base
Address
Page
Of each
Number
Page in
As
Physical
index
Memory
Paging Hardware
Base address
+ page offset=
Physical address
Base
Address
Page 1 Page
Of each
Number
Page in
As
Page 2 Physical
index
Memory
Page 3
As Associative register
Virtual memory
• Virtual memory – separation of user logical memory
from physical memory.
–Only part of the program needs to be in
memory for execution
–Logical address space can therefore be
much larger than physical address space
–Allows address spaces to be shared by
several processes
–Allows for more efficient process creation
⇒
Page Replacement
Page Replacement Algorithms
• Want lowest page-fault rate
H TWOHIT
TWOHIT
I S
S
T
15 PAGE FAULTS
Problem with FIFO Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• 3 frames (3 pages can be in memory at a time per process)
1 1 4 5 9 page faults
2 2 1 3
3 3 2 4
• 4 frames UNEXPECTED
1 1 5 4
Page fault
increases
2 2 1 5
3 3 2
4 4 3 10 page faults
• Belady’s Anomaly:à
à more frames ⇒ more page faults
Optimal Algorithm
H
H
IT
I
T TWOHIT THREE TWOHIT
TWOHIT
S HITS S
S
09 PAGE FAULTS
Difficulty with Optimal Algorithm
• Replace page that will not be used for longest period of
time
• 4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 4
6 page faults
3
4 5
H H TWOHIT
H H
IT IT TWOHIT S
IT IT
S
12 PAGE FAULTS
Least Recently Used (LRU) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 1 1 1 5
2 2 2 2 2
3 5 5 4 4
4 4 3 3 3
• Counter implementation
– Every page entry has a counter; every time page is
referenced through this entry, copy the clock into the
counter
– When a page needs to be changed, look at the
counters to determine which are to change