Writing Dirty Pages to Disk
As we have seen, the kernel keeps filling the page cache
with pages containing data of block devices. Whenever a process modifies
some data, the corresponding page is marked as dirty—that is, its
PG_dirty flag is set.
Unix systems allow the deferred writes of dirty pages into block devices, because this noticeably improves system performance. Several write operations on a page in cache could be satisfied by just one slow physical update of the corresponding disk sectors. Moreover, write operations are less critical than read operations, because a process is usually not suspended due to delayed writings, while it is most often suspended because of delayed reads. Thanks to deferred writes, each physical block device will service, on the average, many more read requests than write ones.
A dirty page might stay in main memory until the last possible moment — that is, until system shutdown. However, pushing the delayed-write strategy to its limits has two major drawbacks:
If a hardware or power supply failure occurs, the contents of RAM can no longer be retrieved, so many file updates that were made since the system was booted are lost.
The size of the page cache, and hence of the RAM required to contain it, would have to be huge—at least as big as the size of the accessed block devices.
Therefore, dirty pages are flushed (written) to disk under the following conditions:
The page cache gets too full and more pages are needed, or the number of dirty pages becomes ...