Second-Chance AlgorithmBasically, its a FIFO algorithmWhen 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 pageWhen a page get a second chance, its reference bit is cleared, and its arrival time is reset to the current time
Second-Chance AlgorithmWhen a page get a second chance, its reference bit is cleared, and its arrival time is reset to the current timeIf a page is used often enough to keep its reference bit set, it will never be replaced
Second-Chance AlgorithmOne 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
Second-Chance Algorithm
Additional-Reference-Bits AlgorithmWe 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 memoryThe 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 AlgorithmFor example: 00000000 means the page has not been used for eight-time interval11111111 means a page that is used at least once in each period11000100 has used more recently with both value of 01110111 and 00111111
Counting Based Page ReplacementLeast Frequently used (LFU) page-replacement algorithm
Most frequently used (MFU) page-replacement algorithm
Page Buffering AlgorithmWe can keep some amount of frames (for example 3 frames) always freeWhen 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 FramesWhen we have more than one processor, we need to allocate frames to each processor
Two major algorithms:1. equal allocation2. proportional allocation
Allocation of Frames
9.6 ThrashingIf 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
ThrashingIf CPU utilization is too low, we increase the degree of multiprogramming by introducing a new process to the systemNow, suppose that a process enters a new phase in its execution and needs more framesIt causes page faults which requires paging device to swap pages in and outCPU utilization therefore decreases
ThrashingThe trade off between CPU utilization and degree of multiprogrammingWhen thrashing has occurred, system throughput plunges. The page fault rate increases tremendouslyAs a result, no work is getting done since the processes are spending all their time paging
ThrashingAs 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
Solution to ThrashingBy considering Page-fault Frequency (PFF)This is trying to prevent thrashingSince Thrashing has a high page-fault rate, we need to control thatWe can establish upper and lower bounds on the desired page-fault rate
Solution to Thrashing
Solution to ThrashingIf 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