Virtual Memory
Virtual Memory
Overview
Memory Hierarchy
Main Memory
Auxiliary Memory
Associative Memory
Cache Memory
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 Mapping
Memory Mapping Table for Virtual Address -> Physical Address
Virtual address
Physical
Address
Memory table Main memory
buffer register buffer register
Address Mapping
Address Space and Memory Space are each divided into fixed size group of
words called blocks or pages
Page 0
1K words group Page 1
Page 2
Address space Memory space Block 0
Page 3
N = 8K = 213 M = 4K = 212 Block 1
Page 4
Block 2
Page 5
Block 3
Page 6
Page 7
Organization of memory Mapping Table in a paged system
Page no. Line number
1 0 1 0 1 0 1 0 1 0 0 1 1 Virtual address
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
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
CSE 211, Computer Organization and Architecture Harjeet Kaur, CSE/IT
Memory Organization 5 Lecture 43
Page Fault
1. Trap to the OS OS
2. Save the user registers and program state
3. Determine that the interrupt was a page fault 2 trap
4. Check that the page reference was legal and
determine the location of the page on the
backing store(disk) 1 Reference
LOAD M
5. Issue a read from the backing store to a free 0
frame 6
restart
a. Wait in a queue for this device until serviced instruction 4
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 swap
out
1 victim
page
2 change to
f 0 v i invalid victim
3
4 swap
f v reset page
table for desired
new page page in
backing store
page table
physical memory
CSE 211, Computer Organization and Architecture Harjeet Kaur, CSE/IT
Memory Organization 7 Lecture 43
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
CSE 211, Computer Organization and Architecture Harjeet Kaur, CSE/IT
Memory Organization 8 Lecture 43
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