Memory Unit Bindu Agarwalla
Memory Unit Bindu Agarwalla
Bindu Agarwalla
Some Basic concepts
Byte-addressable
Processor Memory
k-bit
address bus
MAR
n-bit
data bus Up to 2kaddressable
MDR locations
Control lines
( R / W , MFC, etc.)
Some Basic concepts
Measures for the speed of a memory:
memory access time.
memory cycle time.
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).
Internal organization of memory chips
Internal organization of memory chips
Each memory cell can hold one bit of information.
All cells of a row are connected to a common line, known as the “word
line”.
4 address lines
8 data lines
2 (R/W +CS)
2 (Power Supply+GND )
16 in Total
For 1K x 1 chip
For 64 x 16 chip
Internal organization of 1K x 1
memory chips
Implementation of a SRAM Cell
The cell is connected to one word line and two bits lines by transistors T1 and
T2.
When word line is at ground level, the transistors are turned off and the latch
retains its state.
Implementation of a SRAM Cell
Read operation:
1. In order to read state of SRAM cell, the word line is activated to close switches T1
and T2. Sense/Write circuits at the bottom monitor the state of b and b’
2. Sense/Write circuits at the bottom monitor the state of b and b’ and set the output
accordingly.
3. If the cell is in state 1, the signal on bit line b is high and the signal on bit line b’ is
low.
4. The opposite is true if the cell is in state 0.
Implementation of a SRAM Cell
Write operation:
1. The state of the cell is set by placing the appropriate value on bit line b and its
complement on b’, and then activating the word line.
3. The required signals on the bit lines are generated by the Sense/Write ckt.
Implementation of a SRAM Cell
Volatile memories, because their contents are lost when power is interrupted.
Threshold
voltage
i.e., we need to connect 512K x 8 chips in a matrix form., where no of columns will
be= size of one location in the bigger size/ size of one location in the smaller size.
No of columns = 32/ 8= 4.
2M X 32 Using 512K X 8 Chips
Step 3: Find out the no of rows:
#rows x 4 =32
#rows =32/8=4
For 2M x 32 , memory, 21(4M=221) address lines are required, and for 512K x 8,
19(512K=219) address lines are required. So, out of 21 address lines, the 1st 19 lines
will be connected to all the 512K x 8 memory chips.
Then to select a row, out of 4 rows of 512K x 8 memory chips, the higher order 2
address lines (out of 21 address lines) are connected to a decoder, and the output of
the decoder will select a particular row. From the selected row, 4 chips of 512K x 8,
will give/ take 8 bits of data each, meeting the required size of 32 bits.
Typical Memory Hierarchy
Registers are at the top of the hierarchy
Microprocessor
Typical size < 1 KB
Access time < 0.5 ns Registers
Bigger
Faster
L2 Cache (512KB – 8MB)
Memory Bus
Access time: 3 – 10 ns
Main Memory
Main Memory (4 – 16 GB) I/O Bus
Access time: 50 – 100 ns
Magnetic or Flash Disk
Cache memory is an architectural arrangement which makes the main memory appear
faster to the processor than it really is.
These instructions may be the ones in a loop, nested loop or few procedures calling each
other repeatedly.
This is called “locality of reference”.
Goal is to achieve
Fast speed of cache memory access.
Balance the cost of the memory system.
The Basics of Caches
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 Basics of Caches: 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.
The Basics of Caches: 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.
Write Allocate:
Allocate new block in cache.
Write miss acts like a read miss, block is fetched and updated.
No Write Allocate:
Send data to lower-level memory.
Cache is not modified.
000
001
010
100
101
011
110
111
In this example:
Cache
Cache index =
least significant 3 bits of
Memory address
Memory
Main
00101
10101
00000
00001
00010
00100
01000
01001
01010
10000
10001
10010
10100
01100
01101
10011
00011
00110
01011
10110
11000
11001
11010
01110
11100
11101
00111
10111
11011
01111
11110
11111
Direct-Mapped Cache
A memory address is divided into
Block address: identifies block in memory
Block Address
Block offset: to access bytes within a block
Tag Index offset
No of blocks in mm=2(s+w)/2w
Number of lines in cache= m=2r
Data
– b bits are used for the block offset Hit
j modulo 128
(a)Calculate the number of bits in each of the Tag, Block, and Word fields of the memory
address.
(b)When a program is executed, the processor reads data sequentially from the following word
addresses:
All the above addresses are shown in decimal values. Assume that the cache is initially empty.
For each of the above addresses, indicate whether the cache access will result in a hit or a miss.
Problem: Solution
Block size = 64 bytes = 26 bytes = 26 words (since 1 word = 1 byte)
Therefore, Number of bits in the Word field = 6
For a given 16-bit address, the 5 most significant bits, represent the Tag, the next 5 bits
represent the Block, and the 6 least significant bits represent the Word.
Problem: Solution
b) The cache is initially empty. Therefore, all the cache blocks are invalid.
Access # 1:
Address = (128)10 = (0000000010000000)2
(Note: Address is shown as a 16-bit number, because the computer uses 16-bit addresses)
Since the cache is empty before this access, this will be a cache miss
After this access, Tag field for cache block 00010 is set to 00000
Problem: Solution
Access # 2:
Address = (144)10 = (0000000010010000)2
Since tag field for cache block 00010 is 00000 before this access, this will be a cache hit
(because address tag = block tag)
Problem: Solution
Access # 3:
Address = (2176)10 = (0000100010000000)2
Since tag field for cache block 00010 is 00000 before this access, this will be a cache
miss (address tag ≠ block tag)
After this access, Tag field for cache block 00010 is set to 00001
Access # 4:
Address = (2180)10 = (0000100010000100)2
Since tag field for cache block 00010 is 00001 before this access, this will be a cache hit
(address tag = block tag)
Problem: Solution
Access # 5:
Address = (128)10 = (0000000010000000)2
Since tag field for cache block 00010 is 00001 before this access, this will be a cache miss
(address tag ≠ block tag)
After this access, Tag field for cache block 00010 is set to 00000
Access # 6:
Address = (2176)10 = (0000100010000000)2
Since tag field for cache block 00010 is 00001 before this access, this will be a cache
miss (address tag ≠ block tag)
After this access, Tag field for cache block 00010 is set to 00001
Example on Cache Placement &
Misses
= = = =
mux
m-way associative Data
Hit
Set-Associative Cache
• A set is a group of blocks that can be indexed.
• A block is first mapped onto a set
– Set index = Block No(in mm) mod Number of sets in
cache
• If there are m blocks in a set (m-way set
associative) then
– m tags are checked in parallel using m comparators
• If 2n sets exist then set index consists of n bits
• Cache data size = m 2n+b bytes (with 2b bytes
Set-Associative Cache Diagram
Address Tag Index offset
V Tag Block Data V Tag Block Data V Tag Block Data V Tag Block Data
= = = =
mux
m-way set-associative Hit
Data
Problem
A computer system uses 16-bit memory addresses. It has a 2K-byte cache organized in a 2-
wat set associative manner with 64 bytes per cache block. Assume that the size of each memory
word is 1 byte.
(a)Calculate the number of bits in each of the Tag, set, and Word fields of the memory address.
(b)When a program is executed, the processor reads data sequentially from the following word
addresses:
All the above addresses are shown in decimal values. Assume that the cache is initially empty.
For each of the above addresses, indicate whether the cache access will result in a hit or a miss.
Problem: Solution
Block size = 64 bytes = 26 bytes = 26 words (since 1 word = 1 byte)
Therefore, Number of bits in the Word field = 6
For a given 16-bit address, the 6 most significant bits, represent the Tag, the next 4 bits
represent the Set, and the 6 least significant bits represent the Word.
Problem: Solution
b) The cache is initially empty. Therefore, all the cache blocks are invalid.
Access # 1:
Address = (128)10 = (0000000010000000)2
(Note: Address is shown as a 16-bit number, because the computer uses 16-bit addresses)
Since the cache is empty before this access, this will be a cache miss
After this access, Tag field for the first block in the cache set 0010 is set to 000000
Problem: Solution
Access # 2:
Address = (144)10 = (0000000010010000)2
Since tag field for the first cache block in the set 0010 is 00000 before this access, this
will be a cache hit (because address tag = block tag)
Problem: Solution
Access # 3:
Address = (2176)10 = (0000100010000000)2
The tag field for this address does not match the tag field for the first block in set 0010.
The second block in set 0010 is empty. Therefore, this access will be a cache miss.
After this access, Tag field for the second block in set 0010 is set to 000010
Access # 4:
Address = (2180)10 = (0000100010000100)2
Since tag field for the 2nd cache block in the set 0010 is 00001 before this access, this
will be a cache hit (address tag = block tag)
Problem: Solution
Access # 5:
Address = (128)10 = (0000000010000000)2
The tag field for this address matches the tag field for the first block in set 0010. Therefore,
this access will be a cache hit.
Access # 6:
Address = (2176)10 = (0000100010000000)2
The tag field for this address matches the tag field for the second block in set 0010.
Therefore, this access will be a cache hit.
Numericals on Mapping
Cache/Memory Layout: A computer has an 8 GByte memory with 64 bit word sizes.
Each block of memory stores 16 words. The computer has a direct-mapped cache of 128
blocks. The computer uses word level addressing. What is the address format? If we
change the cache to a 4-way set associative cache, what is the new address format?
Numericals on Mapping
Direct Mapping Question: Assume a computer has 32 bit addresses. Each block stores 16
words. A direct-mapped cache has 256 blocks. In which block (line) of the cache would we
look for each of the following addresses? Addresses are given in hexadecimal for
convenience.
a. 1A2BC012 b. FFFF00FF c. 12345678 d. C109D532
Numericals on Mapping
A two-way set associative cache memory uses block of 4 words. The
cache can have a total of 2048 words from main memory. The main
memory size is 128K X 32.
i)Draw the format of main memory address.
ii)What is the size of cache with tag bits
Numericals on Mapping
A cache consists of a total of 128 blocks. The main memory contains 2K
blocks, each consisting of 32 words.
( I )How many bits are there in each of the TAG, BLOCK and WORD
field in case of direct mapping?
( ii )How many bits are there in each of the TAG, SET, and WORD
field in case of 4-way set-associative mapping?
Numericals
Design a 4M X 32 bits memory using 512KX8 bits memory chip.
How many external connections are required to design 32MX32 memory chip?
Numericals
A computer employs RAM chips of 256X 8 and ROM chips of 1024X8. The
computer system needs 2K bytes of RAM and 4K bytes of ROM. Design the
memory module of above configuration and interface with CPU.
A computer uses RAM chips of 256X4 capacity. Design a memory capacity of 1KB
by using available chip.
Thank You