Unit 5 Memory Organization
Unit 5 Memory Organization
Memory Organization
Contents
• Basic concept and hierarchy
• semiconductor RAM memories and types,
ROM memories and types.
• Cache memories: concept and design issues
( performance, address mapping and
replacement)
• Virtual memory: concept implementation
Memory
• The memory unit is an essential component in any digital computer since
it is needed for storing programs and data.
• Not all accumulated information is needed by the processor at the same
time.
• So it is more economical to use low cost storage devices as a backup for
storing the information which is not currently used by the CPU.
• The execution speed of programs is highly dependant on the speed with
which instruction and data can be transferred between the processor and
memory.
• There are 3 basic parameters of memory:--
• Capacity
• Speed
• Cost per bit
Capacity
• Memory can be viewed as a storage unit
containing m number of locations (addresses),
each of which stores n number of bits..
• Each word is addressed uniquely by log2m
number of bits.
• The total capacity of a memory is expressed as
mXn bit or m word memory.
• Ex. A 16 bit computer that generates 16-bit
address is capable of addressing up to 216=64K
memory locations.
MEMORY
The data and Instructions that are entered into the computer by the
input devices needs to be stored in the computer’s memory before
the actual processing.
And the results after processing and the intermediate results also
need to be stored in the computer’s memory.
It basically provides the space for storing of the data and instructions
before processing, during processing and after processing.
CPU
Register
Cache
Access time
Cost per bit
capacity
Primary or Main Memory
(RAM /ROM )
Flash Memory
Secondary
Hard disk
CD and DVD or
Magnetic tape Auxiliary
memory
Types of Memory
Memory
Magnetic tape
RAM ROM
Primary memory is a type of memory that is available in the form of silicon chips. These chips are
created by IC by using very large scale integration techniques.
It stores data and instructions that are necessary to perform an operation. It holds both the
intermediate and final results of the computer during processing as the program proceeds.
In random access memory, any memory location can be accessed in a random way without
going through any other location. The access time is same for each and every memory
location.
RAM is also called read-write memory. RAM is used in computers for temporary storage of
data.
The major drawback of RAM is that it is volatile i.e. it stores information as long as the power
is supplied to it. Its contents are lost when power supply is switched off or interrupted.
Bit Cell
Bit Lines
High
Sense Amplifier
Low
Address Data
Static RAM
• SRAM is made from an array of filp-flops , where each flip flop maintains
a single bit of data within a single memory location
• SRAM uses multiple transistors for each memory cell.
• Each bit of memory is held by a flip-flop memory which takes four to six
transistors besides some wiring.
Word
Read: Drive word line, sense
Line value on bit lines
Bit
!Bit
Dynamic RAM
Dynamic random-access memory (DRAM) is a type of random access memory that
stores each bit of data in a separate capacitor within an integrated circuit. The
capacitor can be either charged or discharged; these two states are taken to represent
the two values of a bit, conventionally called 0 and 1.
Since capacitors leak charge, the information eventually fades unless the capacitor
charge is refreshed periodically. Because of this refresh requirement
Due to the way in which the cells are constructed, the reading action itself refreshes
the contents of the memory. If this is not done regularly, then the DRAM will lose its
contents, even if it continues to have power supplied to it. This refreshing action is why
the memory is called dynamic.
DRAMs are smaller and less expensive than SRAMs because SRAMs are made from
four to six transistors (or more) per bit, DRAMs use only one, plus a capacitor.
Refreshing Circuit
Like Capacitor
A Refereshing Circuit is required to recharge or reload the data.
Dynamic RAM (DRAM)
Word Line
Bit Line
Random-Access Memory (RAM)
• Static RAM (SRAM)
– Each cell stores bit with a six-transistor circuit.
– Retains value indefinitely, as long as it is kept powered.
– Relatively insensitive to disturbances such as electrical noise.
– Faster (8-16 times faster) and more expensive (8-16 times more expensice as
well) than DRAM.
ROM chips also comprise of columns and rows but it is different from
RAM in terms of intersection of these. These chips use diodes instead
of transistors to connect the lines if the value is 1 whereas if the value is
0 the lines are not connected.
A ROM chip cannot be reprogrammed or rewritten therefore when the
chip is created it requires the programming of perfect and complete
information. ROM chips are cost effective and use very little power.
ROM (Read Only Memory)
ROM is a memory that performs only read operation.
PROM chips have a grid of columns and rows just as ordinary ROMs do. The
difference is that every intersection of a column and row in a PROM chip has a
fuse connecting them.
A charge sent through a column will pass through the fuse in a cell to a
grounded row indicating a value of 1. Since all the cells have a fuse, the initial
(blank) state of a PROM chip is all 1s.
• These chips are erased and rewritten with the help of electric charge.
In EEPROMs:
• The chip does not have to removed to be rewritten.
• The entire chip does not have to be completely erased to change a specific
portion of it.
• Changing the contents does not require additional dedicated equipment.
RAM and ROM chips
RAM
• The block diagram of a RAM chip has been shown.
• The capacity of memory is 128 words of 8 bits
each.
• This require a 7 bit address and an 8 bit
bidirectional data bus.
• The read write inputs specify the memory
operation and the two chip select CS control
inputs are for enabling the chip only when it is
selected by the microprocessor.
RAM
• The unit is in operation only when CS1=1 and CS2 =0.
• If the chip select inputs are not enabled or if they are enabled
but the read write inputs are not enabled the memory is
inhibited and its data bus is in high impedance state.
• When CS1=1 and CS2=0 the memory can be read or write
mode.
• When WR input is enabled the memory stores a byte from
the data bus into a location specified by the address input line
• When RD input is enabled the content of selected bytes are
placed into the bus.
ROM Chip
ROM can only read, the data bus can only be in an output mode.
For the same size chip, it is possible to have more bits of ROM
than of RAM, because the internal binary cells in ROM occupy
less space than in RAM.
For this reason, the diagram specifies a 512 byte ROM, while the
RAM has only 128 bytes.
The nine address lines in the ROM chip specify any one of the
512 bytes stored in it.
ROM chip
Example 1
• Assume that a computer system needs
512 bytes of RAM and 512 bytes of ROM.
= 512 X 8
• 128 X 8
Example 1
128 X 8 RAM 1
128 X 8 RAM 2
512 X 8 RAM
128 X 8 RAM 3
128 X 8 RAM 4
Memory connection to CPU
• RAM and ROM chips are connected to a CPU through the data and address
buses.
• The low order lines in the address bus select the byte within the chips and other
lines select the particular chip.
• In the previous example each RAM chip receives 7 low order bits of address bus
to select one of 128 possible bytes.
• The particular RAM chip selected is determined from lines 8 and 9. This is done
through a 2 X 4 decoder. Whose outputs are connected to the CS1 input in each
RAM chip.
• The selection between the RAM and ROM is achieved by line 10.
Memory address map
• The designer of a system must calculate the amount
of memory required for the particular application
and assign it to either RAM or ROM.
Let us assume that a computer system needs 512 bytes of RAM and 512
bytes of ROM
The RAM chips have 128 bytes and need seven address lines. The ROM
chip has 512 bytes and needs 9 address lines.
The X’s are always assigned to the low order bus lines: lines 1 through 7
for the RAM and lines 1 through 9 for the ROM. It is now necessary to
distinguish between 4 RAM chips by assigning to each a different address.
• The hexadecimal address assigns a range of
hexadecimal equivalent address for each chip
RAM1 0000-007F
Questions?
• How many 128 X 8 RAM chips are needed to
provide a memory capacity of 2048 bytes?
• How many lines of the address bus must be
used to access 2048 bytes of memory? How
many of these lines will be common to all
chips?
• How many lines must be decoded for chip
select? Specify the size of the decoder.
Solution
• No. of chips= 2048 X 8 = 211/ 27=24=16 RAM chips
128 X 8
RAM 12
RAM 13
RAM 14
RAM 15
RAM 7
RAM 8
RAM 5
RAM 9
RAM 1
RAM 2
RAM 3
RAM 4
RAM 6
RAM
RAM
10
16
CS1
CS1
CS 1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
CS1
16 out put lines each will be
connected to CS 1of RAM chip
0 1 2 3 4 --------------16
Decoder
4 X 16 7 address lines to access 128
words.
11 10 9 8 7654321
Question?
• A computer uses RAM chip of 1024 X 1 capacity.
• (a) How many chips are needed, and how
should their address lines be connected to
provide a memory capacity of 1024 bytes?
• (b) How many chips are needed to provide a
memory capacity of 16K bytes? Explain in words
how the chips are to be connected to the
address bus?
Solution 2
• No. of chips= 1024 X 8 = 8 chips
1024 X 1
Solution 2
8 bit data
CS RD WR CS RD WR CS RD WR CS RD WR CS RD WR
CS RD WR
Solution 2
• If total memory capacity is 16K bytes then the no. of
chips required will be
• 16 X 1024 X 8 = 16 X 8
• 1024 X 1
• So 16 rows will be there. And in each row there will
be 8 RAM chips of size 1024 x1.
• Total address lines will be 16 K=24 X 210=214
• 4X 16 decoder will be used.
• All the 8 chips of a decoder will be activated at a time.
Solution 2 16 K bytes
RAM 1 RAM2 RAM3 RAM4 RAM5 RAM6 RAM7 RAM8
Main
Processor Cache memory
• Processor issues a Read request, a block of words is transferred from the main
memory to the cache, one word at a time.
• Subsequent references to the data in this block of words are found in the cache.
• At any given time, only some blocks in the main memory are held in the cache.
Which blocks in the main memory are in the cache is determined by a “mapping
function”.
• When the cache is full, and a block of words needs to be transferred
from the main memory, some block of words in the cache must be
replaced. This is determined by a “replacement algorithm”.
The working of cache
• When the cpu needs to access the memory,
the cache is examined. If the word is found in
the cache, it is read from there. If it is not
found in the cache, the main memory is
accessed to read the word. A block of word
containing the one just accessed is then
transferred from main memory to cache..
Cache hit
• Existence of a cache is transparent to the processor. The processor issues
Read and Write requests in the same manner.
• Read hit:
The data is obtained from the cache.
• 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.
Hit Ratio
• The performance of cache memory
• When the CPU refers to memory and finds the word in the cache its is
said to produce a hit.
• If the word is not found in cache it is in main memory and it counts as
miss.
Hit ratio=Total hits/ total CPU references to memory
First-In-First-Out (FIFO):
The FIFO algorithm selects for replacement the item that has been in the cache from the longest
time.
Random:
The random algorithm selects for replacement the item randomly.
Writing into Cache
• When the CPU finds a word in cache during a read operation,
main memory is not involved.
CPU
Main Memory
32 K X 12 Cache
memory
512 X 12
Associative mapping
• The associative memory stores the address and data of memory
word.
• Here the address is of 15 bits and data is of 12 bits.
• A cpu address of 15 bit is placed in argument register and the
associative memory is searched for the matching address.
• If the address is found the corresponding 12 bit data is read from
the memory.
• If no match occurs, main memory is accessed for the word.
• The address data pair is than transferred to the associative cache
memory.
• If the cache is full then a pair of address of data is replaced from the
memory.
Fully Associative Cache Organization
Direct mapping
• Associated memories are expansive compared to RAM
because of the address logic associated with each cell.
• In direct mapping address is divided in two fields (1)
index (2) tag
• The number of bits in the index field is equal to the no.
of address bits required to access the cache memory.
• In general if there are 2K words in cache memory and 2n
words in main memory. The n bit memory address is
divided into two fields
• K bits for index and n-k bits for tag.
Direct mapping
Direct mapping
Direct Mapping
• Each word in cache consist of the data word and its
associated tag. When a new word is first brought into
the cache the tag bits are stored alongside the data bits.
• The index field is used to access the cache.
• The tag field is compared.
• If the two tag match, there is a hit and desired data is in
cache.
• If there is a miss the required word is read from main
memory, and stored in the cache together with the new
tag replacing the previous value.
Direct mapping
777 01 4560
Direct Mapping Cache Organization
Block
• The disadvantage of direct mapping is that the
hit ratio can drop if two or more words whose
address have the same index but different tags
are accessed repeatedly.
• Ex 01000, 02000, 03000
• This possibility is minimized by the fact that
they will be far apart in the address range.
Direct mapping
• If the cache uses block size of 8 words. Then
the index is divided into two fields.
• (1) block (2) word
• 512/ 8 =64 blocks 6 bits for block
• 9-6=3 bits for word
•
Tag Block Word
6 6 3
Question
• A digital computer has a memory unit of 64K X
16 and a cache memory of 1K words. The
cache can use direct mapping with a block size
of four words.
• (a) how many bits are there in the tag, index,
block and word fields of the address format?
• (b) how many block can the cache
accommodate?
Solution
• Cache size 1K= 210
• So 10 bits are required to address the cache
memory. Index=10bits
• Total memory capacity=64K= 216
• Tag=16-10=6bits
• No. of blocks=1024/4=256=28
• 8 bits for block
• 2 bits for words
Set-Associative mapping
• This organization shows an improvement over
the direct mapping technique.
• Each data word is store two or more words of
memory under the same index addresses.
• Each data word is stored together with its tag.
• The number of tag-data items in one word of
cache is said to form a set.
Set Associative Cache Organization
Set associative mapping
Set associative mapping
• Here each index address refers to two data words and
their associated tags.
• Each tag require 6 bits and each data word is of 12 bits.
• So the word length is 2(6+12)=36 bits.
• An index address of 9 bits can accommodate 512 words.
• Thus the size of cache memory is 512X36 bits.
• It can store 1024 words of main memory.
• In general a set associative cache of set size k will
accommodate k words of main memory in each word of
cache.
Set associative mapping
• When the cpu generates a memory request,
the index value of the address is used to
access the cache.
• The tag field of the address is then compared
with both tags in the cache to determine if a
match occurs.
• The comparison logic is done by an associative
search of the tags.
Questions
arm
The surface consists
of a set of concentric
magnetized rings called
tracks
The read/write
head floats over
the disk surface
and moves back
Each track is divided and forth on an
into sectors arm from track to
track.
Disk Operation
• Operation
– Read or write complete sector
• Seek
– Position head over proper track
• Rotational Latency
– Wait until desired sector passes under head
• Read or Write Bits
– Transfer rate depends on # bits per track and
rotational speed
Logical vs. Physical Address Space
• The concept of a logical address space that is
bound to a separate physical address space is
central to proper memory management
– Logical address – generated by the CPU; also referred to
as virtual address
– Physical address – address seen by the memory unit
• Logical and physical addresses are the same in
compile-time and load-time address-binding
schemes; logical (virtual) and physical addresses
differ in execution-time address-binding scheme
Base and Limit Registers
MMU
yes
CPU < +
no physical
MMU address
error