VM Snapshots Explained
How a VM Snapshot Captures a Virtual Machine's State
A VM snapshot is a saved, point-in-time state of a virtual machine that the owner can later return to. It records the VM's virtual disk and, when requested, its memory and device settings, so the machine can come back to exactly the same state.
Hypervisors usually use copy-on-write to do this quickly. When a snapshot is taken, the existing disk file becomes read-only. Every new write goes into a separate delta file, a small file that stores only the blocks changed since the snapshot. Reading a block checks the newest delta first and then falls back to the older files. Reverting to the snapshot discards the delta files written afterwards.
Because nothing is copied at the moment of creation, a snapshot is nearly instant, even for a large disk. A snapshot of a running VM can also include memory, so reverting returns the machine to a running state instead of a cold boot.
Why Long-Lived Snapshots Cause Problems
Snapshots are not free. Each one adds a layer to the chain of delta files. Reads may have to check several layers, and writes keep growing the newest file, so performance can drop as the chain gets longer.
Space is the other cost. A snapshot that stays for months keeps every block the VM has changed since, and those blocks cannot be freed until the snapshot is removed. Removing a snapshot means merging its deltas back into the base disk, which takes time and disk input and output, so it is best done in a quiet period. Providers that leave old snapshots behind often find that storage fills without an obvious cause. Thin provisioning makes this worse, as described in thin vs thick provisioning.
Snapshots also do not replace backups. They usually live on the same storage as the VM, so a storage failure can destroy the VM and its snapshots together. A snapshot of a busy database can also capture data in a half-written state unless the application is briefly paused or its writes are flushed first.
Snapshots further add to the work of moving a running VM to another host, since their delta files must move with the disk. The process is described in live migration.
Example: A Snapshot Before a Software Upgrade
An administrator plans to upgrade the application on a customer's VM. She takes a snapshot first. If the upgrade breaks the application, she reverts within minutes and the VM returns to its earlier state. Once the upgrade has been tested and accepted, she removes the snapshot, so its delta files are merged and the storage space is recovered.
Frequently asked questions
How long can a VM snapshot be kept?
There is no fixed limit, but snapshots are meant to be temporary. Short-lived snapshots protect a single change, such as an upgrade, and are then removed. Long-lived ones keep growing, slow the VM and make removal slower, so they should be treated as a risk to be cleared once the change is confirmed.
Do snapshots slow down a virtual machine?
They can. Writes to a VM with snapshots go into delta files, and reads may check several layers. The effect is usually small with one or two snapshots that are removed soon after they are taken. It grows with long chains of snapshots and with busy disks.