This document details PrimoCache's Defer-Write feature. Defer-Write is one of the main features of PrimoCache, also known as write-back caching. It can greatly improve the write performance of the entire system. PrimoCache can speed up disk writes only if Defer-Write is enabled, otherwise it will not improve write performance. The red box in the figure below shows the Defer-Write options in the cache configuration dialog. Check the "Enable Defer-Write" option to enable the Defer-Write function of the cache task.
Defer-Write is a caching technique that writes data to disk asynchronously. When PrimoCache receives data that Windows and applications send to disk, it first stores the data in the cache and reports to Windows and applications that the write is complete, and then writes the data to disk after a certain delay time. For Windows and applications, the write speed is very high because the entire writing process is done in the cache. For disk, due to the delay effect, when cache data is written to disk, 1) multiple writes to the same address can be combined into one write, 2) random small data writes to adjacent addresses can also be combined into one sequential write, and 3) temporary files do not need to be written if they have been deleted. Therefore, IO requests and the amount of data written to the disk can be greatly reduced, and the write speed of the disk can be improved. See this article for details. Combining the above two aspects, Defer-Write can greatly improve the overall system write performance.
Since Defer-Write accelerates writes by caching write-data, it requires that at least one of L1 cache and L2 cache is configured with write cache space. The write cache space can be a shared cache space or a separate write cache space. If both L1 cache and L2 cache are set to "100% read", then Defer-Write is actually disabled even if the "Enable Defer-Write" option is checked in the cache configuration dialog. In turn, you can control whether to enable Defer-Write on L1 cache or L2 cache by configuring its cache space. For example, to reduce write wear on the SSD cache, you might want to enable Defer-Write only on the RAM cache (L1 cache). In this case, you can enable the Defer-Write option while setting the L1 cache space to read-write shared or separate write cache space, and the L2 cache space to "100% read". With such a configuration, only the L1 cache has Defer-Write enabled, and Defer-Write on the L2 cache will be turned off. See this article for more information about the cache space.
When the free write cache space is sufficient, the performance of Defer-Write mainly depends on the write speed of the L1 cache or L2 cache. This speed is determined by the hardware device and has nothing to do with the Defer-Write parameters. However, when the free space is insufficient, that is, when the write cache is full of deferred write-data, PrimoCache will force a certain amount of the data to be written to the disk, thereby freeing up space to cache new write-data. Such a write operation is called an "urgent write". Urgent writes have poor performance and may even be slower than the disk's write speed. Therefore, an important goal of tuning the Defer-Write parameters is to avoid urgent writes, that is, to avoid running out of write cache space.
Urgent writes and write cache usage can be viewed in the cache statistics panel. The red box in the figure below shows all the statistics related to Defer-Write. You can use "Total Write (L1/L2)" to view the amount of data written to L1 cache and L2 cache, and "Total Write (Disk)" to view the amount of data actually written to disk. The amount of data written to disk is further divided into two parts: the amount of data written by urgent writes (statistically "Urgent") and the amount of data written after the normal delay expires (statistically "Normal"). The statistical item "Deferred Blocks" indicates the number of data blocks to be written currently, and the percentage in parentheses indicates the proportion of these blocks in all cache blocks, which can be understood as the write cache usage.
Write cache usage is related to write load, disk write speed, write cache size, and Defer-Write latency. If the write cache space is regarded as a reservoir, the write cache size is the reservoir capacity, the write load is equivalent to the water inflow, the disk write speed is equivalent to the water outflow speed, and the latency controls when the reservoir starts to discharge. When the write load and disk write speed cannot be changed, you can increase the write cache space or reduce the latency to reduce the write cache usage and avoid urgent writes.
In the absence of urgent writes, increasing latency helps reduce writes to disk, as more writes can be coalesced into one write. However, considering the risk of data loss mentioned below, the latency should not be too great.
Because write-data is first stored in the cache when Defer-Write is enabled, rather than being written to the disk in real time, in the event of a sudden power failure, system crash or freeze, the data will have no chance to be written to the disk, resulting in loss. Write-data may include file system metadata, so in extreme cases, the file system on the logical disk may even be damaged. Since cache index data is stored in memory, the risk of data loss is the same whether using L1 cache or L2 cache. Write-data on the L2 cache cannot be recovered to disk after a failure and restart.
Based on the above risk considerations, we recommend enabling Defer-Write only on logical disks that store temporary, unimportant, or reproducible data, such as download disks, temporary file disks, and logical disks with good backup mechanisms. A stable system with a UPS configured can also be considered to enable Defer-Write. In addition, reducing the Defer-Write latency can also effectively reduce the risk of data loss.