MEMORY ORGANIZATION
Memory Hierarchy
Main Memory
Auxiliary Memory
Associative Memory
Cache Memory
Virtual Memory
Memory Management Hardware
Computer Organization
Memory Organization
Memory Hierarchy
MEMORY HIERARCHY
Memory Hierarchy is to obtain the highest possible
access speed while minimizing the total cost of the memory system
Auxiliary memory
Magnetic
tapes
I/O
processor
Main
memory
CPU
Cache
memory
Magnetic
disks
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Computer Organization
Memory Organization
Main Memory
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
WR
x
x
0
1
x
x
128 x 8
RAM
Memory function
Inhibit
Inhibit
Inhibit
Write
Read
Inhibit
CS1
CS2
512 x 8
ROM
9-bit address
Computer Organization
AD 9
Memory Organization
Main Memory
1
2
3
4
Hexa
address
0000 - 007F
0080 - 00FF
0100 - 017F
0180 - 01FF
0200 - 03FF
Address bus
10 9
0
0
0
0
1
0
0
1
1
x
8 7 6 5
4 3 2 1
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
Main Memory
CPU
7-1
RD WR
Data bus
CS1
CS2
RD 128 x 8
RAM 4
WR
AD7
1- 7
8
9
Computer Organization
CS1
CS2
512 x 8
AD9 ROM
Data
Data
CS1
CS2
RD 128 x 8
RAM 3
WR
AD7
Data
CS1
CS2
RD 128 x 8
RAM 2
WR
AD7
Data
CS1
CS2
RD 128 x 8
RAM 1
WR
AD7
Data
Decoder
3 2 1 0
Memory Organization
Auxiliary Memory
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
Computer Organization
Memory Organization
Associative Memory
ASSOCIATIVE MEMORY
- Accessed by the content of the data rather than by an address
- Also called Content Addressable Memory (CAM)
Hardware Organization
Argument register(A)
Match
register
Input
Associative memory
array and logic
M
Read
Write
m words
n bits per word
Memory Organization
Associative Memory
ORGANIZATION OF CAM
A1
Aj
An
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
Aj
Input
Kj
Write
S
F ij
Read
Match
logic
To M i
Output
Computer Organization
Memory Organization
Associative Memory
MATCH LOGIC
K1
A1
F'i1
F i1
K2
A2
F'i2
F i2
Kn
....
F'in
An
F in
Mi
Computer Organization
Memory Organization
10
Cache Memory
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
CPU
Cache memory
Computer Organization
Memory Organization
11
Cache Memory
PERFORMANCE OF CACHE
Memory Access
Memory Organization
12
Cache Memory
Argument register
CAM
Computer Organization
Address
Data
01000
02777
22235
3450
6710
1234
Memory Organization
13
Cache Memory
MEMORY AND CACHE MAPPING - DIRECT MAPPING - Each memory block has only one place to load in Cache
- Mapping Table is made of RAM instead of CAM
- n-bit memory address consists of 2 parts; k bits of Index field and
n-k bits of Tag field
- n-bit addresses are used to access main memory
and k-bit Index is used to access the Cache
Addressing Relationships
Tag(6)
Index(9)
00 000
32K x 12
000
Main memory
Address = 15 bits
Data = 12 bits
777
77 777
512 x 12
Cache memory
Address = 9 bits
Data = 12 bits
Memory data
1220
00777
01000
2340
3450
01777
02000
4560
5670
02777
6710
Computer Organization
Index
address
000
777
Cache memory
Tag
00
Data
1220
02
6710
Memory Organization
14
Cache Memory
DIRECT MAPPING
Operation
- CPU generates a memory request with (TAG;INDEX)
- Access Cache using INDEX ; (tag; data)
Compare TAG and tag
- If matches -> Hit
Provide Cache[INDEX](data) to CPU
- If not match -> Miss
M[tag;INDEX] <- Cache[INDEX](data)
Cache[INDEX] <- (TAG;M[TAG; INDEX])
CPU <- Cache[INDEX](data)
tag
000
007
010
017
01
01
Block 63 770
777
02
02
Block 0
Block 1
Computer Organization
data
3450
6578
6
Tag
6
Block
3
Word
INDEX
6710
Memory Organization
15
Cache Memory
MEMORY AND CACHE MAPPING - SET ASSOCIATIVE MAPPING - Each memory block has a set of locations in the Cache to load
Set Associative Mapping Cache with set size of two
Index
Tag
Data
Tag
Data
000
01
3450
02
5670
777
02
6710
00
2340
Operation
- CPU generates a memory address(TAG; INDEX)
- Access Cache with INDEX, (Cache word = (tag 0, data 0); (tag 1, data 1))
- Compare TAG and tag 0 and then tag 1
- If tag i = TAG -> Hit, CPU <- data i
- If tag i TAG -> Miss,
Replace either (tag 0, data 0) or (tag 1, data 1),
Assume (tag 0, data 0) is selected for replacement,
(Why (tag 0, data 0) instead of (tag 1, data 1) ?)
M[tag 0, INDEX] <- Cache[INDEX](data 0)
Cache[INDEX](tag 0, data 0) <- (TAG, M[TAG,INDEX]),
CPU <- Cache[INDEX](data 0)
Computer Organization
Memory Organization
16
Cache Memory
Memory Organization
17
Cache Memory
CACHE WRITE
Write Through
When writing into memory
If Hit, both Cache and memory is written in parallel
If Miss, Memory is written
For a read miss, missing block may be
overloaded onto a cache block
Memory Organization
18
Virtual Memory
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
Address Space(Logical) and Memory Space(Physical)
address space
virtual address
(logical address)
memory space
Mapping
physical address
actual main memory address
Address Mapping
Memory Mapping Table for Virtual Address -> Physical Address
Virtual address
Virtual
address
register
Memory
mapping
table
Main memory
address
register
Main
memory
Physical
Address
Memory table
buffer register
Computer Organization
Main memory
buffer register
Memory Organization
19
Virtual Memory
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 0
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Memory space
M = 4K = 212
Block 0
Block 1
Block 2
Block 3
Virtual address
Presence
bit
000
001
010
011
100
101
110
111
11
00
01
10
01
Computer Organization
Line number
0 1 0 1 0 1 0 0 1 1
0
1
1
0
0
1
1
0
01
0101010011
Main memory
address register
Main memory
Block 0
Block 1
Block 2
Block 3
MBR
Memory Organization
20
Virtual Memory
Line number
Argument register
1 0 1
0 0
Key register
0
0
1
1
1
0
0
1
Associative memory
0
1
0
1
1
0
1
0
1
0
1
0
Page Fault
Page number cannot be found in the Page Table
Computer Organization
Memory Organization
21
Virtual Memory
PAGE FAULT
1. Trap to the OS
trap
OS
Reference
LOAD M
0
frame
a. Wait in a queue for this device until serviced
restart
instruction
free frame
reset
page
table
bring in
missing
page
main memory
Computer Organization
Memory Organization
22
Virtual Memory
PAGE REPLACEMENT
Decision on which page to displace to make room for
an incoming page when no free frame is available
Modified page fault service routine
1. Find the location of the desired page on the backing store
2. Find a free frame
- If there is a free frame, use it
- Otherwise, use a page-replacement algorithm to select a victim frame
- Write the victim page to the backing store
3. Read the desired page into the (newly) free frame
4. Restart the user process
valid/
frame invalid bit
2 change to
f 0 v i
invalid
4
v
f
reset page
table for
new page
page table
swap
out
1 victim
page
victim
3
swap
desired
page in
backing store
physical memory
Computer Organization
Memory Organization
23
Virtual Memory
Reference string
7
7
0
2
0
1
7
0
1
2
3
1
2
3
0
4
3
0
4
2
3
4
2
0
0
1
3
0
2
3
0
1
2
7
1
2
7
0
2
7
0
1
Page frames
FIFO algorithm selects the page that has been in memory the longest time
Using a queue - every time a page is loaded, its
identification is inserted in the queue
Easy to implement
May result in a frequent page fault
Optimal Replacement (OPT) - Lowest page fault rate of all algorithms
Replace that page which will not be used for the longest period of time
Reference string
7
0
7
1
7
0
2
7
0
1
0
2
0
1
0
2
0
3
2
2
4
3
2
0
3
2
2
0
1
7
0
1
Page frames
Computer Organization
Memory Organization
24
Virtual Memory
7
0
7
0
1
0
2
0
1
0
2
0
3
2
4
0
3
3
4
0
2
0
4
3
2
0
3
2
2
1
3
2
1
0
2
1
0
7
Page frames
Computer Organization
Memory Organization
25
Virtual Memory
2
1
0
7
4
7
2
1
0
4
LRU Approximation
- Reference (or use) bit is used to approximate the LRU
- Turned on when the corresponding page is
referenced after its initial loading
- Additional reference bits may be used
Computer Organization
Memory Organization
26
Main
Program
Memory Organization
27
SEGMENTATION
- A memory management scheme which supports
user's view of memory
- A logical address space is a collection of segments
- Each segment has a name and a length
- Address specify both the segment name and the
offset within the segment.
- For simplicity of implementations, segments are numbered.
Segmentation Hardware
Segment Table
s
limit
CPU
base
(s,d)
Memory
<
n
error
Computer Organization
Memory Organization
28
SEGMENTATION EXAMPLE
Subroutine
Stack
Segment 3
1400
Segment 0
2400
Segment 0
Symbol
Table
SQRT
Segment 1
Segment 4
Main
Program
3200
Segment 3
Segment 2
Segment 2
Logical Address Space
4300
4700
Segment 4
5700
Segment 1
Segment Table
limit base
0 1000 1400
1 400 6300
2 400 4300
3 1100 3200
4 1000 4700
Computer Organization
6300
6700
Memory Organization
29
SHARING OF SEGMENTS
Editor
limit
Segment 0
Data 1
base
0 25286 43062
1 4425 68348
43062
Editor
Segment Table
(User 1)
Data 1
Segment 1
68348
72773
Logical Memory
(User 1)
90003
Data 2
98556
Editor
Segment 0
Data 2
limit base
0 25286 43062
1 8550 90003
Physical Memory
Segment Table
(User 2)
Segment 1
Logical Memory
(User 2)
Computer Organization
Memory Organization
30
Page
Segment table
Word
Page table
Block
Word
Physical address
Computer Organization
Memory Organization
31
Computer Organization
Memory Organization
32
EXAMPLE
Logical and Physical Addresses
Logical address format: 16 segments of 256 pages
each, each page has 256words
4
8
Page
Segment
8
Word
20
2 x 32
Physical
memory
8
Word
Page number
60000
Page 0
60100
Page 1
60200
Page 2
60300
60400
604FF
Page 3
Page
00
01
02
03
04
Block
012
000
019
053
A61
Page 4
Computer Organization
Segment
6
6
6
6
6
Memory Organization
33
02
Segment table
Page table
00
7E
Physical memory
00000
000FF
35
35
36
37
38
39
A3
A3
012
000
019
053
A61
012
Block 0
01200
012FF
01900
0197E
019FF
Block 12
32-bit word
Computer Organization
Page
02
04
Block
019
A61
Memory Organization
34
MEMORY PROTECTION
Protection information can be included in the
segment table or segment register of the memory
management hardware
Length
Protection
- Access Rights:
Computer Organization
Memory Organization
35
CPU
Virtual Address
Page
Line
Word in
Number
Number
Line
To translator
A
CPU Memory
Hash
Function
TLB
Cache
A
Real
Compare Virtual
Address
Addresses
Compare Addresses
& Select Data
Data
S = Select
Computer Organization
Data Out
Computer Architectures Lab
Memory Organization
36
Data
Valid
Cache Entry
Entry 1
Entry 2
Entry E
Replacement status
Cache Set
Computer Organization
Memory Organization
37
In TLB ?
yes
Compare Addresses
no
Send Virtual Address
to Translator
yes
Update Replacement
Status in TLB
Update Replacement
Status
Select
Correct
Line
Match ?
no
Send Real Address
to Main Memory
Receive Line from
Main Memory
Store Line
in Cache
Put in TLB
Select Correct
Word from Line
Read Out
Computer Organization
Memory Organization
38
31
21
Map through
page directory
20
17
12
Select set
in TLB
Map through
page table
11
10
Select set
in cache
Line number
Byte within
word
Word within
line