It is the last week of the month in a government office in a district town. The accounts clerk has a large spreadsheet open, a video call is running in another window, and someone has just started the antivirus scan. The computer has 4 GB of RAM and nothing is wrong with it. Yet the disk light has stayed on for a full minute, the mouse jerks, and a single click takes ten seconds to answer. The machine isn't broken, and it isn't slow by nature. It is doing one thing over and over: choosing which pieces of memory to throw out to make room, choosing badly, and fetching the same pieces back a moment later.
That choice is the subject of this chapter. In the last chapter you saw that a program's memory is cut into pages, that only the pages being used sit in RAM, and that touching a page that isn't there is a page fault. A fault is expensive, because it means a trip to the disk. And when RAM is full, every fault brings a second problem: before the new page can come in, an old one must go out. Which one? A good answer saves thousands of trips. A bad answer keeps the disk light on.
By the end you will be able to trace FIFO, LRU and Optimal by hand on any reference string, and say why each page was chosen. You will explain Belady's anomaly and the property that LRU has and FIFO lacks, run the clock algorithm with its reference and dirty bits, and see why real systems only approximate LRU. You will divide frames between processes, say what thrashing is and how it grows, work out working-set sizes, and answer the exam's two favourite questions, "how many page faults?" and "explain thrashing", quickly and without the usual slips.