SlideShare a Scribd company logo
1
Memory Organization
Computer Organization Computer Architectures Lab
• Memory Hierarchy
• Main Memory
• Auxiliary Memory
• Associative Memory
• Cache Memory
• Virtual Memory
• Memory Management Hardware
MEMORY ORGANIZATION
2
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY HIERARCHY
Magnetic
tapes
Magnetic
disks
I/O
processor
CPU
Main
memory
Cache
memory
Auxiliary memory
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Memory Hierarchy is to obtain the highest possible
access speed while minimizing the total cost of the memory system
Memory Hierarchy
3
Memory Organization
Computer Organization Computer Architectures Lab
MAIN MEMORY
RAM and ROM Chips
Typical RAM chip
Typical ROM chip
Chip select 1
Chip select 2
Read
Write
7-bit address
CS1
CS2
RD
WR
AD 7
128 x 8
RAM
8-bit data bus
CS1 CS2 RD WR
0 0 x x
0 1 x x
1 0 0 0
1 0 0 1
1 0 1 x
1 1 x x
Memory function
Inhibit
Inhibit
Inhibit
Write
Read
Inhibit
State of data bus
High-impedence
High-impedence
High-impedence
Input data to RAM
Output data from RAM
High-impedence
Chip select 1
Chip select 2
9-bit address
CS1
CS2
AD 9
512 x 8
ROM
8-bit data bus
Main Memory
4
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY ADDRESS MAP
RAM 1
RAM 2
RAM 3
RAM 4
ROM
0000 - 007F
0080 - 00FF
0100 - 017F
0180 - 01FF
0200 - 03FF
Component
Hexa
address
0 0 0 x x x x x x x
0 0 1 x x x x x x x
0 1 0 x x x x x x x
0 1 1 x x x x x x x
1 x x x x x x x x x
10 9 8 7 6 5 4 3 2 1
Address bus
Memory Connection to CPU
- RAM and ROM chips are connected to a CPU
through the data and address buses
- The low-order lines in the address bus select
the byte within the chips and other lines in the
address bus select a particular chip through
its chip select inputs
Address space assignment to each memory chip
Example: 512 bytes RAM and 512 bytes ROM
Main Memory
5
Memory Organization
Computer Organization Computer Architectures Lab
CONNECTION OF MEMORY TO CPU
Main Memory
}
CS1
CS2
RD
WR
AD7
128 x 8
RAM 1
CS1
CS2
RD
WR
AD7
128 x 8
RAM 2
CS1
CS2
RD
WR
AD7
128 x 8
RAM 3
CS1
CS2
RD
WR
AD7
128 x 8
RAM 4
Decoder
3 2 1 0
WR
RD
9 8 7-1
10
16-11
Address bus
Data bus
CPU
CS1
CS2
512 x 8
ROM
AD9
1- 7
9
8
Data
Data
Data
Data
Data
6
Memory Organization
Computer Organization Computer Architectures Lab
• Random Access Memory (RAM) is used to store the
programs and data being used by the CPU in real time.
The data on the random access memory can be read,
written, and erased any number of times. RAM is the
hardware element where the data being currently used is
stored. It is a volatile memory.
• Types of RAM:
– Static RAM, or (SRAM) which stores a bit of data using the state of a six
transistor memory cell.
– Dynamic RAM, or (DRAM) which stores a bit data using a pair of
transistor and capacitor which constitute a DRAM memory cell.
7
Memory Organization
Computer Organization Computer Architectures Lab
• Read Only Memory (ROM) is a type of memory where the
data has been prerecorded. Data stored in ROM is
retained even after the computer is turned off ie, non-
volatile.
• Types of ROM:
– Programmable ROM, where the data is written after the memory chip has
been created. It is non-volatile.
– Erasable Programmable ROM, where the data on this non-volatile
memory chip can be erased by exposing it to high-intensity UV light.
– Electrically Erasable Programmable ROM, where the data on this non-
volatile memory chip can be electrically erased using field electron
emission.
– Mask ROM, in which the data is written during the manufacturing of the
memory chip.
8
Memory Organization
Computer Organization Computer Architectures Lab
Difference RAM ROM
Data retention
RAM is a volatile memory which could
store the data as long as the power is
supplied.
ROM is a non-volatile memory which
could retain the data even when power
is turned off.
Working type
Data stored in RAM can be retrieved
and altered.
Data stored in ROM can only be read.
Use
Used to store the data that has to be
currently processed by CPU
temporarily.
It stores the instructions required
during bootstrap of the computer.
Speed It is a high-speed memory. It is much slower than the RAM.
CPU Interaction
The CPU can access the data stored
on it.
The CPU can not access the data
stored on it unless the data is stored in
RAM.
Size and Capacity Large size with higher capacity. Small size with less capacity.
Used as/in CPU Cache, Primary memory. Firmware, Micro-controllers
Accessibility The data stored is easily accessible
The data stored is not as easily
accessible as in RAM
Cost Costlier cheaper than RAM.
9
Memory Organization
Computer Organization Computer Architectures Lab
10
Memory Organization
Computer Organization Computer Architectures Lab
• How many 32K x 1 RAM chips are needed to
provide a memory capacity of 256K-bytes?
(A) 8
(B) 32
(C) 64
(D) 128
11
Memory Organization
Computer Organization Computer Architectures Lab
• Answer: (C)
Explanation:
• We need 256 Kbytes, i.e., 256 x 1024 x 8 bits.
We have RAM chips of capacity 32 Kbits = 32 x
1024 bits.
•
(256 * 1024 * 8)/(32 * 1024) = 64
12
Memory Organization
Computer Organization Computer Architectures Lab
• Number of chips (128 x 8 RAM) needed to provide
a memory capacity of 2048 bytes
(A) 2
(B) 4
(C) 8
(D) 16
13
Memory Organization
Computer Organization Computer Architectures Lab
Explanation:
chips (128 x 8 RAM) needed to provide a memory of 2048 B = 2048
x 8 / 128 x 8 = 16 x 1
14
Memory Organization
Computer Organization Computer Architectures Lab
15
Memory Organization
Computer Organization Computer Architectures Lab
RAM 2048 /256 = 8 chips; 2048 = 211; 256 = 28
• ROM 4096 /1024 = 4 chips; 4096 = 212; 1024 = 210
• Interface 4 × 4 = 16 registers; 16 = 24
• Component Address 16 15 14 13 12 11 10 19 8765
4321
• RAM 0000-O7FF 0 0 0 0 0 3 8
• decoder
• × ←⎯⎯→ ×××× ××××
• ROM 4000-4FFF 0 1 0 0 2 4
• decoder
• × ←⎯⎯→ ×× ×××× ××××
• Interface 8000-800F 1 0 0 0 0 0 0 0 0000 ××××
16
Memory Organization
Computer Organization Computer Architectures Lab
17
Memory Organization
Computer Organization Computer Architectures Lab
(a) 8 chips are needed with address lines connected in
parallel.
(b) 16 × 8 = 128 chips. Use 14 address lines (16 k = 214)
10 lines specify the chip address
4 lines are decoded into 16 chip-select inputs.
18
Memory Organization
Computer Organization Computer Architectures Lab
A RAM chip has a capacity of 1024 words of 8 bits each (1K ×
8). The number of 2 × 4 decoders with enable line needed to
construct a 16K × 16 RAM from 1K × 8 RAM is
(A) 4
(B) 5
(C) 6
(D) 7
19
Memory Organization
Computer Organization Computer Architectures Lab
Answer: (B)
Explanation:
RAM chip size = 1k ×8[1024 words of 8 bits each]
RAM to construct =16k ×16
Number of chips required = (16k x 16)/ ( 1k x 8) = (16 x
2) [16 chips vertically with each having 2 chips
horizontally]
So to select one chip out of 16 vertical chips, we need 4
x 16 decoder.
Available decoder is 2 x 4 decoder
To be constructed is 4 x 16 decoder
Hence 4 + 1 = 5 decoders are required.
20
Memory Organization
Computer Organization Computer Architectures Lab
AUXILIARY MEMORY
Information Organization on Magnetic Tapes
EOF
IRG
block 1 block 2
block 3
block 1
block 2
block 3
R1
R2 R3 R4
R5
R6
R1
R3 R2
R5 R4
file i
EOF
Organization of Disk Hardware
Track
Moving Head Disk Fixed Head Disk
Auxiliary Memory
21
Memory Organization
Computer Organization Computer Architectures Lab
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)
Key register (K)
Associative memory
array and logic
m words
n bits per word
Match
register
Input
Read
Write
M
- Compare each word in CAM in parallel with the
content of A(Argument Register)
- If CAM Word[i] = A, M(i) = 1
- Read sequentially accessing CAM for CAM Word(i) for M(i) = 1
- K(Key Register) provides a mask for choosing a
particular field or key in the argument in A
(only those bits in the argument that have 1’s in
their corresponding position of K are compared)
Associative Memory
22
Memory Organization
Computer Organization Computer Architectures Lab
ORGANIZATION OF CAM
Internal organization of a typical cell Cij
C11
Word 1
Word i
Word m
Bit 1 Bit j Bit n
M1
Mi
Mm
Associative Memory
Aj
R S
Output
Match
logic
Input
Write
Read
Kj
Mi
To
F ij
A1
Aj An
K1
Kj Kn
C1j C1n
Ci1 Cij Cin
Cm1 Cmj Cmn
23
Memory Organization
Computer Organization Computer Architectures Lab
MATCH LOGIC
Associative Memory
F'i1 F i1
K1 A1
F'i2 F i2
K2 A2
F'in Fin
Kn An
. . . .
Mi
24
Memory Organization
Computer Organization Computer Architectures Lab
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
Cache Memory
Main memory
Cache memory
CPU
25
Memory Organization
Computer Organization Computer Architectures Lab
PERFORMANCE OF CACHE
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 ?
Memory Access
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.2s, h = 0.85%
Te = 0.4 + (1 - 0.85) * 1.2 = 0.58s
Cache Memory
26
Memory Organization
Computer Organization Computer Architectures Lab
• Assume that for a certain processor, a read
request takes 50 nanoseconds on a cache miss
and 5 nanoseconds on a cache hit. Suppose while
running a program, it was observed that 80% of the
processor’s read requests result in a cache hit.
The average read access time in nanoseconds
is____________.
(A) 10
(B) 12
(C) 13
(D) 14
27
Memory Organization
Computer Organization Computer Architectures Lab
• Answer: (D)
Explanation:
• The average read access time in nanoseconds
= 0.8 * 5 + 0.2*50
= 14
28
Memory Organization
Computer Organization Computer Architectures Lab
Consider a system with 2 level caches. Access times of Level 1
cache, Level 2 cache and main memory are 1 ns, 10ns, and 500 ns,
respectively. The hit rates of Level 1 and Level 2 caches are 0.8
and 0.9, respectively. What is the average access time of the
system ignoring the search time within the cache?
(A) 13.0 ns
(B) 12.8 ns
(C) 12.6 ns
(D) 12.4 ns
29
Memory Organization
Computer Organization Computer Architectures Lab
Answer: (C)
Explanation: First, the system will look in cache 1. If it is not
found in cache 1, then cache 2 and then further in main
memory (if not in cache 2 also).
The average access time would take into consideration success in
cache 1, failure in cache 1 but success in cache 2, failure in both
the caches and success in main memory.
Average access time = [H1*T1]+[(1-H1)*H2*T2]+[(1-H1)(1-H2)*Hm*Tm]
where,
H1 = Hit rate of level 1 cache = 0.8
T1 = Access time for level 1 cache = 1 ns
H2 = Hit rate of level 2 cache = 0.9
T2 = Access time for level 2 cache = 10 ns
Hm = Hit rate of Main Memory = 1
Tm = Access time for Main Memory = 500 ns
30
Memory Organization
Computer Organization Computer Architectures Lab
So, Average Access Time = ( 0.8 * 1 ) + ( 0.2 * 0.9 * 10 ) + (
0.2 * 0.1 * 1 * 500)
= 0.8 + 1.8 + 10
= 12.6 ns
Thus, C is the correct choice.
31
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY AND CACHE MAPPING - ASSOCIATIVE MAPPLING -
Associative mapping
Direct mapping
Set-associative mapping
Associative Mapping
Mapping Function
Specification of correspondence between main
memory blocks and cache blocks
- 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
0 1 0 0 0
0 2 7 7 7
2 2 2 3 5
3 4 5 0
6 7 1 0
1 2 3 4
CAM
Cache Memory
32
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY AND CACHE MAPPING - DIRECT MAPPING -
Addressing Relationships
Direct Mapping Cache Organization
Memory
address Memory data
00000 1 2 2 0
00777
01000
01777
02000
02777
2 3 4 0
3 4 5 0
4 5 6 0
5 6 7 0
6 7 1 0
Index
address Tag Data
000 0 0 1 2 2 0
0 2 6 7 1 0
777
Cache memory
Tag(6) Index(9)
32K x 12
Main memory
Address = 15 bits
Data = 12 bits
512 x 12
Cache memory
Address = 9 bits
Data = 12 bits
00 000
77 777
000
777
- 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
Cache Memory
33
Memory Organization
Computer Organization Computer Architectures Lab
DIRECT MAPPING
Direct Mapping with block size of 8 words
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)
Index tag data
000 0 1 3 4 5 0
007 0 1 6 5 7 8
010
017
770 0 2
777 0 2 6 7 1 0
Block 0
Block 1
Block 63
Tag Block Word
6 6 3
INDEX
Cache Memory
34
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY AND CACHE MAPPING - SET ASSOCIATIVE MAPPING -
Set Associative Mapping Cache with set size of two
- Each memory block has a set of locations in the Cache to load
Index Tag Data
000 0 1 3 4 5 0 0 2 5 6 7 0
Tag Data
777 0 2 6 7 1 0 0 0 2 3 4 0
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
35
Memory Organization
Computer Organization Computer Architectures Lab
BLOCK REPLACEMENT POLICY
Many different block replacement policies are available
LRU(Least Recently Used) is most easy to implement
Cache word = (tag 0, data 0, U0);(tag 1, data 1, U1), Ui = 0 or 1(binary)
Implementation of LRU in the Set Associative Mapping with set size = 2
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
36
Memory Organization
Computer Organization Computer Architectures Lab
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 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
Cache Memory
37
Memory Organization
Computer Organization Computer Architectures Lab
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 Mapping
Memory Mapping Table for Virtual Address -> Physical Address
virtual address
(logical address) physical address
address space memory space
address generated by programs actual main memory address
Mapping
Virtual address
Virtual
address
register
Memory
mapping
table
Memory table
buffer register
Main memory
address
register
Main
memory
Main memory
buffer register
Physical
Address
Virtual Memory
38
Memory Organization
Computer Organization Computer Architectures Lab
ADDRESS MAPPING
Organization of memory Mapping Table in a paged system
Address Space and Memory Space are each divided
into fixed size group of words called blocks or pages
1K words group Page 0
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Block 3
Block 2
Block 1
Block 0
Address space
N = 8K = 213
Memory space
M = 4K = 212
0
000
1
001
1
010
0
011
0
100
1
101
1
110
0
111
1
Block 0
Block 1
Block 2
Block 3
MBR
0 1 0 1 0 1 0 1 0 0 1 1
1 0 1 0 1 0 1 0 1 0 0 1 1
Table
address
Presence
bit
Page no. Line number
Virtual address
Main memory
address register
Memory page table
Main memory
11
00
01
10
01
Virtual Memory
39
Memory Organization
Computer Organization Computer Architectures Lab
ASSOCIATIVE MEMORY PAGE TABLE
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
- More efficient method is m-entry Page Table
Page Table made of an Associative Memory
m words; (Page Number:Block Number)
1 0 1 Line number
Page no.
Argument register
1 0 1 0 0
0 0 1 1 1
0 1 0 0 0
1 0 1 0 1
1 1 0 1 0
Key register
Associative memory
Page no.Block no.
Virtual address
Page Fault
Page number cannot be found in the Page Table
Virtual Memory
40
Memory Organization
Computer Organization Computer Architectures Lab
PAGE FAULT
Processor architecture should provide the ability
to restart any instruction after a page fault.
1. Trap to the OS
2. Save the user registers and program state
3. Determine that the interrupt was a page fault
4. Check that the page reference was legal and
determine the location of the page on the
backing store(disk)
5. Issue a read from the backing store to a free
frame
a. Wait in a queue for this device until serviced
b. Wait for the device seek and/or latency time
c. Begin the transfer of the page to a free frame
6. While waiting, the CPU may be allocated to
some other process
7. Interrupt from the backing store (I/O completed)
8. Save the registers and program state for the other user
9. Determine that the interrupt was from the backing store
10. Correct the page tables (the desired page is now in memory)
11. Wait for the CPU to be allocated to this process again
12. Restore the user registers, program state, and new page table, then
resume the interrupted instruction.
LOAD M
0
Reference
1
OS
trap
2
3 Page is on backing store
free frame
main memory
4
bring in
missing
page
5
reset
page
table
6
restart
instruction
Virtual Memory
41
Memory Organization
Computer Organization Computer Architectures Lab
PAGE REPLACEMENT
Modified page fault service routine
Decision on which page to displace to make room for
an incoming page when no free frame is available
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
2
f 0 v i
f v
frame
valid/
invalid bit
page table
change to
invalid
4
reset page
table for
new page
victim
1
swap
out
victim
page
3
swap
desired
page in
backing store
physical memory
Virtual Memory
42
Memory Organization
Computer Organization Computer Architectures Lab
PAGE REPLACEMENT ALGORITHMS
FIFO
0
7
1
7
2 0 3 0 4 2 3 0 3 2 1 2 0 1 7
7 0 1
0 0
7
1
2
0
1
2
3
1
2
3
0
4
3
0
4
2
0
4
2
3
0
2
3
0
1
3
0
1
2
7
1
2
7
0
2
7
0
1
Page frames
Reference string
-
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
0
7
1
7
2 0 3 0 4 2 3 0 3 2 1 2 0 1 7
7 0 1
0 0
7
1
2
0
1
2
0
3
2
4
3
2
0
3
2
0
1
7
0
1
Page frames
Reference string
Virtual Memory
43
Memory Organization
Computer Organization Computer Architectures Lab
PAGE REPLACEMENT ALGORITHMS
- OPT is difficult to implement since it requires future knowledge
- LRU uses the recent past as an approximation of near future.
Replace that page which has not been
used for the longest period of time
LRU
0
7
1
7
2 0 3 0 4 2 3 0 3 2 1 2 0 1 7
7 0 1
0 0
7
1
2
0
1
2
0
3
4
0
3
4
0
2
4
3
2
0
3
2
1
3
2
1
0
2
1
0
7
Page frames
Reference string
Virtual Memory
- LRU may require substantial hardware assistance
- The problem is to determine an order for the frames
defined by the time of last use
44
Memory Organization
Computer Organization Computer Architectures Lab
PAGE REPLACEMENT ALGORITHMS
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
Virtual Memory
4 7 0 7 1 0 1 2 1 2 7 1 2
Reference string
2
1
0
7
4
7
2
1
0
4
LRU Implementation Methods
• Counters
- For each page table entry - time-of-use register
- Incremented for every memory reference
- Page with the smallest value in time-of-use register is replaced
• Stack
- Stack of page numbers
- Whenever a page is referenced its page number is
removed from the stack and pushed on top
- Least recently used page number is at the bottom
45
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY MANAGEMENT HARDWARE
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
Subroutine
Stack
SQRT
Main
Program
Symbol
Table
User's view of memory
User's view of a program
The user does not think of
memory as a linear array
of words. Rather the user
prefers to view memory as
a collection of variable
sized segments, with no
necessary ordering among
segments.
Memory Management Hardware
46
Memory Organization
Computer Organization Computer Architectures Lab
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
limit base
(s,d)
s
Memory
+
y
n
error
CPU
Memory Management Hardware
47
Memory Organization
Computer Organization Computer Architectures Lab
SEGMENTATION EXAMPLE
Subroutine
Segment 0
Stack
Segment 3
SQRT
Segment 1 Main
Program
Segment 2
Symbol
Table
Segment 4
Segment 0
Segment 3
Segment 2
Segment 4
Segment 1
1400
2400
3200
4300
4700
5700
6300
6700
Segment Table
1000 1400
400 6300
400 4300
1100 3200
1000 4700
limit base
0
1
2
3
4
Logical Address Space
Memory Management Hardware
48
Memory Organization
Computer Organization Computer Architectures Lab
SHARING OF SEGMENTS
Editor
Segment 0
Data 1
Segment 1
Logical Memory
(User 1)
Editor
Segment 0
Data 2
Segment 1
Logical Memory
(User 2)
Editor
43062
Data 1
68348
72773
90003
98556
Data 2
25286 43062
4425 68348
limit base
0
1
Segment Table
(User 1)
25286 43062
8550 90003
limit base
0
1
Segment Table
(User 2)
Physical Memory
Memory Management Hardware
49
Memory Organization
Computer Organization Computer Architectures Lab
SEGMENTED PAGE SYSTEM
Segment Page Word
Segment table Page table
+
Block Word
Logical address
Physical address
Memory Management Hardware
50
Memory Organization
Computer Organization Computer Architectures Lab
IMPLEMENTATION OF PAGE AND SEGMENT TABLES
Implementation of the Page Table
- Hardware registers (if the page table is reasonably small)
- Main memory
Implementation of the Segment Table
Similar to the case of the page table
- Cache memory (TLB: Translation Lookaside Buffer)
- To speedup the effective memory access time,
a special small memory called associative
memory, or cache is used
- Page Table Base Register(PTBR) points to PT
- Two memory accesses are needed to access
a word; one for the page table, one for the word
Memory Management Hardware
51
Memory Organization
Computer Organization Computer Architectures Lab
EXAMPLE
Logical and Physical Addresses
Logical and Physical Memory Address Assignment
Segment Page Word
4 8 8
Block Word
12 8
Physical address format: 4096 blocks of 256 words
each, each word has 32bits
2 x 32
Physical
memory
20
Logical address format: 16 segments of 256 pages
each, each page has 256words
Hexa
address Page number
Page 0
Page 1
Page 2
Page 3
Page 4
60000
60100
60200
60300
60400
604FF
Segment Page Block
6 00 012
6 01 000
6 02 019
6 03 053
6 04 A61
(a) Logical address assignment (b) Segment-page versus
memory block assignment
Memory Management Hardware
52
Memory Organization
Computer Organization Computer Architectures Lab
LOGICAL TO PHYSICAL MEMORY MAPPING
Segment table
0
F
35
6
A3
Page table
00
35 012
36 000
37 019
38 053
39 A61
012
A3
Physical memory
00000
000FF
Block 0
01200
012FF
Block 12
01900
019FF
32-bit word
0197E
Logical address (in hexadecimal)
6 02 7E
Segment and page table mapping
Segment Page Block
6 02 019
6 04 A61
Associative memory mapping
Memory Management Hardware
53
Memory Organization
Computer Organization Computer Architectures Lab
MEMORY PROTECTION
Protection information can be included in the
segment table or segment register of the memory
management hardware
- Format of a typical segment descriptor
- The protection field in a segment descriptor specifies
the Access Rights to the particular segment
- In a segmented-page organization, each entry in the
page table may have its own protection field to
describe the Access Rights of each page
- Access Rights:
Full read and write privileges.
Read only (write protection)
Execute only (program protection)
System only (O.S. Protection)
Base address Length Protection
Memory Management Hardware
54
Memory Organization
Computer Organization Computer Architectures Lab
A Typical Cache and TLB Design
Page
Number
Line
Number
Word in
Line
Virtual Address
Virtual
Address
Real
Address
From translator CPU
Hash
Function
S
Compare Virtual
Addresses
Real Address Data
CPU Memory
A
S
To translator
Compare Addresses
& Select Data
Word Select & Align
Data
Data Out
S = Select
A
Real
Address
To Main Memory
TLB
Cache
55
Memory Organization
Computer Organization Computer Architectures Lab
Structure of Cache Entry and Cache Set
Cache Entry
Real Address Tag Data Valid
Entry 1 Entry 2    Entry E Replacement status
Cache Set
56
Memory Organization
Computer Organization Computer Architectures Lab
Cache Operation Flow Chart
Receive Virtual Address
Hash Page Number
Search TLB
In TLB ?
Send Virtual Address
to Translator
Use Page & Segment tables
to Translate Address
Put in TLB
A
Use Line Number
to Select Set
Read Out Address Tags
Compare Addresses
Match ?
Send Real Address
to Main Memory
Receive Line from
Main Memory
Select Correct
Word from Line
Read Out
Store Line
in Cache
Update Replacement
Status in TLB
Update Replacement
Status
Select
Correct
Line
A
yes
yes
no
no
57
Memory Organization
Computer Organization Computer Architectures Lab
Virtual Address Format - Example
Byte within line
31 21 20 17 12 11 10 4 3 2 1 0
Byte within page
Page number
Byte within
word
Word within
line
Select set
in cache
Select set
in TLB
Line number
Map through
page directory Map through
page table
Virtual Address of Fairchild Clipper

More Related Content

PPT
Memory Organization
PPT
Mba admission in india
PPTX
Unit-6.pptx lk kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Memory Organization digital image processing
PPTX
Memory organization.pptx
PPT
Memory organisation
PPTX
Different types of memory and hardware designs of RAM and ROM
PPT
Memory Hierarchy PPT of Computer Organization
Memory Organization
Mba admission in india
Unit-6.pptx lk kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Memory Organization digital image processing
Memory organization.pptx
Memory organisation
Different types of memory and hardware designs of RAM and ROM
Memory Hierarchy PPT of Computer Organization

Similar to Memory_Unit Cache Main Virtual Associative (20)

PPSX
Coa presentation3
PPTX
waserdtfgfiuerhiuerwehfiuerghzsdfghyguhijdrtyunit5.pptx
PPTX
UNIT-9 MEMORY ORGANIZATION OF COA..pptx
PPT
Memory organization and management in system.ppt
PPTX
Computer organizatin.Chapter Seven.pptxs
PDF
Memory (Computer Organization)
PPT
Memory Organizationsssssssssssssssss.ppt
PPT
Memoryhierarchy
PPTX
Memory Organization
PPTX
Computer memory
PPTX
logical memory-organisation
PPT
memory management powerpoint presentation
PPTX
Introduction to Computer - Secondary Storage.pptx
PPTX
Computer memory
PPTX
ICT-Lecture_07(Primary Memory and its types).pptx
PPT
Top schools in ghaziabad
PPT
Memory Organization in Computer Organization and Architecture
PPT
Btech admission in india
PPT
memory.ppt
PPT
memory.ppt
Coa presentation3
waserdtfgfiuerhiuerwehfiuerghzsdfghyguhijdrtyunit5.pptx
UNIT-9 MEMORY ORGANIZATION OF COA..pptx
Memory organization and management in system.ppt
Computer organizatin.Chapter Seven.pptxs
Memory (Computer Organization)
Memory Organizationsssssssssssssssss.ppt
Memoryhierarchy
Memory Organization
Computer memory
logical memory-organisation
memory management powerpoint presentation
Introduction to Computer - Secondary Storage.pptx
Computer memory
ICT-Lecture_07(Primary Memory and its types).pptx
Top schools in ghaziabad
Memory Organization in Computer Organization and Architecture
Btech admission in india
memory.ppt
memory.ppt
Ad

Recently uploaded (20)

PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPT
Total quality management ppt for engineering students
PPTX
UNIT - 3 Total quality Management .pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Abrasive, erosive and cavitation wear.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
Categorization of Factors Affecting Classification Algorithms Selection
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
86236642-Electric-Loco-Shed.pdf jfkduklg
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
R24 SURVEYING LAB MANUAL for civil enggi
Information Storage and Retrieval Techniques Unit III
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Fundamentals of safety and accident prevention -final (1).pptx
Fundamentals of Mechanical Engineering.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Total quality management ppt for engineering students
UNIT - 3 Total quality Management .pptx
Ad

Memory_Unit Cache Main Virtual Associative

  • 1. 1 Memory Organization Computer Organization Computer Architectures Lab • Memory Hierarchy • Main Memory • Auxiliary Memory • Associative Memory • Cache Memory • Virtual Memory • Memory Management Hardware MEMORY ORGANIZATION
  • 2. 2 Memory Organization Computer Organization Computer Architectures Lab MEMORY HIERARCHY Magnetic tapes Magnetic disks I/O processor CPU Main memory Cache memory Auxiliary memory Register Cache Main Memory Magnetic Disk Magnetic Tape Memory Hierarchy is to obtain the highest possible access speed while minimizing the total cost of the memory system Memory Hierarchy
  • 3. 3 Memory Organization Computer Organization Computer Architectures Lab MAIN MEMORY RAM and ROM Chips Typical RAM chip Typical ROM chip Chip select 1 Chip select 2 Read Write 7-bit address CS1 CS2 RD WR AD 7 128 x 8 RAM 8-bit data bus CS1 CS2 RD WR 0 0 x x 0 1 x x 1 0 0 0 1 0 0 1 1 0 1 x 1 1 x x Memory function Inhibit Inhibit Inhibit Write Read Inhibit State of data bus High-impedence High-impedence High-impedence Input data to RAM Output data from RAM High-impedence Chip select 1 Chip select 2 9-bit address CS1 CS2 AD 9 512 x 8 ROM 8-bit data bus Main Memory
  • 4. 4 Memory Organization Computer Organization Computer Architectures Lab MEMORY ADDRESS MAP RAM 1 RAM 2 RAM 3 RAM 4 ROM 0000 - 007F 0080 - 00FF 0100 - 017F 0180 - 01FF 0200 - 03FF Component Hexa address 0 0 0 x x x x x x x 0 0 1 x x x x x x x 0 1 0 x x x x x x x 0 1 1 x x x x x x x 1 x x x x x x x x x 10 9 8 7 6 5 4 3 2 1 Address bus Memory Connection to CPU - RAM and ROM chips are connected to a CPU through the data and address buses - The low-order lines in the address bus select the byte within the chips and other lines in the address bus select a particular chip through its chip select inputs Address space assignment to each memory chip Example: 512 bytes RAM and 512 bytes ROM Main Memory
  • 5. 5 Memory Organization Computer Organization Computer Architectures Lab CONNECTION OF MEMORY TO CPU Main Memory } CS1 CS2 RD WR AD7 128 x 8 RAM 1 CS1 CS2 RD WR AD7 128 x 8 RAM 2 CS1 CS2 RD WR AD7 128 x 8 RAM 3 CS1 CS2 RD WR AD7 128 x 8 RAM 4 Decoder 3 2 1 0 WR RD 9 8 7-1 10 16-11 Address bus Data bus CPU CS1 CS2 512 x 8 ROM AD9 1- 7 9 8 Data Data Data Data Data
  • 6. 6 Memory Organization Computer Organization Computer Architectures Lab • Random Access Memory (RAM) is used to store the programs and data being used by the CPU in real time. The data on the random access memory can be read, written, and erased any number of times. RAM is the hardware element where the data being currently used is stored. It is a volatile memory. • Types of RAM: – Static RAM, or (SRAM) which stores a bit of data using the state of a six transistor memory cell. – Dynamic RAM, or (DRAM) which stores a bit data using a pair of transistor and capacitor which constitute a DRAM memory cell.
  • 7. 7 Memory Organization Computer Organization Computer Architectures Lab • Read Only Memory (ROM) is a type of memory where the data has been prerecorded. Data stored in ROM is retained even after the computer is turned off ie, non- volatile. • Types of ROM: – Programmable ROM, where the data is written after the memory chip has been created. It is non-volatile. – Erasable Programmable ROM, where the data on this non-volatile memory chip can be erased by exposing it to high-intensity UV light. – Electrically Erasable Programmable ROM, where the data on this non- volatile memory chip can be electrically erased using field electron emission. – Mask ROM, in which the data is written during the manufacturing of the memory chip.
  • 8. 8 Memory Organization Computer Organization Computer Architectures Lab Difference RAM ROM Data retention RAM is a volatile memory which could store the data as long as the power is supplied. ROM is a non-volatile memory which could retain the data even when power is turned off. Working type Data stored in RAM can be retrieved and altered. Data stored in ROM can only be read. Use Used to store the data that has to be currently processed by CPU temporarily. It stores the instructions required during bootstrap of the computer. Speed It is a high-speed memory. It is much slower than the RAM. CPU Interaction The CPU can access the data stored on it. The CPU can not access the data stored on it unless the data is stored in RAM. Size and Capacity Large size with higher capacity. Small size with less capacity. Used as/in CPU Cache, Primary memory. Firmware, Micro-controllers Accessibility The data stored is easily accessible The data stored is not as easily accessible as in RAM Cost Costlier cheaper than RAM.
  • 9. 9 Memory Organization Computer Organization Computer Architectures Lab
  • 10. 10 Memory Organization Computer Organization Computer Architectures Lab • How many 32K x 1 RAM chips are needed to provide a memory capacity of 256K-bytes? (A) 8 (B) 32 (C) 64 (D) 128
  • 11. 11 Memory Organization Computer Organization Computer Architectures Lab • Answer: (C) Explanation: • We need 256 Kbytes, i.e., 256 x 1024 x 8 bits. We have RAM chips of capacity 32 Kbits = 32 x 1024 bits. • (256 * 1024 * 8)/(32 * 1024) = 64
  • 12. 12 Memory Organization Computer Organization Computer Architectures Lab • Number of chips (128 x 8 RAM) needed to provide a memory capacity of 2048 bytes (A) 2 (B) 4 (C) 8 (D) 16
  • 13. 13 Memory Organization Computer Organization Computer Architectures Lab Explanation: chips (128 x 8 RAM) needed to provide a memory of 2048 B = 2048 x 8 / 128 x 8 = 16 x 1
  • 14. 14 Memory Organization Computer Organization Computer Architectures Lab
  • 15. 15 Memory Organization Computer Organization Computer Architectures Lab RAM 2048 /256 = 8 chips; 2048 = 211; 256 = 28 • ROM 4096 /1024 = 4 chips; 4096 = 212; 1024 = 210 • Interface 4 × 4 = 16 registers; 16 = 24 • Component Address 16 15 14 13 12 11 10 19 8765 4321 • RAM 0000-O7FF 0 0 0 0 0 3 8 • decoder • × ←⎯⎯→ ×××× ×××× • ROM 4000-4FFF 0 1 0 0 2 4 • decoder • × ←⎯⎯→ ×× ×××× ×××× • Interface 8000-800F 1 0 0 0 0 0 0 0 0000 ××××
  • 16. 16 Memory Organization Computer Organization Computer Architectures Lab
  • 17. 17 Memory Organization Computer Organization Computer Architectures Lab (a) 8 chips are needed with address lines connected in parallel. (b) 16 × 8 = 128 chips. Use 14 address lines (16 k = 214) 10 lines specify the chip address 4 lines are decoded into 16 chip-select inputs.
  • 18. 18 Memory Organization Computer Organization Computer Architectures Lab A RAM chip has a capacity of 1024 words of 8 bits each (1K × 8). The number of 2 × 4 decoders with enable line needed to construct a 16K × 16 RAM from 1K × 8 RAM is (A) 4 (B) 5 (C) 6 (D) 7
  • 19. 19 Memory Organization Computer Organization Computer Architectures Lab Answer: (B) Explanation: RAM chip size = 1k ×8[1024 words of 8 bits each] RAM to construct =16k ×16 Number of chips required = (16k x 16)/ ( 1k x 8) = (16 x 2) [16 chips vertically with each having 2 chips horizontally] So to select one chip out of 16 vertical chips, we need 4 x 16 decoder. Available decoder is 2 x 4 decoder To be constructed is 4 x 16 decoder Hence 4 + 1 = 5 decoders are required.
  • 20. 20 Memory Organization Computer Organization Computer Architectures Lab AUXILIARY MEMORY Information Organization on Magnetic Tapes EOF IRG block 1 block 2 block 3 block 1 block 2 block 3 R1 R2 R3 R4 R5 R6 R1 R3 R2 R5 R4 file i EOF Organization of Disk Hardware Track Moving Head Disk Fixed Head Disk Auxiliary Memory
  • 21. 21 Memory Organization Computer Organization Computer Architectures Lab 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) Key register (K) Associative memory array and logic m words n bits per word Match register Input Read Write M - Compare each word in CAM in parallel with the content of A(Argument Register) - If CAM Word[i] = A, M(i) = 1 - Read sequentially accessing CAM for CAM Word(i) for M(i) = 1 - K(Key Register) provides a mask for choosing a particular field or key in the argument in A (only those bits in the argument that have 1’s in their corresponding position of K are compared) Associative Memory
  • 22. 22 Memory Organization Computer Organization Computer Architectures Lab ORGANIZATION OF CAM Internal organization of a typical cell Cij C11 Word 1 Word i Word m Bit 1 Bit j Bit n M1 Mi Mm Associative Memory Aj R S Output Match logic Input Write Read Kj Mi To F ij A1 Aj An K1 Kj Kn C1j C1n Ci1 Cij Cin Cm1 Cmj Cmn
  • 23. 23 Memory Organization Computer Organization Computer Architectures Lab MATCH LOGIC Associative Memory F'i1 F i1 K1 A1 F'i2 F i2 K2 A2 F'in Fin Kn An . . . . Mi
  • 24. 24 Memory Organization Computer Organization Computer Architectures Lab 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 Cache Memory Main memory Cache memory CPU
  • 25. 25 Memory Organization Computer Organization Computer Architectures Lab PERFORMANCE OF CACHE 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 ? Memory Access 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.2s, h = 0.85% Te = 0.4 + (1 - 0.85) * 1.2 = 0.58s Cache Memory
  • 26. 26 Memory Organization Computer Organization Computer Architectures Lab • Assume that for a certain processor, a read request takes 50 nanoseconds on a cache miss and 5 nanoseconds on a cache hit. Suppose while running a program, it was observed that 80% of the processor’s read requests result in a cache hit. The average read access time in nanoseconds is____________. (A) 10 (B) 12 (C) 13 (D) 14
  • 27. 27 Memory Organization Computer Organization Computer Architectures Lab • Answer: (D) Explanation: • The average read access time in nanoseconds = 0.8 * 5 + 0.2*50 = 14
  • 28. 28 Memory Organization Computer Organization Computer Architectures Lab Consider a system with 2 level caches. Access times of Level 1 cache, Level 2 cache and main memory are 1 ns, 10ns, and 500 ns, respectively. The hit rates of Level 1 and Level 2 caches are 0.8 and 0.9, respectively. What is the average access time of the system ignoring the search time within the cache? (A) 13.0 ns (B) 12.8 ns (C) 12.6 ns (D) 12.4 ns
  • 29. 29 Memory Organization Computer Organization Computer Architectures Lab Answer: (C) Explanation: First, the system will look in cache 1. If it is not found in cache 1, then cache 2 and then further in main memory (if not in cache 2 also). The average access time would take into consideration success in cache 1, failure in cache 1 but success in cache 2, failure in both the caches and success in main memory. Average access time = [H1*T1]+[(1-H1)*H2*T2]+[(1-H1)(1-H2)*Hm*Tm] where, H1 = Hit rate of level 1 cache = 0.8 T1 = Access time for level 1 cache = 1 ns H2 = Hit rate of level 2 cache = 0.9 T2 = Access time for level 2 cache = 10 ns Hm = Hit rate of Main Memory = 1 Tm = Access time for Main Memory = 500 ns
  • 30. 30 Memory Organization Computer Organization Computer Architectures Lab So, Average Access Time = ( 0.8 * 1 ) + ( 0.2 * 0.9 * 10 ) + ( 0.2 * 0.1 * 1 * 500) = 0.8 + 1.8 + 10 = 12.6 ns Thus, C is the correct choice.
  • 31. 31 Memory Organization Computer Organization Computer Architectures Lab MEMORY AND CACHE MAPPING - ASSOCIATIVE MAPPLING - Associative mapping Direct mapping Set-associative mapping Associative Mapping Mapping Function Specification of correspondence between main memory blocks and cache blocks - 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 0 1 0 0 0 0 2 7 7 7 2 2 2 3 5 3 4 5 0 6 7 1 0 1 2 3 4 CAM Cache Memory
  • 32. 32 Memory Organization Computer Organization Computer Architectures Lab MEMORY AND CACHE MAPPING - DIRECT MAPPING - Addressing Relationships Direct Mapping Cache Organization Memory address Memory data 00000 1 2 2 0 00777 01000 01777 02000 02777 2 3 4 0 3 4 5 0 4 5 6 0 5 6 7 0 6 7 1 0 Index address Tag Data 000 0 0 1 2 2 0 0 2 6 7 1 0 777 Cache memory Tag(6) Index(9) 32K x 12 Main memory Address = 15 bits Data = 12 bits 512 x 12 Cache memory Address = 9 bits Data = 12 bits 00 000 77 777 000 777 - 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 Cache Memory
  • 33. 33 Memory Organization Computer Organization Computer Architectures Lab DIRECT MAPPING Direct Mapping with block size of 8 words 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) Index tag data 000 0 1 3 4 5 0 007 0 1 6 5 7 8 010 017 770 0 2 777 0 2 6 7 1 0 Block 0 Block 1 Block 63 Tag Block Word 6 6 3 INDEX Cache Memory
  • 34. 34 Memory Organization Computer Organization Computer Architectures Lab MEMORY AND CACHE MAPPING - SET ASSOCIATIVE MAPPING - Set Associative Mapping Cache with set size of two - Each memory block has a set of locations in the Cache to load Index Tag Data 000 0 1 3 4 5 0 0 2 5 6 7 0 Tag Data 777 0 2 6 7 1 0 0 0 2 3 4 0 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
  • 35. 35 Memory Organization Computer Organization Computer Architectures Lab BLOCK REPLACEMENT POLICY Many different block replacement policies are available LRU(Least Recently Used) is most easy to implement Cache word = (tag 0, data 0, U0);(tag 1, data 1, U1), Ui = 0 or 1(binary) Implementation of LRU in the Set Associative Mapping with set size = 2 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
  • 36. 36 Memory Organization Computer Organization Computer Architectures Lab 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 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 Cache Memory
  • 37. 37 Memory Organization Computer Organization Computer Architectures Lab 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 Mapping Memory Mapping Table for Virtual Address -> Physical Address virtual address (logical address) physical address address space memory space address generated by programs actual main memory address Mapping Virtual address Virtual address register Memory mapping table Memory table buffer register Main memory address register Main memory Main memory buffer register Physical Address Virtual Memory
  • 38. 38 Memory Organization Computer Organization Computer Architectures Lab ADDRESS MAPPING Organization of memory Mapping Table in a paged system Address Space and Memory Space are each divided into fixed size group of words called blocks or pages 1K words group Page 0 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Block 3 Block 2 Block 1 Block 0 Address space N = 8K = 213 Memory space M = 4K = 212 0 000 1 001 1 010 0 011 0 100 1 101 1 110 0 111 1 Block 0 Block 1 Block 2 Block 3 MBR 0 1 0 1 0 1 0 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 1 1 Table address Presence bit Page no. Line number Virtual address Main memory address register Memory page table Main memory 11 00 01 10 01 Virtual Memory
  • 39. 39 Memory Organization Computer Organization Computer Architectures Lab ASSOCIATIVE MEMORY PAGE TABLE 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 - More efficient method is m-entry Page Table Page Table made of an Associative Memory m words; (Page Number:Block Number) 1 0 1 Line number Page no. Argument register 1 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 0 Key register Associative memory Page no.Block no. Virtual address Page Fault Page number cannot be found in the Page Table Virtual Memory
  • 40. 40 Memory Organization Computer Organization Computer Architectures Lab PAGE FAULT Processor architecture should provide the ability to restart any instruction after a page fault. 1. Trap to the OS 2. Save the user registers and program state 3. Determine that the interrupt was a page fault 4. Check that the page reference was legal and determine the location of the page on the backing store(disk) 5. Issue a read from the backing store to a free frame a. Wait in a queue for this device until serviced b. Wait for the device seek and/or latency time c. Begin the transfer of the page to a free frame 6. While waiting, the CPU may be allocated to some other process 7. Interrupt from the backing store (I/O completed) 8. Save the registers and program state for the other user 9. Determine that the interrupt was from the backing store 10. Correct the page tables (the desired page is now in memory) 11. Wait for the CPU to be allocated to this process again 12. Restore the user registers, program state, and new page table, then resume the interrupted instruction. LOAD M 0 Reference 1 OS trap 2 3 Page is on backing store free frame main memory 4 bring in missing page 5 reset page table 6 restart instruction Virtual Memory
  • 41. 41 Memory Organization Computer Organization Computer Architectures Lab PAGE REPLACEMENT Modified page fault service routine Decision on which page to displace to make room for an incoming page when no free frame is available 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 2 f 0 v i f v frame valid/ invalid bit page table change to invalid 4 reset page table for new page victim 1 swap out victim page 3 swap desired page in backing store physical memory Virtual Memory
  • 42. 42 Memory Organization Computer Organization Computer Architectures Lab PAGE REPLACEMENT ALGORITHMS FIFO 0 7 1 7 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 7 0 1 0 0 7 1 2 0 1 2 3 1 2 3 0 4 3 0 4 2 0 4 2 3 0 2 3 0 1 3 0 1 2 7 1 2 7 0 2 7 0 1 Page frames Reference string - 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 0 7 1 7 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 7 0 1 0 0 7 1 2 0 1 2 0 3 2 4 3 2 0 3 2 0 1 7 0 1 Page frames Reference string Virtual Memory
  • 43. 43 Memory Organization Computer Organization Computer Architectures Lab PAGE REPLACEMENT ALGORITHMS - OPT is difficult to implement since it requires future knowledge - LRU uses the recent past as an approximation of near future. Replace that page which has not been used for the longest period of time LRU 0 7 1 7 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 7 0 1 0 0 7 1 2 0 1 2 0 3 4 0 3 4 0 2 4 3 2 0 3 2 1 3 2 1 0 2 1 0 7 Page frames Reference string Virtual Memory - LRU may require substantial hardware assistance - The problem is to determine an order for the frames defined by the time of last use
  • 44. 44 Memory Organization Computer Organization Computer Architectures Lab PAGE REPLACEMENT ALGORITHMS 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 Virtual Memory 4 7 0 7 1 0 1 2 1 2 7 1 2 Reference string 2 1 0 7 4 7 2 1 0 4 LRU Implementation Methods • Counters - For each page table entry - time-of-use register - Incremented for every memory reference - Page with the smallest value in time-of-use register is replaced • Stack - Stack of page numbers - Whenever a page is referenced its page number is removed from the stack and pushed on top - Least recently used page number is at the bottom
  • 45. 45 Memory Organization Computer Organization Computer Architectures Lab MEMORY MANAGEMENT HARDWARE 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 Subroutine Stack SQRT Main Program Symbol Table User's view of memory User's view of a program The user does not think of memory as a linear array of words. Rather the user prefers to view memory as a collection of variable sized segments, with no necessary ordering among segments. Memory Management Hardware
  • 46. 46 Memory Organization Computer Organization Computer Architectures Lab 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 limit base (s,d) s Memory + y n error CPU Memory Management Hardware
  • 47. 47 Memory Organization Computer Organization Computer Architectures Lab SEGMENTATION EXAMPLE Subroutine Segment 0 Stack Segment 3 SQRT Segment 1 Main Program Segment 2 Symbol Table Segment 4 Segment 0 Segment 3 Segment 2 Segment 4 Segment 1 1400 2400 3200 4300 4700 5700 6300 6700 Segment Table 1000 1400 400 6300 400 4300 1100 3200 1000 4700 limit base 0 1 2 3 4 Logical Address Space Memory Management Hardware
  • 48. 48 Memory Organization Computer Organization Computer Architectures Lab SHARING OF SEGMENTS Editor Segment 0 Data 1 Segment 1 Logical Memory (User 1) Editor Segment 0 Data 2 Segment 1 Logical Memory (User 2) Editor 43062 Data 1 68348 72773 90003 98556 Data 2 25286 43062 4425 68348 limit base 0 1 Segment Table (User 1) 25286 43062 8550 90003 limit base 0 1 Segment Table (User 2) Physical Memory Memory Management Hardware
  • 49. 49 Memory Organization Computer Organization Computer Architectures Lab SEGMENTED PAGE SYSTEM Segment Page Word Segment table Page table + Block Word Logical address Physical address Memory Management Hardware
  • 50. 50 Memory Organization Computer Organization Computer Architectures Lab IMPLEMENTATION OF PAGE AND SEGMENT TABLES Implementation of the Page Table - Hardware registers (if the page table is reasonably small) - Main memory Implementation of the Segment Table Similar to the case of the page table - Cache memory (TLB: Translation Lookaside Buffer) - To speedup the effective memory access time, a special small memory called associative memory, or cache is used - Page Table Base Register(PTBR) points to PT - Two memory accesses are needed to access a word; one for the page table, one for the word Memory Management Hardware
  • 51. 51 Memory Organization Computer Organization Computer Architectures Lab EXAMPLE Logical and Physical Addresses Logical and Physical Memory Address Assignment Segment Page Word 4 8 8 Block Word 12 8 Physical address format: 4096 blocks of 256 words each, each word has 32bits 2 x 32 Physical memory 20 Logical address format: 16 segments of 256 pages each, each page has 256words Hexa address Page number Page 0 Page 1 Page 2 Page 3 Page 4 60000 60100 60200 60300 60400 604FF Segment Page Block 6 00 012 6 01 000 6 02 019 6 03 053 6 04 A61 (a) Logical address assignment (b) Segment-page versus memory block assignment Memory Management Hardware
  • 52. 52 Memory Organization Computer Organization Computer Architectures Lab LOGICAL TO PHYSICAL MEMORY MAPPING Segment table 0 F 35 6 A3 Page table 00 35 012 36 000 37 019 38 053 39 A61 012 A3 Physical memory 00000 000FF Block 0 01200 012FF Block 12 01900 019FF 32-bit word 0197E Logical address (in hexadecimal) 6 02 7E Segment and page table mapping Segment Page Block 6 02 019 6 04 A61 Associative memory mapping Memory Management Hardware
  • 53. 53 Memory Organization Computer Organization Computer Architectures Lab MEMORY PROTECTION Protection information can be included in the segment table or segment register of the memory management hardware - Format of a typical segment descriptor - The protection field in a segment descriptor specifies the Access Rights to the particular segment - In a segmented-page organization, each entry in the page table may have its own protection field to describe the Access Rights of each page - Access Rights: Full read and write privileges. Read only (write protection) Execute only (program protection) System only (O.S. Protection) Base address Length Protection Memory Management Hardware
  • 54. 54 Memory Organization Computer Organization Computer Architectures Lab A Typical Cache and TLB Design Page Number Line Number Word in Line Virtual Address Virtual Address Real Address From translator CPU Hash Function S Compare Virtual Addresses Real Address Data CPU Memory A S To translator Compare Addresses & Select Data Word Select & Align Data Data Out S = Select A Real Address To Main Memory TLB Cache
  • 55. 55 Memory Organization Computer Organization Computer Architectures Lab Structure of Cache Entry and Cache Set Cache Entry Real Address Tag Data Valid Entry 1 Entry 2    Entry E Replacement status Cache Set
  • 56. 56 Memory Organization Computer Organization Computer Architectures Lab Cache Operation Flow Chart Receive Virtual Address Hash Page Number Search TLB In TLB ? Send Virtual Address to Translator Use Page & Segment tables to Translate Address Put in TLB A Use Line Number to Select Set Read Out Address Tags Compare Addresses Match ? Send Real Address to Main Memory Receive Line from Main Memory Select Correct Word from Line Read Out Store Line in Cache Update Replacement Status in TLB Update Replacement Status Select Correct Line A yes yes no no
  • 57. 57 Memory Organization Computer Organization Computer Architectures Lab Virtual Address Format - Example Byte within line 31 21 20 17 12 11 10 4 3 2 1 0 Byte within page Page number Byte within word Word within line Select set in cache Select set in TLB Line number Map through page directory Map through page table Virtual Address of Fairchild Clipper