Unit 5 (Memory)
Unit 5 (Memory)
Control lines
( R / W, MFC, etc.)
Memory Basic Concepts(Contd.,)
Measures for the speed of a memory:
Memory access time.
Memory cycle time.
An important design issue is to provide a computer
system with as large and fast a memory as possible,
within a given cost target.
Several techniques to increase the effective size and
speed of the memory:
Cache memory (to increase the effective speed).
Virtual memory (to increase the effective size).
The Memory System
•
•
•
FF FF
A0 W1
•
•
•
A1
Address Memory
• • • • • • cells
decoder • • • • • •
A2
• • • • • •
A3
W15
•
•
•
b b
T 1
X Y T 2
Word line
Bit lines
Asynchronous DRAMs
• Static RAMs (SRAMs):
– Consist of circuits that are capable of retaining their state as long as the
power is applied.
– Volatile memories, because their contents are lost when power is
interrupted.
– Access times of static RAMs are in the range of few nanoseconds.
– However, the cost is usually high.
C AS D7 D0
Fast Page Mode
Suppose if we want to access the consecutive bytes in the
selected row.
This can be done without having to reselect the row.
Add a latch at the output of the sense circuits in each row.
All the latches are loaded when the row is selected.
Different column addresses can be applied to select and place different bytes on the
data lines.
Consecutive sequence of column addresses can be applied
under the control signal CAS, without reselecting the row.
Allows a block of data to be transferred at a much faster rate than random accesses.
A small collection/group of bytes is usually referred to as a block.
This transfer capability is referred to as the
fast page mode feature.
Synchronous DRAMs
•Operation is directly synchronized
Refresh
counter with processor clock signal.
•The outputs of the sense circuits are
connected to a latch.
Row •During a Read operation, the
Ro w
address decoder Cell array contents of the cells in a row are
latch
Row/Column loaded onto the latches.
address •During a refresh operation, the
Column Co lumn Read/Write contents of the cells are refreshed
address
counter decoder circuits & latches without changing the contents of
the latches.
•Data held in the latches correspond
Clock to the selected columns are transferred
RAS to the output.
Mode register
CA S and Data input Data output •For a burst mode of operation,
register register
R/W timing control successive columns are selected using
CS column address counter and clock.
CAS signal need not be generated
externally. A new data is placed during
Data
raising edge of the clock
Latency, Bandwidth, and
DDRSDRAMs
• Memory latency is the time it takes to
transfer a word of data to or from
memory
• Memory bandwidth is the number of
bits or bytes that can be transferred in
one second.
• DDRSDRAMs-Double-Data-Rate-SDRAM
– Cell array is organized in two banks
Static Memories
21-bit
addresses 19-bit internal chip address Implement a memory unit of 2M
A0
A1
words of 32 bits each.
Use 512x8 static memory chips.
A 19
A 20 Each column consists of 4 chips.
Each chip implements one byte
position.
A chip is selected by setting its
chip select control line to 1.
2-bit Selected chip places its data on the
decoder
data output line, outputs of other
chips are in high impedance state.
21 bits to address a 32-bit word.
512K 8
High order 2 bits are needed to
memory chip
D 31-24 D 23-16 D 15-8 D 7-0 select the row, by activating the
512K 8 memory chip
four Chip Select signals.
19 bits are used to access specific
19-bit 8-bit data
byte locations inside the selected
address input/output chip.
Chip select
Dynamic Memories
Large dynamic memory systems can be implemented using DRAM
chips in a similar way to static memory systems.
Placing large memory systems directly on the motherboard will
occupy a large amount of space.
Packaging considerations have led to the development of larger
memory units known as SIMMs (Single In-line Memory Modules)
and DIMMs (Dual In-line Memory Modules).
Memory modules are an assembly of memory chips on a small
board that plugs vertically onto a single socket on the
motherboard.
Memory Controller
Recall that in a dynamic memory chip, to reduce the
number of pins, multiplexed addresses are used.
Address is divided into two parts:
High-order address bits select a row in the array.
They are provided first, and latched using RAS signal.
Low-order address bits select a column in the row.
They are provided later, and latched using CAS signal.
However, a processor issues all address bits at the same
time.
In order to achieve the multiplexing, memory
controller circuit is inserted between the processor
and memory.
Memory Controller (contd..)
Row/Column
Address address
RAS
R/ W
CAS
Memory
Request controller R/ W
Processor Memory
CS
Clock
Clock
Data
19
The Memory System
Read-Only Memory:
Data are written into a ROM when it is manufactured.
Programmable Read-Only Memory (PROM):
Allow the data to be loaded by a user.
Process of inserting the data is irreversible.
Storing information specific to a user in a ROM is expensive.
Providing programming capability to a user may be better.
Erasable Programmable Read-Only Memory (EPROM):
Stored data to be erased and new data to be loaded.
Flexibility, useful during the development phase of digital systems.
Erasable, reprogrammable ROM.
Erasure requires exposing the ROM to UV light.
Read-Only Memories (Contd.,)
Flash memory:
Has similar approach to EEPROM.
Read the contents of a single cell, but write the contents
of an entire block of cells.
Speed, Size, and Cost
A big challenge in the design of a computer system is to provide a sufficiently large
memory, with a reasonable speed at an affordable cost.
Static RAM:
Very fast, but expensive, because a basic SRAM cell has a complex circuit making it
impossible to pack a large number of cells onto a single chip.
Dynamic RAM:
Simpler basic cell circuit, hence are much less expensive, but significantly slower than
SRAMs.
Magnetic disks:
Storage provided by DRAMs is higher than SRAMs, but is still less than what is necessary.
Secondary storage such as magnetic disks provide a large amount
of storage, but is much slower than DRAMs.
Memory Hierarchy
Pr ocessor •Fastest access is to the data held in
processor registers. Registers are at
Registers the top of the memory hierarchy.
Increasing Increasing Increasing •Relatively small amount of memory that
size speed cost per bit can be implemented on the processor
Primary L1
cache chip. This is processor cache.
•Two levels of cache. Level 1 (L1) cache
is on the processor chip. Level 2 (L2)
Secondary L2 cache is in between main memory and
cache processor.
•Next level is main memory, implemented
as SIMMs. Much larger, but much slower
Main than cache memory.
memory
•Next level is magnetic disks. Huge amount
of inexpensive storage.
•Speed of memory access is critical, the
Magnetic disk idea is to bring instructions and data
secondary that will be used in the near future as
memory
close to the processor as possible.
The Memory System
Cache Memories
Cache Memory
Processor is much faster than the main
memory.
Speed of the main memory cannot be
increased beyond a certain point.
Cache memory is an architectural
arrangement which makes the main
memory appear faster to the processor
than it really is.
Cache memory is based on the property
of computer programs known as “locality
of reference”.
Locality of Reference
Main
Processor Cache memory
• Write hit:
Cache has a replica of the contents of the main memory.
Contents of the cache and the main memory may be updated
simultaneously. This is the write-through protocol.
Update the contents of the cache, and mark it as updated by setting
a bit known as the dirty bit or modified bit. The contents of the main
memory are updated when this block is replaced. This is write-back
or copy-back protocol.
Cache Miss
• If the data is not present in the cache, then a Read miss or Write miss occurs.
• Read miss:
Block of words containing this requested word is transferred from the memory.
After the block is transferred, the desired word is forwarded to the processor.
The desired word may also be forwarded to the processor as soon as it is transferred
without waiting for the entire block to be transferred. This is called load-through or
early-restart.
• Write-miss:
Write-through protocol is used, then the contents of the main memory are
updated directly.
If write-back protocol is used, the block containing the
addressed word is first brought into the cache. The desired word
is overwritten with new information.
Cache Coherence Problem
• A bit called as “valid bit” is provided for each block.
• If the block contains valid data, then the bit is set to 1, else it is 0.
• Valid bits are set to 0, when the power is just turned on.
• When a block is loaded into the cache for the first time, the valid bit is set to 1.
• Data transfers between main memory and disk occur directly bypassing the cache.
• When the data on a disk changes, the main memory block is also updated.
• However, if the data is also resident in the cache, then the valid bit is set to 0.
• What happens if the data in the disk and main memory changes and the write-
back protocol is being used?
• In this case, the data in the cache may also have changed and is indicated by the
dirty bit.
• The copies of the data in the cache, and the main memory are different. This is
called the cache coherence problem.
• One option is to force a write-back before the main memory is updated from the
disk.
Mapping Functions
Mapping functions determine how memory blocks
are placed in the cache.
A simple processor example:
Cache consisting of 128 blocks of 16 words each.
Total size of cache is 2048 (2K) words.
Main memory is addressable by a 16-bit address.
Main memory has 64K words.
Main memory has 4K blocks of 16 words each.
Three mapping functions:
Direct mapping
Associative mapping
Set-associative mapping.
Direct Mapping
Main Block 0
•Block j of the main memory maps to j modulo 128 of
memory
the cache. 0 maps to 0, 129 maps to 1.
Cache Block 1
•More than one memory block is mapped onto the
tag
Block 0 same position in the cache.
tag
Block 1 •May lead to contention for cache blocks even if the
cache is not full.
Block 127
•Resolve the contention by allowing new block to
Block 128 replace the old block, leading to a trivial replacement
tag algorithm.
Block 127 Block 129
•Memory address is divided into three fields:
- Low order 4 bits determine one of the 16
words in a block.
Block 255 - When a new block is brought into the cache,
Tag Block Word
Block 256 the the next 7 bits determine which cache
5 7 4
block this new block is placed in.
Block 257
Main memory address - High order 5 bits determine which of the possible
32 blocks is currently present in the cache. These
are tag bits.
•Simple to implement but not very flexible.
Block 4095
Associative Mapping
Main Block 0
memory
•Main memory block can be placed into any cache
Cache Block 1
position.
tag
Block 0 •Memory address is divided into two fields:
tag
Block 1
- Low order 4 bits identify the word within a block.
- High order 12 bits or tag bits identify a memory
Block 127 block when it is resident in the cache.
Block 128 •Flexible, and uses cache space efficiently.
tag
Block 127 Block 129
•Replacement algorithms can be used to replace an
existing block in the cache when the cache is full.
•Cost is higher than direct-mapped cache because of
the need to search all 128 patterns to determine
whether a given block is in the cache.
Block 255
Tag Word
12 4 Block 256
Block 4095
Set-Associative mapping
Cache
Main
Blocks of cache are grouped into sets.
Block 0
memory Mapping function allows a block of the main
tag Block 0
Block 1 memory to reside in any block of a specific set.
tag Block 1 Divide the cache into 64 sets, with two blocks per set.
tag Block 2 Memory block 0, 64, 128 etc. map to block 0, and
they can occupy either of the two positions.
tag Block 3
Block 63 Memory address is divided into three fields:
- 6 bit field determines the set number.
Block 64
- High order 6 bit fields are compared to the tag
tag
Block 126 Block 65 fields of the two blocks in a set.
tag
Block 127
Block 4095
Replacement Algorithms
• For direct mapping where there is only one possible line for a block of memory, no
replacement algorithm is needed.
• For associative and set associative mapping, however, an algorithm is needed.
•For maximum speed, this algorithm is implemented in the hardware. Four of the most
common algorithms are:
1. Least Recently Used:- This replaces the candidate line in cache memory that has
been there the longest with no reference to it.
2. First In First Out:- This replaces the candidate line in the cache that has been there
the longest.
3. Least Frequently Used:- This replaces the candidate line in the cache that has had the
fewest references.
4. Random Replacement:- This algorithm randomly chooses a line to be replaced from
among the candidate lines. This yields only slightly inferior performance than other
algorithms.
FIFO (First In First Out)
• Pages in main memory are kept in a list
• First in first out is very easy to implement
• The FIFO algorithm select the page for replacement that has been in memory
the longest time
FIFO (First In First Out)
• Advantages:
• FIFO is easy to understand.
• It is very easy to implement.
• Disadvantages:
• The oldest block in memory may be often used.
LRU (Least Recently Used)
• The least recently used page replacement algorithm keeps track page uses over a
short period of time.
LRU (Least Recently Used)
• Advantages:
• LRU page replacement algorithm is quiet efficient.
• Disadvantages:
• Implementation difficult. This algorithm requires keeping track of
what was used when, which is expensive if one wants to make sure
• the algorithm always discards the least recently used item.
Comparison of Clock with FIFO and LRU
LFU (Least Frequently Used)
• The Least-Frequently-Used (LFU) Replacement technique replaces the
least-frequently block in use when an eviction must take place.
• Software counter associated with each block, initially zero is required in
this algorithm.
• The operating system checks all the blocks in the cache at each clock
interrupt.
• The R bit, which is '0' or '1', is added to the counter for each block.
Consequently, the counters are an effort to keep track of the frequency of
referencing each block.
• When a block must be replaced, the block that has the lowest counter is
selected for the replacement.
LFU (Least Frequently Used)
• Advantage:
• Extremely simple
• Disadvantages:
• Can easily make "bad" choices by swapping out pages right before
Performance considerations
Performance Considerations
• A key design objective of a computer system is to
achieve the best possible performance at the lowest
possible cost.
– Price/performance ratio is a common measure of success.
• Performance of a processor depends on:
– How fast machine instructions can be brought into the
processor for execution.
– How fast the instructions can be executed.
Interleaving
Divides the memory system into a number of memory modules.
Each module has its own address buffer register (ABR) and data buffer register
(DBR).
Arranges addressing so that successive words in the address space
are placed in different modules.
When requests for memory access involve consecutive addresses,
the access will be to different modules.
Since parallel access to these modules is possible, the average rate
of fetching words from the Main Memory can be increased.
Methods of Address Layouts
mbits k bits
k bits mbits
Module Address in module MM address Address in module Module MM address
ABR DBR ABR DBR ABR DBR ABR DBR ABR DBR ABR DBR
used.
Virtual Memory
Virtual Memory
Recall that an important challenge in the design of a computer
system is to provide a large, fast memory system at an affordable
cost.
Architectural solutions to increase the effective speed and size
of the memory system.
Cache memories were developed to increase the effective speed
of the memory system.
Virtual memory is an architectural solution to increase the
effective size of the memory system.
57
Virtual Memory (contd..)
Recall that the addressable memory space depends on the
number of address bits in a computer.
For example, if a computer issues 32-bit addresses, the addressable memory space is 4G bytes.
58
Virtual Memory (contd..)
When a new piece of a program is to be transferred to
the main memory, and the main memory is full, then
some other piece in the main memory must be
replaced.
Recall this is very similar to what we studied in case of cache memories.
59
Virtual Memory (contd..)
Techniques that automatically move program and data
between main memory and secondary storage when
they are required for execution are called virtual-
memory techniques.
Programs and processors reference an instruction or data
independent of the size of the main memory.
Processor issues binary addresses for instructions and
data called logical or virtual addresses.
Virtual addresses are translated into physical addresses
by a combination of hardware and software subsystems.
If virtual address refers to a part of the program that is currently in the main memory, it is
accessed immediately.
If the address refers to a part of the program that is not currently in the main memory, it is first
transferred to the main memory before it can be used.
60
Virtual Memory Organization
Processor
Disk storage
61
Address Translation
Assume that program and data are composed of fixed-
length units called pages.
A page consists of a block of words that occupy
contiguous locations in the main memory.
Page is a basic unit of information that is transferred
between secondary storage and main memory.
Size of a page commonly ranges from 2K to 16K bytes.
Pages should not be too small, because the access time of a secondary storage device is much
larger than the main memory.
Pages should not be too large, else a large portion of the page may not be used, and it will
occupy valuable space in the main memory.
62
Address Translation (contd..)
• Virtual memory:
– Introduced to bridge the speed gap between the main memory and secondary storage.
– Implemented in part by software.
63
Address Translation (contd..)
Each virtual or logical address generated by a processor is interpreted
as a virtual page number (high-order bits) plus an offset (low-order
bits) that specifies the location of a particular byte within that page.
Information about the main memory location of each page is kept in
the page table.
Main memory address where the page is stored.
Area of the main memory that can hold a page is called as page
frame.
Starting address of the page table is kept in a page table base register.
64
Address Translation (contd..)
65
Address Translation (contd..)
PTBR holds Virtual address from processor
Page table base register
the address of
the page table. Page table address Virtual page number Offset
Virtual address is
interpreted as page
+ number and offset.
PAGE TABLE
PTBR + virtual
page number provide
the entry of the page This entry has the starting location
in the page table. of the page.
One bit indicates whether the page has been modified during its
residency in the main memory.
This bit determines whether the page should be written back to the disk when it is removed from the main
memory.
Similar to the dirty or modified bit in case of cache memory.
67
Address Translation
(contd..)
• Other control bits for various other
imposed.
– For example, a program may only have read permission for a page,
68
Address Translation (contd..)
69
Address Translation (contd..)
A small cache called as Translation Lookaside Buffer (TLB) is included in
the MMU.
TLB holds page table entries of the most recently accessed pages.
Recall that cache memory holds most recently accessed blocks from
the main memory.
Operation of the TLB and page table in the main memory is similar to the operation of the cache
and main memory.
In addition to the above for each page, TLB must hold the virtual page
number for each page.
70
Address Translation (contd..)
Virtual address from processor
71
Physical address in main memory
Address Translation (contd..)
How to keep the entries of the TLB coherent with the contents of
the page table in the main memory?
Operating system may change the contents of the page table in
the main memory.
Simultaneously it must also invalidate the corresponding entries in the TLB.
72
Address Translation (contd..)
73
Address Translation (contd..)
75
Address Translation (contd..)
76
Address Translation (contd..)
77
Input and Output Organization:
Data Transfer Techniques
computer system.
Input and Output Organization:
Data Transfer Techniques
Peripheral Devices:
Input or output devices that are connected to computer are called
peripheral devices.
These devices are designed to read information into or out of the
memory unit upon command from the CPU and are considered to be the
part of computer system. These devices are also called peripherals.
For example: Keyboards, display units and printers are common peripheral
devices.
Programmed I/O
Each IOP controls and manage the input-output tasks. The IOP is
processing. The IOP can fetch and execute its own instructions.
Processors. The memory unit occupies the central position and can
The CPU processes the data required for solving the computational
tasks. The IOP provides a path for transfer of data between peripherals
and memory. The CPU assigns the task of initiating the I/O program.
The IOP operates independent from CPU and transfer data between
Memory Management
Memory management
• Operating system is concerned with transferring programs and
data between secondary storage and main memory.
• Operating system needs memory routines in addition to the
other routines.
• Operating system routines are assembled into a virtual
address space called system space.
• System space is separate from the space in which user
application programs reside.
– This is user space.
• Virtual address space is divided into one
system space + several user spaces.
Memory management (contd..)
Recall that the Memory Management Unit (MMU) translates
logical or virtual addresses into physical addresses.
MMU uses the contents of the page table base register to
determine the address of the page table to be used in the
translation.
Changing the contents of the page table base register can enable us to
use a different page table, and switch from one space to another.
At any given time, the page table base register can point to
one page table.
Thus, only one page table can be used in the translation process at a
given time.
Pages belonging to only one space are accessible at any
given time.
Memory management (contd..)
When multiple, independent user programs coexist in the
main memory, how to ensure that one program does not
modify/destroy the contents of the other?
Processor usually has two states of operation:
Supervisor state.
User state.
Supervisor state:
Operating system routines are executed.
User state:
User programs are executed.
Certain privileged instructions cannot be executed in user state.
These privileged instructions include the ones which change page
table base register.
Prevents one user from accessing the space of other users.
Memory Mapped I/O
• There is no specific input or output instructions
• The CPU can manipulate I/O data residing in interface registers with the same instructions that
are used to manipulate memory words.
• Each interface is organized as set of registers(read & write in normal address space).
• Memory mapped I/O can use memory type instructions to access I/O data.
• It allows the computer to use the same instructions for either i/o transfer or for memory
transfers.
• The advantage is that the load and store instructions used for reading and writing from memory
can be used to input and output data from I/O registers.
Data
Memory address
Memory read
Memory
write
a) CPU Signals b) Address space division
Difference between Memory mapped
I/O and I/O mapped I/O
Memory Mapped Input/Output Input/Output Mapped Input/Output
1. Each port is treated as a memory Each port is treated as an independent unit.
location.
2. CPU’s memory address space is Separate address spaces for memory and
divided between memory and input/output ports.
input/output ports.
3. Single instruction can transfer Two instruction are necessary to transfer
data between memory and port. data between memory and port.
4. Data transfer is by means of Each port can be accessed by means of IN
instruction like MOVE. or OUT instructions.
Program Controlled I/O
• Program controlled I/O is one in which the processor repeatedly checks a status flag to
achieve the required synchronization between processor & I/O device.
• The processor polls the device.
• It is useful in small low speed systems where hardware cost must be minimized.
• It requires that all input/output operators be executed under the direct control of
the CPU.
• The transfer is between CPU registers(accumulator) and a buffer register
connected to the input/output device.
• The i/o device does not have direct access to main memory.
• A data transfer from an input/output device to main memory requires the
execution of several instructions by the CPU, including an input instruction to
transfer a word from the input/output device to the CPU and a store instruction to
transfer a word from CPU to main memory.
• One or more additional instructions may be needed for address communication
and data word counting.
Typical Program Controlled
Instructions
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Call CALL
Return RET
Compare CMP
Test(by ADDing) TST
Interrupts
• A Suspension of a process such as the execution of a computer program,
caused by an event external to that process, and performed in such a
way that the process can be resumed. A way to improve processor
utilization.
• The processor set this register bit 1 when the interrupt accept and
when a return instruction is executed, the contents of the PS are
cleared (0)and stored in the stack again.
Handling Multiple Devices