Memory
Memory
• Main Memory
• Auxiliary Memory
• Associative Memory
• Cache Memory
• Virtual Memory
CPU Cache
memory
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Main Memory
Decoder
3 2 1 0
CS1
CS2
Data
RD 128 x 8
RAM 1
WR
AD7
CS1
CS2
Data
RD 128 x 8
RAM 2
WR
AD7
CS1
CS2
Data
RD 128 x 8
RAM 3
WR
AD7
CS1
CS2
RD 128 x 8 Data
RAM 4
WR
AD7
CS1
CS2
Data
1- 7 512 x 8
8
9 } AD9 ROM
Auxiliary Memory
Track
Associative Memory
A1 Aj An
K1 Kj Kn
Write
R S
F ij Match To M i
Read logic
Output
Associative Memory
K1 A1 K2 A2 Kn An
Mi
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
Cache Memory
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
Te = Tc + (1 - h) Tm
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
Address Data
01000 3450
CAM 02777 6710
22235 1234
Cache Memory
00 000 32K x 12
000
512 x 12
Main memory Cache memory
Address = 15 bits Address = 9 bits
Data = 12 bits Data = 12 bits
77 777 777
01777 4560
02000 5670
777 02 6710
02777 6710
Cache Memory
Operation
Block 63 770 02
777 02 6710
Cache Memory
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)
Cache Memory
Modifications
Initially all U0 = U1 = 1
When Hit to (tag 0, data 0, U0), U1 <- 1(least recently used)
(When Hit to (tag 1, data 1, U1), U0 <- 1(least recently used))
When Miss, find the least recently used one(Ui=1)
If U0 = 1, and U1 = 0, then replace (tag 0, data 0)
M[tag 0, INDEX] <- Cache[INDEX](data 0)
Cache[INDEX](tag 0, data 0, U0) <- (TAG,M[TAG,INDEX], 0); U1 <- 1
If U0 = 0, and U1 = 1, then replace (tag 1, data 1)
Similar to above; U0 <- 1
If U0 = U1 = 0, this condition does not exist
If U0 = U1 = 1, Both of them are candidates,
Take arbitrary selection
Cache Memory
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 is always updated
-> Important when CPU and DMA I/O are both executing
Slow, due to the memory access time
Write-Back (Copy-Back)
When writing into memory
If Hit, only Cache is written
If Miss, missing block is brought to Cache and write into Cache
For a read miss, candidate block must be
written back to the memory
Memory is not up-to-date, i.e., the same item in
Cache and memory may have different value
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 Mapping
Memory Mapping Table for Virtual Address -> Physical Address
Virtual address
Physical
Address
Memory table Main memory
buffer register buffer register
Virtual Memory
Table Presence
address bit
000 0 Main memory
001 11 1 Block 0
010 00 1 Block 1
011 0 01 0101010011 Block 2
100 0 Block 3
Main memory
101 01 1 address register
Memory page table 110 10 1
111 0 MBR
01 1
Virtual Memory
Assume 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
1 0 1 0 0 Key register
0 0 1 1 1
0 1 0 0 0 Associative memory
1 0 1 0 1
1 1 0 1 0
Page no.Block no.
Page Fault
Page number cannot be found in the Page Table
Virtual Memory
physical memory
Virtual Memory
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
Replace that page which will not be used for the longest period of time
Reference string
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2 2 2 7
0 0 0 0 4 0 0 0
1 1 3 3 3 1 1
Page frames
Virtual Memory
LRU
- OPT is difficult to implement since it requires future knowledge
- LRU uses the recent past as an approximation of near future.
Reference string
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 4 4 4 0 1 1 1
0 0 0 0 0 0 3 3 3 0 0
1 1 3 3 2 2 2 2 2 7
Page frames
2 7
1 2
0 1
7 0
LRU Approximation 4 4
Basic Functions of MM
- Dynamic Storage Relocation - mapping logical
memory references to physical memory references
- Provision for Sharing common information stored
in memory by different users
- Protection of information against unauthorized access
Segmentation
- A segment is a set of logically related instructions
or data elements associated with a given name
- Variable size
User's view of memory
The user does not think of
Stack memory as a linear array
Subroutine of words. Rather the user
Symbol prefers to view memory as
Table
a collection of variable
SQRT
Main sized segments, with no
Program
necessary ordering among
segments.
User's view of a program
Memory Management Hardware
limit base
CPU (s,d)
Memory
y
< +
n
error
Memory Management Hardware
1400
Subroutine Stack Segment 0
Segment 3
Segment 0 2400
Symbol
Table 3200
Segment 1 Main
Program 4300
Segment 2
Segment 2 4700
Segment 4
Logical Address Space
5700
6300
Segment 1
Segment Table 6700
limit base
0 1000 1400
1 400 6300
2 400 4300
3 1100 3200
4 1000 4700
Memory Management Hardware
Editor
limit base 43062
0 25286 43062
Segment 0 1 4425 68348 Editor
Data 1 Segment Table
(User 1) 68348
Segment 1 Data 1
72773
Logical Memory
(User 1)
90003
Data 2
98556
limit base
Editor
0 25286 43062
1 8550 90003 Physical Memory
Segment 0
Segment Table
Data 2 (User 2)
Segment 1
Logical Memory
(User 2)
Memory Management Hardware
Logical address
Block Word
Physical address
Memory Management Hardware
20
2 x 32
Physical Physical address format: 4096 blocks of 256 words
memory each, each word has 32bits
12 8
Block Word
Hash
Function Real Address Data
TLB
Cache
S S
Cache Entry
Cache Set
Receive Virtual Address
Read Out
Page number Byte within page
Byte within line
31 21 20 17 12 11 10 4 3 2 1 0
Byte within
Select set Select set word
in TLB in cache
Map through Word within
page directory Map through
page table Line number line