KVM guest performance can be improved knowing and selecting the guest caching mode that is the best for your environment. It will help the operating system to maintain the page cache so that the storage I/O performance can be improved.
When the data gets copied on the page cache the write operations to the storage system are considered to be completed. If the data requested to read is present in the cache then page cache can satisfy its read operations.
fsync(2) is used to copy the page cache to the permanent storage whereas page cache is bypassed by the direct I/O. while using the environment of Kernel-based Virtual Machine page caches can be maintained by both, the host and guest operating systems, to provide two copies of data to the memory of the system.
Normally one of these page caches is bypassed to improve KVM guest performance. For instance, if the direct I/O operations are used by the application running in the guest then it will be better to bypass guest page cache.
If no cache is set in the guest then to turn all the I/O operations from guest to direct I/O operations on the host it will be better to bypass host page cache.
The performance of write operations to the storage system can be improved by planning the disk write cache. Even though the data is not physically transferred to the disk media but still the write operation is considered to be completed by just reaching to the disk write cache.
But there is a risk of losing the data by the disk write cache if the cache is not supported by battery backup and there is a power failure. The applications must issue fsync(2) to ensure the actual transfer of write data on physical disk media.
Normally the write performance gets significantly improved by enabling disk write cache but incase of power failure the protection and integrity of the data can be ensured only if the storage stack and the applications correctly transfer the cache data to the permanent storage.
On the other hand the write performance may suffer if the disk write cache is disabled in case of power failure but it will considerably lessen the risk of data loss, which is a good point.
Some resources regarding KVM guest performance:
- Kernel configuration
- Filesystem choice
- Usage of Virtio device drivers
I’ve been able to improve my agency’s VPS (FreeBSD guest) performance before we turned to MacquarieTelecom’s secure hosting for government agencies.
Information about the caching modes used by Red Hat enterprises using Linux 6 for improving KVM guest performance is provided hereunder.
This default caching mode enables the host page cache for the guest but disables the write cache for disk. As a result this caching mode keeps the integrity of the data safe even if it is not properly transferred completely to the permanent storage by the applications and storage stack by using file system barriers or fsync operations.
The read performance is generally better for applications running in the guest as the host page cache is enabled in this mode. But the disabling of disk write cache adversely affects the KVM guest performance in write operations.
This caching mode enables both, the disk write cache and the host page cache, for improving the KVM guest performance. Though it improves the I/O performance for applications running in the guest but there is a risk of data loss as it is not protected from power failure. Thus this caching mode is recommended to use where potential amount of data is not required to be transferred to permanent storage.
This caching mode enables the disk write cache for the guest but disables the host page cache. This caching mode improves the KVM guest performance to its maximum because the host page cache is bypassed by the write operations and the disk write cache directly receives the data.
The integrity of data can be ensured with this caching mode if the disk write cache is supported by battery backup or the data is properly transferred by the applications or storage stack by using file system barriers or fsync operations.
But the KVM guest performance with this caching mode may not be improved to the level of the modes with enabled host page cache due to its disabled host page cache.
Cache transfer operations are completely ignored with the unsafe caching mode. This caching mode is recommended to be used for temporary data transfers only where the risk of data loss can not disturb the quality of operation, as its name suggests unsafe. Though it can be used for speeding up the installation of guests but to improve KVM guest performance you should opt for other caching modes.
To conclude, I recommend using one of the caching modes (depending on your scenario) that enable the host page cache like writethrough mode to improve the KVM guest performance for local or directly attached storage.
This mode can ensure the integrity of the data due to their acceptability to the I/O performance for applications, especially for the read operations, running in the guest.