Thrashing

A process is thrashing when it is spending more time on page faults (and page replacements) than executing its code.

Cause: historically, whenever the OS notices that the CPU utilization is low (the CPU is not executing code,) it runs more processes. The problem is that when memory is filled up and processes start spending more time waiting for their pages to be loaded from disk, then CPU utilization would decrease (since the processes are waiting,) causing the scheduler to add in even more processes, which makes thrashing grow.

To prevent thrashing, we check how many frames the process needs "right now" using one of the methods below:

  1. Locality Model: It is typical for processes to access pages located in the same general area of memory (= locality), so the number of needed frames could become the number of frames in the current locality.
  2. Working-Set Model: Take note of (observe) the most recently accessed pages for some time, and make the number of frames equal to the amount of these accessed pages.