Page Thrashing

A further problem that may occur when performing swapping operations is page thrashing. As the term implies, this involves intensive transfers between swap space and RAM memory; this boils down to nothing more than the repeated backward and forward swapping of pages. This phenomenon tends to increase as the number of system processes increases. It occurs when important data are swapped out and are needed again very soon afterward.

The main problem that the kernel must address to prevent page thrashing is to determine the working set of a process (in other words, the pages that are needed most frequently) as accurately as possible so that the least important pages can be moved to the swap area or some other backing store and the really important data can be kept in memory.

To do this, the kernel needs an appropriate algorithm to evaluate the importance of pages to the overall system. On the one hand, pages must be evaluated as fairly as possible so that processes are not unduly favored or disadvantaged. On the other hand, the algorithm must be implemented simply and efficiently to ensure that not too much processing time is needed to select the pages to be swapped out.

The many CPU types provide different methods of supporting the kernel in this task that vary in their level of sophistication. However, Linux is not able to use all methods as they are not always available on simpler CPUs and may also be difficult to emulate. As usual, the lowest common denominator must be found upon which the kernel can build its hardware-independent layers.

One particularly simple, but important trick that is completely independent of the processor's abilities is to keep a swap token in the system that is given to one single process that swaps in pages. The kernel tries to avoid swapping out pages from this process, thus alleviating its situation by giving it some time to, hopefully, finish a task. After some time, the swap token is passed to some other process that also undergoes swapping and requires memory more exigent than the current token holder.

Continue reading here: Second Chance

Was this article helpful?

0 0