A system thrashing is often a result of a sudden spike in memory requests during page demanding from a small number of running programs, which is difficult for OS to handle this situation.
The Swap-Token Solution Swap-token is a lightweight and dynamic thrashing protection mechanism for OS. The basic idea is to set a token in the system, which is randomly or targetly given to a process that has page faults when thrashing happens. The process that has the token is given a privilege to allocate more physical memory pages to build its working set, which is expected to quickly finish its execution and to release its physical memory space allocation to other processes. A time stamp is used to handover the token one by one.
The Usage of the Swap-Token in OS
The first version of swap-token implemented in Linux applies the random approach. The second version is called preempt swap-token, where a priority counter is set for each process to track the number of swap-out pages. The token is always given to the process with a high priority, which has a high number of swap-out pages. The length of the time stamp is not a constant but is determined by the priority: the higher the number of swap-out pages of a process, the longer the time stamp for it will be.