CHAPTER 5. Memory Element: Amir Abu Bakar Electrical Engineering Department Ptss
CHAPTER 5. Memory Element: Amir Abu Bakar Electrical Engineering Department Ptss
CHAPTER 5. Memory Element: Amir Abu Bakar Electrical Engineering Department Ptss
Learning Outcomes
After learning of this chapter, student should be able: To know the computer memory organization To understand Virtual Memory Organization To understand cache memory To understand decoder To realize connecting memory chips to computer bus
2
JKE, PTSS
Brainstorming
JKE, PTSS
Memory
Main memory consists of a number of storage locations, each of which is identified by a unique address The ability of the CPU to identify each location is known as its addressability Each location stores a word i.e. the number of bits that can be processed by the CPU in a single operation. Word length may be typically 16, 24, 32 or as many as 64 bits. A large word length improves system performance, though may be less efficient on occasions when the full word length is not used
JKE, PTSS
Memory
N
Read/Write Chip Select (Chip Enable)
2N words
(M-bit per word)
JKE, PTSS
JKE, PTSS
JKE, PTSS
JKE, PTSS
RAM CHIP
Design a 2K x 8 memory chips
A10 A8 A7
D7
2K x 8
A0 D2 D1 CS CS = CHIP SELECT CS = 0 enables the output buffers R/W D0
0 = Write 1 = Read
10
JKE, PTSS
a) Data bus -Carry information b) Address bus- Determine where it should be sent c) Control bus - Determine its operation
JKE, PTSS
12
JKE, PTSS
JKE, PTSS
13
JKE, PTSS
14
15
JKE, PTSS
JKE, PTSS
17
RAM CHIP
Design a 8-word 3 bit RAM chip ?
A0
8X3
D2 D1 D0
CS
R/W
18
JKE, PTSS
Q&A
19
JKE, PTSS
CS
D3 D2 D1 R/W D0
CS
A0
A0
CS
20
JKE, PTSS
Q&A
21
JKE, PTSS
D2
D1 D0
CS
R/W
CS
1Mx4
A0
Prof. Sean Lees Slide, Georgia Tech
CS
R/W
22
JKE, PTSS
Q&A
23
JKE, PTSS
D7
16kx8 CS R/W
D6 D5 D4 D3 D2 D1
R/W
A0
A14 A15
3 2-to-4 2 Decoder 1 0
16kx8 CS
D0
16kx8 CS R/W
CS
16kx8
A0
24
CS
R/W
JKE, PTSS
4 words x 8 bits
0
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
Wordline (WL)
1-bit
1-bit
2 A1 CS D7
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
3
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
Chip Select
D6
D5
D4
D3
D2
D1
D0
BitLine
25
JKE, PTSS
4 words x 8 bits 0
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
D7
D6
D5
D4
D3
D2
D1
D0
26
JKE, PTSS
Storage Hierarchies :
Computer data storage often called storage or memory, refers to computer components and recording media that retain digital data. Data storage is one of the core functions and fundamental components of computers.
JKE, PTSS
PRIMARY STORAGE
Primary storage (or main memory or internal memory), often referred to simply as memory, is the only one directly accessible to the CPU. The CPU continuously reads instructions stored there and executes them as required. Any data actively operated on is also stored there in uniform manner.
RAM:
Processor registers are located inside the processor. Each register typically holds a word of data (often 32 or 64 bits). CPU instructions instruct the arithmetic and logic unit to perform various calculations or other operations on this data (or with the help of it). Registers are the fastest of all forms of computer data storage.
Processor cache is an intermediate stage between ultra-fast registers and much slower main memory. It's introduced solely to increase performance of the computer. Most actively used information in the main memory is just duplicated in the cache memory, which is faster, but of much lesser capacity.
Main memory is directly or indirectly connected to the central processing unit via a memory bus. It is actually two buses ): an address bus and a data bus. The CPU firstly sends a number through an address bus, a number called memory address, that indicates the desired location of data. Then it reads or writes the data itself using the data bus.
JKE, PTSS
SECONDARY STORAGE
Secondary storage (also known as external memory or auxiliary storage), differs from primary storage in that it is not directly accessible by the CPU. The computer usually uses its input/output channels to access secondary storage and transfers the desired data using intermediate area in primary storage. Secondary storage does not lose the data when the device is powered downit is non-volatile. Example: Flash drive, CD and DVD drives, floppy disks, punch cards.
TERTIARY STORAGE
Tertiary storage or tertiary memory, provides a third level of storage. Typically it involves a robotic mechanism which will mount (insert) and dismount removable mass storage media into a storage device according to the system's demands; this data is often copied to secondary storage before use. Example: useful for extraordinarily large data stores, accessed without human operators(robotic arms). Typical examples include tape libraries and optical jukeboxes.
Off-line storage
Off-line storage is a computer data storage on a medium or a device that is not under the control of a processing unit. The medium is recorded, usually in a secondary or tertiary storage device, and then physically removed or disconnected. It must be inserted or connected by a human operator before a computer can access it again. Unlike tertiary storage, it cannot be accessed without human interaction. Example : Optical discs and flash memory devices
JKE, PTSS
Memory Hierarchy
30
JKE, PTSS
As you can see in the diagram above, the CPU accesses memory according to a distinct hierarchy. Whether it comes from permanent storage (the hard drive) or input (the keyboard), most data goes in random access memory (RAM) first. The CPU then stores pieces of data it will need to access, often in a cache, and maintains certain special instructions in the register. We'll talk about cache and registers later. All of the components in your computer, such as the CPU, the hard drive and the operating system, work together as a team, and memory is one of the most essential parts of this team. From the moment you turn your computer on until the time you shut it down, your CPU is constantly using memory
31
JKE, PTSS
JKE, PTSS
33
Introduction
Solves problem of limited memory space Creates the illusion that more memory exists than is available in system Two types of addresses in virtual memory systems
Virtual addresses Referenced by processes Physical addresses- Describes locations in main memory
JKE, PTSS
Virtual memory combines active RAM and inactive memory in disk form into a large range of contiguous addresses.
35
JKE, PTSS
JKE, PTSS
TWO common approaches of Virtual Memory Organization Two common approaches of Virtual Memory
Linear Virtual Memory Segmented Virtual Memory
37
JKE, PTSS
38
JKE, PTSS
Paging
Virtual memory is divided into fixed-size blocks called pages
typically a few kilobytes should be a natural unit of transfer to/from disk
Page replacement
LRU, MRU, Clock etc
Page placement
Fully associative - efficient
JKE, PTSS
Paging
Page Identification
Virtual address is divided into <virtual page number, page offset> The virtual page number is translated into a physical page number Provides indirection
Indirection is always good
JKE, PTSS
Segmentation
Supports user view of memory. Virtual memory is divided into variable length regions called segments Virtual address consists of a segment number and a segment offset
<segment-number, offset>
JKE, PTSS
Paging
Paging is memory management technique where memory divided into equal parts like 4k,4k,4k, etc. When Primary memory space is less than processor swap the virtual memory from Secondary memory that time if virtual memory configured into paging technique than only page will be swap as per requirement similarly if need more virtual space than similar space of 4k block will swap for the e.g.: -if there is need of 16kb data than 4pages will be swap like 4k,4k,4k,4k.
42
JKE, PTSS
Segmentation
Very few systems use the concept of segmentation for implementing virtual memory. In segmentation memory is divided in variable size segments. Segment number and an offset within the segment together form a virtual address. If a processor wants a particular data item it first looks up for its segment number in a segment table to find a segment descriptor. Segment descriptor gives information whether the offset within the segment is less than the length of the segment and if it isn't an interrupt is generated to notify that the segment is found. If the processor is unable to find the segment in the main memory it generates a hardware interrupt prompting the operating system to swap in the segment. The operating system then searches for the segments that were not in use for a long time and swaps them out of main memory in order to make space for the new segments to be read in.
43
JKE, PTSS
Paging:
Block replacement easy Fixed-length blocks
Segmentation:
Block replacement hard Variable-length blocks Need to find contiguous, variablesized, unused part of main memory
44
JKE, PTSS
Paging:
Invisible to application programmer No external fragmentation There is internal fragmentation Unused portion of page Units of code and data are broken up into separate pages
Segmentation:
Visible to application programmer No internal fragmentation Unused pieces of main memory There is external fragmentation Keeps blocks of code or data as single units
45
JKE, PTSS
Cache Memory
46
Cache- Introduction
Small amount of fast memory Sits between normal main memory and CPU May be located on CPU chip or module
47
JKE, PTSS
Is an intermediate buffer between CPU and main memory. Objective :- to reduce the CPU waiting time during the main memory accesses. Without cache memory, every main memory access results in delay in instruction processing. Due to main memory access time is higher than processor clock period. High speed CPUs time wasted during memory access (instruction fetch, operand fetch or result storing) To minimize the waiting time for the CPU, a small but fast memory is introduced as a cache buffer between main memory and CPU
48
JKE, PTSS
A portion of program and data is brought into the cache memory in advance. The cache controller keeps track of locations of the main memory which are copied In cache memory When CPU needs for instruction or operand, it receives from the cache memory (if available) instead of accessing the main memory. Thus the memory access is fast because the slow main memory appears as a fast memory. The cache memory capacity is very small compared to main memory but the speed is several times better than main memory. Transfer between the CPU and cache memory usually one word at a time. The cache memory usually can be physically with processor IC as internal cache, also known as on-chip cache.
49
JKE, PTSS
Cache consists of C-lines. Each line contains K words and a tag of a few bits. The number of words in the line referred as line size. Tag- a portion of main memory address. Each line includes a tag identifies which particular block is currently being stored.
50
JKE, PTSS
51
JKE, PTSS
52
JKE, PTSS
ii) How many bits are used to select the line in the cache that may contain the data.
JKE, PTSS
54
Direct mapping
Each block of main memory maps to only one cache line i.e. if a block is in cache, it must be in one specific place Address is in two parts Least Significant w bits identify unique word Most Significant s bits specify one memory block The MSBs are split into a cache line field r and a tag of s-r (most significant)
55
JKE, PTSS
EXAMPLE : TAG=8, LINE = 14, WORD=2 24 bit address 2 bit word identifier (4 byte block) 22 bit block identifier 8 bit tag (=22-14) 14 bit slot or line No two blocks in the same line have the same Tag field Check contents of cache by finding line and checking Tag
56
JKE, PTSS
JKE, PTSS
57
JKE, PTSS
58
Direct Mapping
Example
JKE, PTSS
59
Decoder
60
Decoder
A decoder is a device which does the reverse of an encoder, undoing the encoding so that the original information can be retrieved.
JKE, PTSS
Determine the digital circuit in a tree-type decoding network with 16 output lines
The first stage is a 2-to-4-line decoder. A new variable is introduced in each successive stage; it or
its inverse becomes one input to each of the two-input AND gates in this stage. The second input to each AND gate comes from the preceding stage. For example, one of the outputs of the second stage will be AB'C. This will result in two outputs from the next stage, AB'CD and AB'CD'. This design does avoid the fan-out problem in the early stages but not in the later stages. Nevertheless, the problem exists only for the variables introduced in those stages.
JKE, PTSS
JKE, PTSS
JKE, PTSS
65
a) Data bus -Carry information b) Address bus- Determine where it should be sent c) Control bus - Determine its operation
JKE, PTSS
JKE, PTSS
Read cycle
JKE, PTSS
JKE, PTSS
70
JKE, PTSS
JKE, PTSS
When you save a file and close the application, the file is written to the specified storage device, and then it and the application are purged from RAM. In the list above, every time something is loaded or opened, it is placed into RAM. This simply means that it has been put in the computer's temporary storage area so that the CPU can access that information more easily. The CPU requests the data it needs from RAM, processes it and writes new data back to RAM in a continuous cycle. In most computers, this shuffling of data between the CPU and RAM happens millions of times every second. When an application is closed, it and any accompanying files are usually purged (deleted) from RAM to make room for new data. If the changed files are not saved to a permanent storage device before being purged, they are lost.
72
JKE, PTSS
73
JKE, PTSS
Write operation
Put the new value on Bitline and its inverse on ~Bitline Then set the Wordline to high
Wordline (WL)
BitLine
Modified from Prof Sean Lees Slide, Georgia Tech
BitLine
74
JKE, PTSS
Read operation
Precharge bitline to Vdd (1) Assert WL to 1
Wordline (WL)
Bitline
Modified from Prof Sean Lees Slide, Georgia Tech
75
JKE, PTSS
Memory Description
Capacity of a memory is described as
# addresses x Word size
Examples:
Memory 1M x 8 2M x 4 1K x 4 4M x 32 16K x 64 # of addr 1,048,576 2,097,152 1024 4,194,304 16,384 # of data lines 8 4 4 32 64 # of addr lines 20 21 10 22 14 # of total bytes 1 MB 1 MB 512 B 16 MB 128 KB
76
JKE, PTSS
Example
77
JKE, PTSS
8 words x 4 bits
0
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
A1
1
Row Decoder 2
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
A2
CS
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
3
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
Chip Select
CS
D1 D2 D3
A0
Modified from Prof Sean Lees Slide, Georgia Tech
78
JKE, PTSS
Read Operation
2-to-4 8 words x 4 bits 0
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
A1
Row Decoder 2 3 CS
1
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
A2
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
Rd/Wr = 0
D0 D1 D2 D3
Chip Select
CS
A0 = 0
Modified from Prof Sean Lees Slide, Georgia Tech
79
JKE, PTSS
Write Operation
2-to-4 A1 8 words x 4 bits 0
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
Row Decoder 2 3 CS
1
1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit 1-bit
A2
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
1-bit
Rd/Wr = 1
D0 D1 D2 D3
Chip Select
CS
A0 = 1
Prof. Sean Lees Slide, Georgia Tech
80
JKE, PTSS
CS
D3 D2 D1 R/W D0
CS
A0
A0
CS
81
JKE, PTSS
D2
D1 D0
CS
R/W
CS
1Mx4
A0
Prof. Sean Lees Slide, Georgia Tech
CS
R/W
82
JKE, PTSS
D7
1Mx4 CS R/W
D6 D5 D4 D3 D2 D1
R/W
A0
A20 1-to-2 Decoder
1 0
1Mx4 CS
A0
D0
CS
1Mx4 CS R/W
1Mx4
A0
83
CS
R/W
JKE, PTSS
84
JKE, PTSS
If the transistor is present, it pulls the bitline LOW If the transistor is not present, the bitline remanins HIGH
32 X 8 ROM
To read the cell, the bitline is weakly pulled HIGH. Then, the wordline is turned ON
A4
A3
A2 A1
5-to-32
Decoder
0 1 2 3
A0
28 29 30 31
D7
D6
D5
D4
D3
85
D2
D1
D0
JKE, PTSS
A4
A3
A2 A1 A0
5-to-32 Decoder
0 1 2
29 30 31
D7
D6
D5
D4 86
D3
D2
D1
D0
JKE, PTSS
Flash memory
Read and Writable Non-volatile
Power off does not erase information stored
Flash memory has become extremely popular to store large amounts of data in portable systems such as cameras and music players
87
JKE, PTSS
The End
88
JKE, PTSS