Page 179 - DCAP103_Principle of operating system
P. 179
Principles of Operating Systems
Notes page replacement algorithm never has to search for a replacement — it just looks on top
of the stack — it still results in a large system overhead to maintain the stack. We must
update a data structure which requires process synchronization and therefore waiting.
Again, without special hardware, this is not economical. In practice, many systems use
something like the second-chance algorithm above. The UNIX page daemon uses this
approach.
5.8 Thrashing
Swapping and paging can lead to quite a large system overhead. Compared to memory speeds,
disk access is quite slow — and, in spite of optimized disk access for the swap area, these
operations delay the system markedly. Consider the sequence of events which takes place when
a page fault occurs:
1. Interrupt/trap and pass control to the system interrupt handler.
2. Save the process control block.
3. Determine cause of interrupt — a page fault.
4. Consult MMU — is the logical address given inside the process’ segment, i.e. legal.
5. Look for a free frame in the frame table. If none is found, free one.
6. Schedule the disk operation to copy the required page and put the process into the waiting
state.
7. Interrupt from disk signals end of waiting.
8. Update the page table and schedule the process for running.
9. (On scheduling) Restore the process control block and resume executing the instruction
that was interrupted.
Such a sequence of operations could take of the order or milliseconds under favorable conditions
(although technology is rapidly reducing the timescale for everything). It is possible for the
system to get into a state where there are so many processes competing for limited resources
that it spends more time servicing page faults and swapping in and out processes than it does
executing the processes. This sorry state is called thrashing.
Thrashing can occur when there are too many active processes for the available memory.
It can be alleviated in certain cases by making the system page at an earlier threshold of
memory usage than normal. In most cases, the best way to recover from thrashing is to
suspend processes and forbid new ones, to try to clear some of the others by allowing
them to execute. The interplay between swapping and paging is important here too, since
swapping effectively suspends jobs.
Thrashing can occur when there are too many active processes for the
available memory. It can be alleviated in certain cases by making the system
page at an earlier threshold of memory usage than normal. In most cases,
the best way to recover from thrashing is to suspend processes and forbid
new ones, to try to clear some of the others by allowing them to execute.
The interplay between swapping and paging is important here too, since
swapping effectively suspends jobs.
172 LOVELY PROFESSIONAL UNIVERSITY