Virtual Memory
Virtual Memory
that are not completely in memory. One of the major advantage of this scheme is that programs can be larger than the physical memory available.
separation of user logical memory from physical memory. Program would no longer be constrained by the amount of physical
Demand paging
Demand segmentation
9.1
9.2
Demand Paging
Bring a page into memory only when it is needed
9.3
Valid-Invalid Bit
With each page table entry a validinvalid bit is associated (v in-memory, i not-in-memory) Initially validinvalid bit is set to i on all entries Example of a page table snapshot:
Frame # valid-invalid bit
v v v v i . i i
page table
9.5
Page Fault
If there is a reference to a page, first reference to
9.6
9.7
Replacement algorithm selects the victim page want an algorithm which will result in minimum number of page faults
9.8
2.
Find a free frame: - If there is a free frame, then use it - If there are no free frames, use a page replacement algorithm to select a victim frame Bring the desired page into the (newly) freed frame, and update the page and frame tables
Restart the interrupted instruction of the process
3.
4.
9.9
Page Replacement
Use modify (dirty) bit to reduce overhead of page transfers
9.10
string of memory references (reference string) and computing the number of page faults on that string
FIFO page replacement Optimal page replacement LRU page replacement LRU approximation page replacement
9.11
9.12
9.13
9.14
1 2 3
1 2 3
4 1 2
5 3 4 9 page faults
1 2 3 4
5 1 2 3
4 5 10 page faults
2
3 4
9.15
9.16
4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 2 3 4 5 4 6 page faults
We dont! OPT is impossible to implement accurately unless the order of page references is known a priori
9.17
9.18
Optimal
Future requirement
Operating System Concepts 7th Edition, Feb 22, 2005 9.19 Silberschatz, Galvin and Gagne 2005
Reference to page 2 replaces page 7, because page 7 will not be used until reference 18, whereas page 0 will be used at 5, and page 1 at 14. The reference to page 3 replaces page 1, as page 1 will be the last of the 3 pages in the memory to be referenced again. With only 9 page faults, OPT is much better than FIFO algo. Which results in 15 faults.
9.20
LRU replacement
The key distinction between FIFO and OPT(other than
looking backward versus forward in time) is that FIFO algo uses the time when a page was brought into the memory whereas Opt algo uses the time when a page is to be used.
If we use recent past as an approximation of the near future,
thus we can 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
pages last use. When a page is to be replaced, LRU chooses the page that has not been used for the longest period of time.
9.21
1 2 3 4
1 2 5 4
1 2 5 3
1 2 4 3
2
4 3
9.22
LRU
9.23
9.24
Every page entry has a counter; every time page is referenced through this entry, copy the clock value into the counter When a page needs to be replaced, linear search the counters and select the minimum value as the victim
Stack implementation
9.25
9.26
true LRU page replacement. Some systems provide no hardware support, and other page replacement algorithms must have to be used. Many systems provide help, however, in the form of reference bit.
Reference bit (modified by hardware)
With each page associate a reference bit, initially = 0 When page is referenced, set reference bit to 1 Replace any victim page with reference bit = 0
9.27
set reference bit 0 leave page in memory replace next page (in clock order), subject to same rules
(0,0) neither recently used, nor modified (best choice) (0,1) not recently used, but modified (need write-back) (1,0) recently used, but not modified (might need soon) (1,1) recently used and modified (worst choice)
9.28
9.29
Counting Algorithms
Keep a counter of the number of references that have been
Replaces page with the smallest reference count Intuition is that active pages have high reference counts
A problem arises, however, when a page is used heavily during the initial phase of the process and may never used again. But because of its large count it remains in the memory. Replaces the page with the highest reference count
Intuition is that pages with small reference counts were probably just paged into memory recently and have yet to be used in the active working set
9.30
Each process selects only from its set of allocated frames Pages in memory for process P is only affected by the paging behavior of process P itself. Number of frames allocated per process doesnt change
Global replacement
9.31
Thrashing
If the number of frames allocated to a low priority process falls
below the minimum number required by the computer architecture , If a process does not have enough pages in memory, it will quickly page fault at this point it must replace some page. Since all the pages are active in use, it must replace a page that will be needed again right away. Consequently, it page faults again, and again and again. the page-fault rate can be very high. This leads to:
Low CPU utilization and low throughput OS attempts to increase the degree of multiprogramming Another process added to the system Even more page faults ensue.
Thrashing a process is busy swapping pages in and out This high paging activity is called thrashing.
9.32
Thrashing
9.33
If actual rate too low, process loses frame If actual rate too high, process gains frame
9.34
Prepaging
Prepaging
To reduce the large number of page faults that occurs at process startup Prepage all or some of the pages a process will need, before they are referenced But if prepaged pages are unused, I/O and memory was wasted
9.35
End of Chapter 9