今日已更新 392 条资讯 | 累计 26804 条内容
关于我们

Thrashing!!

Ritika Gaur 2026年06月30日 20:31 2 次阅读 来源:Dev.to

Follow here Thrashing occurs when a system spends more time swapping data between memory and disk than actually performing useful work. In simple terms, the system becomes busy “managing memory” instead of processing tasks efficiently. A simple real-life analogy is a small study table with space for only three books while you need ten books to study. You constantly remove one book and bring another from the bookshelf again and again. Instead of studying, most of your time is wasted managing the books. That situation is similar to thrashing. In operating systems, thrashing usually happens when RAM becomes full and too many processes compete for memory. The operating system uses virtual memory and page replacement techniques, but if the working sets of processes cannot fit into RAM, continuous page faults occur. As a result, pages are constantly swapped between RAM and disk, drastically reducing CPU utilization and slowing down the entire system. Thrashing can also occur in database systems and caching layers such as Redis. If the cache size is too small for the workload, the system keeps evicting old data to make space for new data, only to immediately need the old data again. For example, if a cache can hold 1000 items but users repeatedly request 2000 items in rotation, the cache continuously reloads and evicts the same entries. This repeated cache miss cycle is called cache thrashing. Consider an operating system example where four processes are running while RAM can hold only four pages. If each process requires at least two pages to execute properly, the system actually needs eight pages in total. Since only four pages fit in memory, the OS constantly swaps pages between RAM and disk. The CPU then spends most of its time waiting for memory I/O rather than executing instructions, resulting in severe performance degradation. A similar situation can happen in applications like Instagram using Redis caching. Suppose Redis can store 1000 user profiles while 3000 acti

本文内容来源于互联网,版权归原作者所有
查看原文