Definition
Cleaning Policy
A cleaning policy determines when a modified (dirty) page should be written back to secondary storage (disk). It is the opposite of a fetch policy.
Strategies
Demand Cleaning
A page is only written back to disk when it has been selected for replacement by the replacement policy.
- Pros: Minimises unnecessary disk writes, as a page might be modified multiple times before being swapped out.
- Cons: When a page fault occurs and a dirty page is chosen for replacement, the process must wait for the write to finish before the new page can be read, increasing latency.
Pre-cleaning
The system writes modified pages back to disk in batches, even if they have not yet been selected for replacement.
- Pros: When a page needs to be replaced, it is more likely to already be “clean” (matching the disk version), allowing the replacement to happen immediately.
- Cons: A page may be written to disk only to be modified again shortly after, resulting in redundant I/O operations.
Trade-offs
Modern operating systems often use a hybrid approach, such as page buffering, where replaced pages are kept in a list (clean or dirty). Dirty pages are written out in batches when the disk is idle or when the list of clean pages falls below a certain threshold.