170 likes | 316 Views
Second-Chance Algorithm. Basically, it’s a FIFO algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to replace this page, otherwise, we give the page a second chance and move on to select the next FIFO page
E N D
Second-Chance Algorithm • Basically, it’s a FIFO algorithm • When a page has been selected, we inspect its reference bit. • If the value is 0, we proceed to replace this page, otherwise, we give the page a second chance and move on to select the next FIFO page • When a page get a second chance, it’s reference bit is cleared, and its arrival time is reset to the current time
Second-Chance Algorithm • When a page get a second chance, it’s reference bit is cleared, and its arrival time is reset to the current time • If a page is used often enough to keep its reference bit set, it will never be replaced
Second-Chance Algorithm • One way to implement the second-chance algorithm is as a circular queue • In the worst case, when all bits are set, the pointer cycles through the whole queue, giving each page a second chance • Enhanced second-chance algorithm
Additional-Reference-Bits Algorithm • We can gain additional ordering information by recording the reference bits at regular intervals. • We can keep 8-bit byte for each page in a table in memory • The OS shifts the reference bit for each page into the high-order bit of its 8-bit byte, shifting the other bit right by 1 bit and discard the low-order bit
Additional-Reference-Bits Algorithm • For example: 00000000 means the page has not been used for eight-time interval • 11111111 means a page that is used at least once in each period • 11000100 has used more recently with both value of 01110111 and 00111111
Counting Based Page Replacement • Least Frequently used (LFU) page-replacement algorithm • Most frequently used (MFU) page-replacement algorithm
Page Buffering Algorithm • We can keep some amount of frames (for example 3 frames) always free • When a page fault occurs, the system does not have to wait the execution of replace algorithm. • The system can load the page into free space and swapped out frames
Allocation of Frames • When we have more than one processor, we need to allocate frames to each processor • Two major algorithms: • 1. equal allocation • 2. proportional allocation
9.6 Thrashing • If the process does not have “enough” number of frames it needs to support page in active use, it will quickly page-fault • If the number of frames allocated to a process falls below the minimum number required by the process, thrashing will happen • Thrashing: The process spending more time paging than executing • Thrashing results in severe performance problems
Thrashing • If CPU utilization is too low, we increase the degree of multiprogramming by introducing a new process to the system • Now, suppose that a process enters a new phase in its execution and needs more frames • It causes page faults which requires paging device to swap pages in and out • CPU utilization therefore decreases
Thrashing • The trade off between CPU utilization and degree of multiprogramming • When thrashing has occurred, system throughput plunges. The page fault rate increases tremendously • As a result, no work is getting done since the processes are spending all their time paging
As the degree of multiprogramming increases, CPU utilization also increases If the degree of multiprogramming is increased even further, thrashing sets in, and CPU utilization drops sharply Under this situation, we must decrease the degree of multiprogramming Thrashing
Solution to Thrashing • By considering Page-fault Frequency (PFF) • This is trying to prevent thrashing • Since Thrashing has a high page-fault rate, we need to control that • We can establish upper and lower bounds on the desired page-fault rate
Solution to Thrashing • If the page-fault rate increases and no free frames are available, we must select some process and suspend it. • The freed frames are then distributed to processes with high page-fault rates