Chapter 3 Lecture 1
Chapter 3 Lecture 1
DMiT
School of Electrical & Computer Engineering
Chapter Three(Lecture 1)
Memory Basics
1
Computer Memory Overview
• The memory is that part of computer where programs and
data are stored.
• The basical concept is the following:
– Bits
• The basic unit of memory is the binary digit called a bit. A
bit may contain a 0 or 1. It is the simplest possible unit
– Memory addresses
• Memories consist of a number of cells or locations each of
which can store a piece of information. Each location has a
number called its address, by which program can refer to it.
The cells is the smallest addressable
• Byte: 8-bits
• Bytes are grouped into words. The significance of word is
that most instruction operate on entire word. A computer
with a 32bit/word has 4 bytes/word
2
Characteristics of Memory Systems
• Classifying and studying memory systems using their key
characteristics
• Location
• Capacity
• Unit of transfer
• Access method
• Performance
• Physical type
• Physical characteristics
3
Characteristics of Memory Systems…Cntd
• Location
• Refers to whether memory is internal or external to computer
system
• Internal memory
• Cache
• CPU registers
• External memory
4
Characteristics of Memory Systems…Cntd
• Capacity
• the amount of information that can be contained in a memory unit
5
Characteristics of Memory Systems…Cntd
• Unit of Transfer
• For internal memory
• Usually governed by data bus width
• May be equal to a word
• For external memory
• Data transferred in much larger units than a word
• Usually a block which is much larger than a word
6
Characteristics of Memory Systems…Cntd
• Access Methods
• Sequential Access
7
Characteristics of Memory Systems…Cntd
• Random Access
• The computer system can read or write information anywhere
in the data file.
• e.g. RAM
• Associative Access
• A method of addressing a location by virtue of its data content
rather than by its physical location.
• An access is made by specifying something about the contents
of the desired location rather than by using a normal address.
• e.g. Some cache memory units
8
Characteristics of Memory Systems…Cntd
Performance
• Access time (latency)
• It is the time it takes to perform a read or write operation
• Memory Cycle time
• Cycle time is the time, usually measured in nanoseconds, between
the start of one random access memory access to the time when the
next access can be started.
• applicable to RAM
• Transfer rate
• The rate at which data can be transferred into or out of a memory unit
9
Characteristics of Memory Systems…Cntd
• Physical Types
• Semiconductor
• RAM
• Magnetic
• Disk & Tape
• Optical
• CD & DVD
10
Characteristics of Memory Systems…Cntd
Physical Characteristics
◦ Volatility
Volatile memory
Information is lost when electrical power is switched off
E.g RAM
Non Volatile memory
Information once recorded remains without deterioration
Electrical power not needed to retain information
E.g magnetic storage unit
Non erasable memory
cannot be altered
ROM
11
Types of Memory
• Main Memory (“Internal” memory components)
• RAM (read-write memory): Static RAM, Dynamic RAM
• ROM (Read Only Memories) : ROMs, PROMs, EPROMs,
EEPROMs, Flash Memory.
• Cache memory
• The cache memories are high-speed buffers for holding
recently accessed data and neighbouring data in main memory.
• External Memory
• Magnetic disks
• Optical disks
• Magnetic tape
12
Memory Hierarchy
• Basic elements in memory hierarchy
• Registers
• In CPU
• Internal or Main memory
• May include one or more levels of cache
• “RAM”
• External memory
• Backing store
13
Memory Hierarchy…Cntd
Design constraint on computer’s memory system
◦ How much ?
capacity
◦ How fast ?
To achieve performance, memory must keep up with processor
◦ How expensive ?
Cost must be reasonable in relationship to other components
14
Memory Hierarchy…Cntd
• Trade off among three key characteristics of memory: Capacity ,
Access time and Cost
• faster access time --- greater cost per bit
• greater capacity --- smaller cost per bit
• greater capacity --- slower access time
• Solution:
• Not to rely on a single memory component or tech
• Employ memory hierarchy
15
Memory Hierarchy - Diagram
16
Hierarchy List
• Registers
• L1 Cache
• L2 Cache
• Main memory
• Disk
• Optical
• Tape
17
Semiconductor Memory
• RAM
• Misnamed as all semiconductor memory is random access
• What should be its name?
• Possible to Read/Write
• Volatile
• Can be used only as a temporary storage
• Two types of technologies can be used to built RAM:
• Dynamic RAM (DRAM)
• Static RAM (SRAM)
18
Semiconductor Memory…Cntd
• Dynamic RAM (DRAM)
• Bits stored as charge in capacitors
• Charges leak
• Need refreshing even when powered
• Less expensive
• Slower
• Used for main memory
19
Semiconductor Memory…Cntd
• Static RAM
• Bits stored using flip flops, on/off switches
• No charges to leak
• No refreshing needed when powered
• More expensive
• Faster
• Used for cache memory
20
Semiconductor Memory…Cntd
• SRAM v DRAM
• Both volatile
• Power needed to preserve data
• Dynamic
• Less expensive
• Needs refresh
• Main memory
• Static
• Faster
• Cache
21
Semiconductor Memory…Cntd
• Types of ROM (PROM, EPROM, EEPROM and Flash memory)
• Read Only Memory (ROM)
• contains a permanent pattern of data that cannot be changed
• Nonvolatile
• Read but cannot write
• Used for
• Microprogramming , Library subroutines – for frequently used
functions, system programs (BIOS)
• Written during fabrication
22
Semiconductor Memory…Cntd
• Programmable ROM (PROM)
• Programmed only once
• Once the PROM is programmed, the information written is permanent
and cannot be erased or deleted
• Read “mostly” memory
• Erasable Programmable (EPROM)
• The data can be erased and reprogrammed by using ultraviolet (UV)
light.
• The UV light clears the data on the chip so that it can reprogram.
• Electrically Erasable (EEPROM)
• Cells don’t need to be erased before programming
• It can be programmed and erased electrically using electron emission
• Flash memory
• It can be electrically erased and reprogrammed.
• It was developed from EEPROM (electronically erasable
programmable read-only memory).
23
Summery of Semiconductor Memory
24
Types of External Memory
• Magnetic tape
• Magnetic disc
• Optical
• CD-ROM
• CD-Recordable (CD-R)
• CD-R/W
• DVD
• DVD-R/W
25
Magnetic Tape
• Serial access
• Slow
• Very cheap
• Backup
26
Magnetic Disk
• A magnetic disk is a storage device that uses a magnetization process to
write, rewrite and access data.
• Are widely used to store computer data as well as audio and video
signals.
• Hard disks and floppy disks are common examples of magnetic disks.
27
Optical Storage
• CD-ROM
– can store up to 700 MB of data.
– the data cannot be altered or overwritten.
– It is typically used to store software programs.
– CDs can store audio and video data, as well as text and program
instructions.
28
Optical Storage…Cntd
• CD-Recordable (CD-R)
•It can only record data once, then the data becomes permanent on
the disc.
•Custom made music CDs
• CD-RW
• can be written, read, erased, and re-written
• Digital Video Disk (DVD-ROM,DVD-R and DVD-RW)
• Rapidly replacing CD
• Has higher capacity
29
Cache Memory
• Small amount of fast memory
30
Cache and Main Memory
31
Cache operation
• CPU requests contents of memory location
32
Cache Read Operation - Flowchart
33
Typical Cache Organization
34
Cache/Main Memory Structure
M = 2n / K blocks in RAM
C << M blocks in cache
35
Mapping Functions
• The transformation of data from main memory to cache memory is
referred to as mapping process
• It is used when copying a block from main memory to the cache and
Also it is used again when trying to retrieve data from the cache
– Associative
– Set Associative
36
Direct Mapping
• Each block of main memory maps to only one cache line
• So, simple and inexpensive
• Line number is calculated using the following function
i = j modulo m
where
37
Direct Mapping…Cntd
• For example, on the right
is a 16-byte main memory
and a 4-byte cache (four
1-byte blocks).
– Memory locations 0, 4, 8
and 12 all map to cache
block 0.
– Addresses 1, 5, 9 and 13
map to cache block 1, etc.
– How can we compute this mapping?
38
Direct Mapping Cache Line Table
39
Direct Mapping Address Structure
– Most significant s-r bits uniquely identifies the block within a line of
the cache
40
Direct Mapping…Cntd
• Address length = (s + w) bits
41
Direct Mapping Address Structure
• Example 1
• Cache of 64kByte
• 24 bit address
– (224=16M)
42
Direct Mapping Address Structure…Cntd
Tag s-r Line or slot r Word w
8 14 2
• 24 bit address
43
Direct Mapping Address Structure…Cntd
• Example 2
• Show cache addressing for a byte-addressable memory with 32-bit
addresses. Cache line W = 16 B. Cache size L = 4096 lines (64 KB).
Solution
Byte offset in line is log216 = 4 b. Cache line index is log24096 = 12 b.
This leaves 32 – 12 – 4 = 16 b for the tag.
44
Associative Mapping
• Main memory block can be placed into any cache position
45
Associative Mapping…Cntd
• Address length = (s + w) bits
46
Associative Mapping Address Structure
• Example 1
• Cache of 64kByte
47
Set Associative Mapping
• Combination of direct and associative mapping
• Cache is divided into a number of sets
• Each set contains a number of lines
• A block maps to any line in a given set
– e.g. Block B can be in any line of set i
• k lines in a cache is called a k-way set associative mapping
• E.g. 2 lines per set
– Called 2-way set associative mapping
– A given block can be in one of 2 lines in a particular set
48
Set Associative Mapping…Cntd
• Address length is s + w bits
49
Set Associative Mapping Address Structure
• Example 1
• Cache of 64kByte
50
Set Associative Mapping Address Structure…Cntd
• Example 2
• Show cache addressing scheme for a byte-addressable memory with
32-bit addresses. Cache line width = 16 B. Set size(k) = 2 lines.
Cache size = 4096 lines (64 KB).
Solution
Byte offset in line is log216 = 4 b. Cache set index is (log24096/2) = 11 b.
This leaves 32 – 11 – 4 = 17 b for the tag.
11-bit set index in cache
17-bit line tag 4-bit byte offset in line
32-bit
address
51
Set Associative Mapping Address Structure…Cntd
• Example 3
• A 64 KB four-way set-associative cache is byte-addressable and
contains 32 B lines. Memory addresses are 32 b wide. Illustrate the set
Associative mapping address Structure
Solution
Address (32 b) = 5 b byte offset + 9 b set index + 18 b tag
tag set index byte offset
18 bits 9 bits 5 bits
52
Exercise
1. For each of the following addresses, answer the following
questions based on a 2-way set associative cache with 4K lines,
each line containing 16 words, with the main memory of size 256
Meg memory space (28-bit address):
– What cache set number will the block be stored to?
– What will their tag be?
– What will the minimum address and the maximum address of
each block they are in be?
2. A set-associative cache consists of 64 lines, or slots,
divided into four-line sets. Main memory contains 4K blocks of
128 words each. Show the format of main memory addresses.
3. A two-way set-associative cache has lines of 16 bytes and a total
size of 8 kbytes. The 64-Mbyte main memory is byte addressable.
Show the format of main memory addresses.
53
Exercise…Cntd
54