To clean the cache we need to send one or more buffers to the disk. This will allow the system to reuse them as an up-to-date copy of the data will be kept in the swap device. The intuitive idea of cleaning the cache consists of sending to the disk all buffers when no free space is left. As buffers do not usually get completely filled with compressed pages, we have modified the concept of full buffer as follows:
Using this new concept, whenever a page does not fit in the cache, all full buffers will be sent to the disk in a single operation where all of them are written contiguously on the disk. This will increase the performance of the write operations significantly.
Should the system need to perform a clean operation when there are no full buffers, the buffer with more data will be sent to disk.
As we do not want to wait until no free space is left on the cache to clean it, whenever it has a given percentage of its buffers full, the system writes them to the disk. This percentage can be adjusted to the needs of the system as will be seen in a later section. This operation is currently done in a synchronous way but we are working to make it asynchronous.
An important detail is the addition of a flag that tells whether there is a cleaning operation already running. If this flag is on, a second concurrent cleaning will not be done as only one is really needed.