Lecture Virtual Memory Unit 5
Lecture Virtual Memory Unit 5
• Less I/O would be needed to load or swap each user program into
memory, Virtual memory can be implemented via:
• Demand paging
• Demand segmentation
Transfer of a Paged Memory to Contiguous Disk Space
Demand Paging
i
i
page table
1 1 4 5
2 2 1 3 9 page faults
3 3 2 can
4 be in memory per process)
• 4 frames (3 pages
1 1 5 4
2 2 1 5 10 page faults
3 3 2
4 4 3
Optimal Algorithm (Called OPT or MIN)
We don’t! OPT is impossible to implement accurately unless
the order of page references is known a priori
1 4
2 6 page faults
3
4 5
LRU replacement
• Replace a page that has not been used for the longest period of time.
• This approach is LEAST RECENTLY USED(LRU) algorithm.
• LRU replacement associates with each page the time of the page’s last
use. When a page is to be replaced, LRU chooses the page that has not
been used for the longest period of time.
LRU Page Replacement Example
Thrashing
• Thrashing - a process is busy swapping pages in and out
• This high paging activity is called thrashing.
• If a process does not have “enough” pages, the page-fault rate is very high
• Page fault to get page
• Replace existing frame
• But quickly need replaced frame back
• This leads to:
• Low CPU utilization
• Operating system thinking that it needs to increase the degree of
multiprogramming
• Another process added to the system