Preventing And Recovering From Thrashing Tutorial

Describes how to reduce the chance of thrashing occurring in demand memory and how to recover from thrashing.

Introduction

Thrashing is a state where the vast majority of the processing time is spent paging memory in and out of the system and very little is spent useful work. If this situation persists, then the system performance rapidly becomes unacceptable and will appear to the user to have hung.

Background information

The following is useful background reading:

  • Thrashing

Thrashing features

When thrashing occurs the device will appear to do nothing or 'hang' for period. Unlike a deadlock however, the device can recover from thrashing.

Prevention of thrashing

The following can be used reduce the chance of thrashing:

  • Compress pages in memory to decrease the amount of memory that has to be paged in and out

  • Limit the maximum size of each process's paged memory to the minimum size of the paging cache

  • Partition the page cache per-process and allocate pages to processes based on the Working Set Size (WSS) of threads in that process

  • Swap out the oldest pages in advance to free up memory to cope with spikes in paging demand

  • Don't let threads steal pages from other threads

Recovery from thrashing

The possible courses of action to undertake, should thrashing occur, are :

  • Reboot the device

  • Kill a thread

  • Decrease the number of paged threads running concurrently

  • Pick one thread with a high page fault rate and stop other threads stealing pages from the thread's associated process

  • Prompt the user-side memory manager to close down applications.

Related concepts
Thrashing guide