Professional Documents
Culture Documents
Overview
Memory Hierarchy
Main Memory
Auxiliary Memory
Associative Memory
Cache Memory
Virtual Memory
Lecture 40
Memory Organization
Lecture 40
Memory Hierarchy
Memory Hierarchy is to obtain the highest possible access
speed while minimizing the total cost of the memory
system
Magnetic
tapes
Magnetic
disks
I/O
processor
Main
memory
CPU
Cache
memory
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Memory Organization
Lecture 40
Main Memory
RAM and ROM Chips
Typical RAM chip
Chip select 1
Chip select 2
Read
Write
7-bit address
CS1 CS2
0
0
0
1
1
0
1
0
1
0
1
1
CS1
CS2
RD
WR
AD 7
RD
x
x
0
0
1
x
128 x 8
RAM
WR Memory function
Inhibit
x
Inhibit
x
Inhibit
0
Write
1
Read
x
Inhibit
x
9-bit address
CS1
CS2
AD 9
512 x 8
ROM
Memory Organization
Lecture 40
1
2
3
4
Hexa
address10
0000
0080
0100
0180
0200
007F
0
0
00FF
0
017F
0
01FF
1
03FF
Address bus
9
0
0
1
1
x
0
1
0
1
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
Memory Organization
Lecture 40
CS1
CS2
RD 128 x 8
RAM 2
WR
AD7
CS1
CS2
RD 128 x 8
RAM 3
WR
AD7
CS1
CS2
RD 128 x 8
RAM 4
WR
AD7
1- 7
8
9
CS1
CS2
512 x 8
AD9 ROM
Data
CS1
CS2
RD 128 x 8
RAM 1
WR
AD7
Data
Decoder
3 2 1 0
Data bus
Data
RD WR
Data
7-1
Data
Address bus
16-11 10 9 8
Memory Organization
Lecture 41
Auxiliary Memory
Information Organization on Magnetic Tapes
file i
block 1
R1
block 2
block 3
R2
R3
R4
EOF
R5
R6
block 3 IRG
R1
EOF
R5
R4
R3 R2
block 1
block 2
Track
Memory Organization
Lecture 41
Associative Memory
- Accessed by the content of the data rather than by
an address
- Also called Content Addressable Memory (CAM)
Hardware
Argument register(A)
Organization
Key register (K)
Match
register
Input
Read
Write
Associative memory
array and logic
m words
n bits per word
Memory Organization
Lecture 41
Organization of CAM
i= word
j-= bit in word
A1
Aj
K1
Kj
Kn
Word 1
C11
C1j
C1n
M1
Word i
Ci1
Cij
Cin
Mi
Word m
Cm1
Cmj
Cmn
Mm
Bit 1
Bit j
Bit n
An
Aj
Input
Kj
Write
R
Read
Output
F ij
Match
logic
To Mi
Memory Organization
Lecture 41
Match Logic
K1
F'i1
A1
F i1
K2
F'i2
A2
F i2
Kn
. . . . F'in
An
Fin
Mi
Memory Organization
10
Lecture 42
Cache Memory
Locality of Reference
- The references to memory at any given time interval tend to be confined
within a localized areas
- This area contains a set of information and the membership changes
gradually as time goes by
- Temporal Locality
The information which will be used in near future is likely to be in use
already( e.g. Reuse of information in loops)
- Spatial Locality
If a word is accessed, adjacent(near) words are likely accessed soon
(e.g. Related data items (arrays) are usually stored together;
instructions are executed sequentially)
Cache
- The property of Locality of Reference makes the cache memory systems work
- Cache is a fast small capacity memory that should hold those information
which are most likely to be accessed
Main memory
Cache memory
CPU
Memory Organization
11
Lecture 42
Performance of Cache
Memory
Access
All the memory accesses are directed first to Cache
If the word is in Cache; Access cache to provide it to CPU
If the word is not in Cache; Bring a block (or a line)
including
that word to replace a block now in Cache
- How can we know if the word that is required is there ?
- If a new block is to replace one of the old blocks, which
one should we choose ?
Performance of Cache Memory System
Hit Ratio - % of memory accesses satisfied by Cache
memory system
Te: Effective memory access time in Cache memory
system
Tc: Cache access time
Tm: Main memory access time
Te = Tc + (1 - h) Tm
Example: Tc = 0.4 s, Tm = 1.2s, h = 0.85%
Memory Organization
12
Lecture 42
Mapping Function
Specification of correspondence between main memory blocks
and cache blocks
Associative mapping
Direct mapping
Set-associative mapping
Associative Mapping
- Any block location in Cache can store any block in memory
-> Most flexible
- Mapping Table is implemented in an associative memory
-> Fast, very Expensive
- Mapping Table
Stores both address and the content of the memory word
address (15 bits)
Argument register
CAM
Address
Data
01000
02777
22235
3450
6710
1234
Memory Organization
13
Lecture 42
000
32K x 12
Main memory
2340
3450
01777
02000
4560
5670
02777
6710
77
Address = 15 bits
Data = 12 bits
777
Cache memory
Index
address
000
777
Tag
00
Data
1220
02
6710
000
512 x 12
Cache memory
Address = 9 bits
Data = 12 bits
777
Memory Organization
14
Lecture 42
01
01
3450
6578
Block 63 770
777
02
02
6710
Block 0
Block 1
Tag
Block
INDEX
Word
Memory Organization
15
Lecture 42
Index
Tag
Data
Tag
Data
000
01
3450
02
5670
777
02
6710
00
2340
Memory Organization
16
Lecture 42
Cache Write
Write Through
When writing into memory
parallel
Memory Organization
17
Lecture 43
Virtual Memory
Give the programmer the illusion that the system has a very large
memory, even though the computer actually has a relatively small
main memory
memory space
Mapping
physical address
ess Mapping
emory Mapping Table for Virtual Address -> Physical Address
Virtual address
Virtual
address
register
Memory
mapping
table
Memory table
buffer register
Main memory
address
register
Physical
Address
Main
memory
Main memory
buffer register
Memory Organization
18
Lecture 43
Address Mapping
Address Space and Memory Space are each divided into
fixed size group of words called blocks or pages
1K words group
Address space
N = 8K = 213
Page
Page
Page
Page
Page
Page
Page
Page
0
1
2
3
4
5
6
7
Virtual address
Presence
bit
000
001
010
011
100
101
110
111
11
00
01
10
01
0
1
1
0
0
1
1
0
1
0 10 1 0 1 0 1 0 0 1 1
Main memory
address register
Main memory
Block 0
Block 1
Block 2
Block 3
MBR
Memory Organization
19
Lecture 43
ssume that
Number of Blocks in memory = m
Number of Pages in Virtual Address Space = n
Page Table
- Straight forward design -> n entry table in memory
Inefficient storage space utilization
<- n-m entries of the table is empty
- More efficient method is m-entry Page Table
Page Table made of an Associative Memory
m words; (Page Number:Block
Number)
Virtual address
Page no.
1 0 1
Line number
Argument register
1 0 1
0 0Key register
0
0
1
1
1
0
0
1
0
1
0
1
1
0
1
0
1
0Associative memory
1
0
Page no.
Block no.
Page Fault
Page number cannot be found in the Page Table
Memory Organization
20
Lecture 43
Page Fault
p to the OS
OS
ve the user registers and program state
ermine that the interrupt was a page fault
2 trap
eck that the page reference was legal and
determine the location of the page on the
backing store(disk)
1Reference
LOAD M
ue a read from the backing store to a free
0
frame
6
restart
a. Wait in a queue for this device until serviced
instruction
b. Wait for the device seek and/or latency time
c. Begin the transfer of the page to a free frame
free frame
5
reset
ile waiting, the CPU may be allocated to
page
some other process
table
errupt from the backing store (I/O completed)
ve the registers and program state for the other user
main memory
ermine that the interrupt was from the backing store
orrect the page tables (the desired page is now in memory)
ait for the CPU to be allocated to this process again
estore the user registers, program state, and new page table, then
sume the interrupted instruction.
bring in
missing
page
Memory Organization
21
Lecture 43
Page Replacement
f 0
f
v i
v
page table
2change to
invalid
4
reset page
table for
new page
swap
out
victim
1
page
victim
3
swap
desired
page in
physical memory
backing store
Memory Organization
22
Lecture 43
Reference string
7
7
0
7
0
1
2
0
1
0
2
3
1
4
2
3
0
2
4
3
0
0
4
2
3
4
2
0
2
0
1
3
0
2
3
0
1
2
0
7
1
2
1
7
0
2
7
0
1
Page frames
algorithm selects the page that has been in memory the longest time
g a queue - every time a page is loaded, its
-identification is inserted in the queue
to implement
result in a frequent page fault
0
7
1
7
0
2
7
0
1
Page frames
0
2
0
1
0
2
0
3
2
2
4
3
3
2
0
3
2
2
0
1
0
7
0
1
Memory Organization
23
Lecture 43
7
0
7
0
1
2
0
1
0
2
0
3
2
4
0
3
3
4
0
2
0
4
3
2
3
0
3
2
2
1
3
2
Page frames
1
1
0
2
0
1
0
7