Part 5 of 7 · 2 min read
Page-fault frequency
In plain words: The working set model needs a window of references, which is costly to keep. A simpler way watches only the fault rate of each process. Set an upper bound and a lower bound for the rate (the numbers below are made up). Then:
- If the rate of a process rises above the upper bound, the process needs more frames. Give it one, or if none is free, suspend a process.
- If the rate falls below the lower bound, the process has more frames than it needs. Take one frame away.
- Between the bounds, leave it.
With bounds of 0.01 and 0.05, a process at 0.08 gets a frame, a process at 0.002 loses one, and a process at 0.02 keeps what it has. This method is called page-fault frequency (PFF) control. It reaches the same goal as the working set with less work. It also gives a clear signal: if a process needs more frames and none can be freed, then memory is too small for the load, and some process must wait.
Linux does not run PFF in this exact form. It reacts to memory pressure in other ways: it reclaims pages from lists of recently used and idle pages (page 8), and in the last resort, when memory and swap are both exhausted, the out-of-memory killer chooses a process and ends it to free its frames. That is a hard way to reduce the load, and a good system avoids reaching it.
Page-fault frequency
Page-fault frequency (PFF) control is a method of managing frames in which the kernel measures the fault rate of each process and gives frames to a process whose rate is above an upper bound, and takes frames from one whose rate is below a lower bound.
Example: with bounds of 0.01 and 0.05, a process that faults on 8 of every 100 references gets another frame.
Interview angle
"What is thrashing and how can it be avoided?" A good answer says that thrashing is a state in which most time goes to page faults, that it appears when the processes together need more frames than exist, and that the cures are to give each process its working set, to suspend a process, or to add memory. It mentions that adding more processes is the wrong reaction.
Check yourself: 1. What does PFF do if the fault rate of a process falls below the lower bound? 2. What does it mean if a process needs a frame and none can be freed? 3. What does the out-of-memory killer do?