381CCS Chapter7
381CCS Chapter7
2
7.1 BACKGROUND
Code needs to be in memory to execute, but entire program rarely used
• Error code, unusual routines, large data structures
Entire program code not needed at same time
Virtual memory
• It is a scheme that allows a process to execute while it is only partially
in memory,
Figure 7.3 Page table when some pages are not in main memory.
STEPS IN HANDLING A PAGE FAULT
1. If there is a reference to a page, first reference to that page will trap to operating
system Page fault
2. Operating system looks at another table to decide:
Invalid reference abort, Just not in memory
3. Find free frame
4. Swap page into frame via scheduled disk operation
5. Reset tables to indicate page now in memory, Set validation bit = v
6. Restart the instruction that caused the page fault
Figure 7.3 Page table when some pages are not in main memory.
7.2.2 FREE-FRAME LIST
When a page fault occurs, the operating system must bring the desired page from
secondary storage into main memory.
Most operating systems maintain a free-frame list -- a pool of free frames for
satisfying such requests.
Operating system typically allocate free frames using a technique known as zero-
fill-on-demand -- the content of the frames zeroed-out before being allocated.
When a system starts up, all available memory is placed on the free-frame list.
Page Fault = 15
Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5
• Adding more frames can cause more page faults!
Belady’s Anomaly
How to track ages of pages?
• Just use a FIFO queue
9
Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
7.3.3 OPTIMAL PAGE REPLACEMENT ALGORITHM
Replace page that will not be used for longest period of time
• 9 is optimal for the example
How do you know this?
• Can’t read the future
Used for measuring how well your algorithm performs
Page Fault = 9
1
0
Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
7.3.4 LEAST RECENTLY USED (LRU) ALGORITHM
Replace page that has not been used in the most amount of time
Associate time of last use with each page
Page Fault = 12, Better than FIFO but worse than OPT
Generally good algorithm and frequently used