EECS 3221 E F20 Ch-10 1 Virtual Memory Material
Virtual Memory
These materials, including any presentations, are the exclusive copyright of Prof. Jia Xu and may only be used by students enrolled in EECS 3221 Section E, Operating System Fundamentals, in the Fall 2020 semester at York University, Toronto, Canada. Unauthorized or commercial use of these materials is expressly prohibited.
Copyright © 2020 Jia Xu. All rights reserved.
Demand Paging, Page Fault, and Page Replacement (See OS-ch10.pdf, slides 10.1 – 10.21; Textbook p.389-404.)
1. Here is an example that illustrates how page replacement works.
1.1.The first diagram titled “Before Page Replacement” below, illustrates the state of a system at the time when process 1 attempts to access page M which is not in memory – this generates a page fault.
The page table for process 1 indicates that page M is not in memory, because the valid-invalid bit in the page table entry associated with page M is set to “i” which means “invalid”.
The page fault causes a trap to the operating system, which:
(a)
(b)
(c)
select a victim page. It is assumed that page D in frame 2, which belongs to process 2, is selected as the victim page.
Finds the location of the desired page M on disk
Tries to find a free frame:
Since there is no free frame, a page replacement algorithm is used to
(d) Writes out page D to disk if D has been modified; brings the desired page M from disk into the (newly) free frame 2; updates the page and frame tables. (e) Restarts process 1 where the page fault occurred, so process 1 is able to access page M as if page M had always been present in physical memory.
Copyright © 2020 Jia Xu. All rights reserved.
PC
0 1
2 3
0 1 2 3
0
1 2
4 5 6
7
physical memory
Before Page Replacement
valid/invalid frame bit
L
M
O
P
3
v
i
5
v
4
v
monitor
D
L
P
O
A
E
page table
logical memoryfor process 1 3
D
M
for process 1
6
v
i
2
v
7
v
A
B
D
E
logical memory for process 2
secondary storage (disk)
Copyright © 2020 Jia Xu. All rights reserved.
page table for process 2
B
1.2.The second diagram titled “After Page Replacement” below, illustrates the state of the system after all the actions described above have been performed.
Copyright © 2020 Jia Xu. All rights reserved.
frame
valid/invalid bit
After Page Replacement
L
M
O
P
3
v
2
v
5
v
4
v
PC
0 1
2 3
4
reset page table for 0
new page 1
swap out victim page
1 3D
monitor
M
L
P
O
A
E
logical memoryfor process 1 for process 1
page table
2 3 4
6
v
i
i
7
v
A
B
D
E
0 1 2 3
logical memory for process 2
2 change to invalid
page table for process 2
5swap 6 desired 7 page in
physical memory
M
Copyright © 2020 Jia Xu. All rights reserved.
B
secondary storage (disk)